| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package main |
| |
| import ( |
| "flag" |
| "fmt" |
| "io" |
| "os" |
| |
| "android.googlesource.com/platform/tools/gpu/client/gapii" |
| "android.googlesource.com/platform/tools/gpu/framework/app" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| ) |
| |
| func init() { |
| verb := &app.Verb{ |
| Name: "info", |
| ShortHelp: "Prints information about a gfx trace capture file", |
| Run: doInfo, |
| } |
| app.AddVerb(verb) |
| } |
| |
| type countingReader struct { |
| from io.Reader |
| count int |
| } |
| |
| func (c *countingReader) Read(buf []byte) (int, error) { |
| size, err := c.from.Read(buf) |
| c.count += size |
| return size, err |
| } |
| |
| func doInfo(ctx log.Context, flags flag.FlagSet) error { |
| if flags.NArg() != 1 { |
| app.Usage(ctx, "Exactly one gfx trace file expected, got %d", flags.NArg()) |
| return nil |
| } |
| filename := flags.Arg(0) |
| fmt.Println("reading file ", filename) |
| fstat, err := os.Stat(filename) |
| if err != nil { |
| return err |
| } |
| fmt.Println("total file size ", fstat.Size()) |
| f, err := os.Open(filename) |
| if err != nil { |
| return err |
| } |
| defer f.Close() |
| in := &countingReader{from: f} |
| list, err := gapii.ReadCapture(ctx, fstat.Name(), in) |
| fmt.Println("Got ", len(list.Atoms), " atoms from ", in.count, "bytes") |
| if err != nil { |
| return err |
| } |
| return err |
| } |