blob: 9334716b2f00dae7eb722b6ec9b9fe8f81d396a7 [file] [log] [blame]
// 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 (
"encoding/json"
"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"
"android.googlesource.com/platform/tools/gpu/gapid/gfxapi/gles"
)
var (
showDeviceInfo bool
)
func init() {
verb := &app.Verb{
Name: "info",
ShortHelp: "Prints information about a gfx trace capture file",
Run: doInfo,
}
verb.Flags.BoolVar(&showDeviceInfo, "di", false, "show originating device info")
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, in)
fmt.Println("Got ", len(list.Atoms), " atoms from ", in.count, "bytes")
if err != nil {
return err
}
if showDeviceInfo {
for _, a := range list.Atoms {
if di := gles.FindDeviceInfo(a.Extras()); di != nil {
b, err := json.MarshalIndent(di, "", " ")
if err != nil {
return err
}
fmt.Printf("DeviceInfo: %s\n", string(b))
}
}
}
return err
}