| // 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" |
| "path/filepath" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/app" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| "android.googlesource.com/platform/tools/gpu/framework/stringtable" |
| "android.googlesource.com/platform/tools/gpu/gapid/atom" |
| "android.googlesource.com/platform/tools/gpu/gapid/service" |
| ) |
| |
| type reportFlags struct { |
| flag.FlagSet |
| replayFlags |
| } |
| |
| func init() { |
| verb := &app.Verb{ |
| Name: "report", |
| ShortHelp: "Check a capture replays without issues", |
| } |
| |
| reportFlags := reportFlags{} |
| reportFlags.replayFlags.bind(verb) |
| verb.Run = func(ctx log.Context, flags flag.FlagSet) error { |
| reportFlags.FlagSet = flags |
| return doReport(ctx, reportFlags) |
| } |
| app.AddVerb(verb) |
| } |
| |
| func doReport(ctx log.Context, flags reportFlags) 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 ctx.S("path", flags.Arg(0)).WrapError(err, "Could not find capture file") |
| } |
| |
| client, err := getGapis(ctx, flags.gapis, flags.gapir) |
| if err != nil { |
| return ctx.WrapError(err, "Failed to connect to the GAPIS server") |
| } |
| defer client.Close(ctx) |
| |
| stringTables, err := client.GetAvailableStringTables(ctx) |
| if err != nil { |
| return ctx.WrapError(err, "Failed get list of string tables") |
| } |
| |
| var stringTable *stringtable.StringTable |
| if len(stringTables) > 0 { |
| // TODO: Let the user pick the string table. |
| stringTable, err = client.GetStringTable(ctx, stringTables[0]) |
| if err != nil { |
| return ctx.WrapError(err, "Failed get string table") |
| } |
| } |
| |
| device, err := getDevice(ctx, client, flags.replayFlags) |
| if err != nil { |
| return err |
| } |
| |
| capturePath, err := client.LoadCapture(ctx, capture) |
| if err != nil { |
| return ctx.WrapError(err, "Failed to load the capture file") |
| } |
| |
| boxedAtoms, err := client.Get(ctx, capturePath.Atoms()) |
| if err != nil { |
| return ctx.WrapError(err, "Failed to acquire the capture's atoms") |
| } |
| atoms := boxedAtoms.(*atom.List).Atoms |
| |
| boxedReport, err := client.Get(ctx, capturePath.Report(device)) |
| if err != nil { |
| return ctx.WrapError(err, "Failed to acquire the capture's report") |
| } |
| |
| 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], report.ConstructMessage(e.Message).Text(stringTable)) |
| } else { |
| ctx.At(e.Severity).Logf("%v", report.ConstructMessage(e.Message).Text(stringTable)) |
| } |
| } |
| |
| if len(report.Items) == 0 { |
| ctx.Print("No issues found") |
| } else { |
| ctx.Info().Logf("%d issues found", len(report.Items)) |
| } |
| |
| return nil |
| } |