blob: d7b6aeeb829364bd46555f24f9d564ad605c28b1 [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 (
"flag"
"fmt"
"path/filepath"
"strings"
"android.googlesource.com/platform/tools/gpu/client/gapis"
"android.googlesource.com/platform/tools/gpu/framework/app"
"android.googlesource.com/platform/tools/gpu/framework/file"
"android.googlesource.com/platform/tools/gpu/framework/log"
"android.googlesource.com/platform/tools/gpu/gapid/atom"
"android.googlesource.com/platform/tools/gpu/gapid/auth"
"android.googlesource.com/platform/tools/gpu/gapid/service"
"android.googlesource.com/platform/tools/gpu/gapid/service/path"
)
var (
gapisPort int
profile string
gapisArgStr string
gapirArgStr string
)
func init() {
verb := &app.Verb{
Name: "report",
ShortHelp: "Check a capture replays without issues",
Run: doReport,
}
verb.Flags.IntVar(&gapisPort, "gapis", 0, "gapis tcp port to connect to, 0 means start new instance.")
verb.Flags.StringVar(&profile, "profile", "", "produce a pprof file from gapis")
verb.Flags.StringVar(&gapisArgStr, "gapis-args", "", `"<The arguments to be passed to gapis>"`)
verb.Flags.StringVar(&gapirArgStr, "gapir-args", "", `"<The arguments to be passed to gapir>"`)
verb.Run = doReport
app.AddVerb(verb)
}
func doReport(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
}
capture, err := filepath.Abs(flags.Arg(0))
if err != nil {
return fmt.Errorf("Could not find capture file '%s': %v", flags.Arg(0), err)
}
args := strings.Fields(gapisArgStr)
if gapirArgStr != "" {
// Pass the arguments for gapir further to gapis. Add flag to tag the
// gapir argument string for gapis.
args = append(args, "--gapir-args", gapirArgStr)
}
if profile != "" {
args = append(args, "-cpuprofile", profile)
}
binDir := file.ExecutablePath().Parent()
client, _, err := gapis.Connect(ctx, binDir, gapisPort, auth.GenToken(), args...)
if err != nil {
return fmt.Errorf("Failed to connect to the GAPIS server: %v", err)
}
devices, err := client.GetDevices(ctx)
if err != nil {
return fmt.Errorf("Failed query list of devices: %v", err)
}
var devicePath *path.Device
// TODO: Let the user control the device used.
if len(devices) > 0 {
devicePath = devices[0]
} else {
ctx.Warning().Log("No replay device found")
}
capturePath, err := client.LoadCapture(ctx, capture)
if err != nil {
return fmt.Errorf("Failed to load the capture file '%v': %v", capture, err)
}
boxedAtoms, err := client.Get(ctx, capturePath.Atoms())
if err != nil {
return fmt.Errorf("Failed to acquire the capture's atoms: %v", err)
}
atoms := boxedAtoms.(*atom.List).Atoms
boxedReport, err := client.Get(ctx, capturePath.Report(devicePath))
if err != nil {
return fmt.Errorf("Failed to acquire the capture's report: %v", err)
}
report := boxedReport.(*service.Report)
for _, e := range report.Items {
if e.Atom != uint64(atom.NoID) {
ctx.At(e.Severity).Logf("(%d) %v %v", e.Atom, atoms[e.Atom], e.Message)
} else {
ctx.At(e.Severity).Logf("%v", e.Message)
}
}
if len(report.Items) == 0 {
ctx.Print("No issues found")
} else {
ctx.Info().Logf("%d issues found", len(report.Items))
}
return nil
}