Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Robot building and working again. #2598

Merged
merged 11 commits into from
Feb 15, 2019
107 changes: 59 additions & 48 deletions cmd/gapit/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"time"
Expand All @@ -46,6 +47,8 @@ func init() {
})
}

type target func(opts *service.TraceOptions)

func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
client, err := getGapis(ctx, verb.Gapis, GapirFlags{})
if err != nil {
Expand All @@ -63,32 +66,26 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
traceURI = flags.Arg(0)
}

var traceDevice *path.Device
out := "capture.gfxtrace"
var port uint32
var uri string
var target target

if verb.Local.Port != 0 {
serverInfo, err := client.GetServerInfo(ctx)
if err != nil {
return err
}
traceDevice = serverInfo.GetServerLocalDevice()
traceDevice := serverInfo.GetServerLocalDevice()
if traceDevice.GetID() == nil {
return fmt.Errorf("The server was not started with a local device for tracing")
}
port = uint32(verb.Local.Port)
} else {
type info struct {
uri string
device *path.Device
deviceName string
name string
target = func(opts *service.TraceOptions) {
opts.Device = traceDevice
opts.App = &service.TraceOptions_Port{
Port: uint32(verb.Local.Port),
}
}
var found []info

} else {
// Find the actual trace URI from all of the devices

devices, err := filterDevices(ctx, &verb.DeviceFlags, client)
if err != nil {
return err
Expand All @@ -99,12 +96,32 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
}

if len(devices) == 1 && strings.HasPrefix(traceURI, "port:") {
found = append(found, info{
uri: traceURI,
device: devices[0],
name: "capture",
})
target = func(opts *service.TraceOptions) {
opts.Device = devices[0]
opts.App = &service.TraceOptions_Uri{
Uri: traceURI,
}
}
} else if len(devices) == 1 && strings.HasPrefix(traceURI, "apk:") {
data, err := ioutil.ReadFile(traceURI[4:])
if err != nil {
return log.Errf(ctx, err, "Failed to read APK at %s", traceURI[4:])
}
target = func(opts *service.TraceOptions) {
opts.Device = devices[0]
opts.App = &service.TraceOptions_UploadApplication{
pmuetschard marked this conversation as resolved.
Show resolved Hide resolved
UploadApplication: data,
}
}
} else {
type info struct {
uri string
device *path.Device
deviceName string
name string
}
var found []info

for _, dev := range devices {
targets, err := client.FindTraceTargets(ctx, &service.FindTraceTargetsRequest{
Device: dev,
Expand Down Expand Up @@ -137,36 +154,39 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
})
}
}
}

if len(found) == 0 {
return fmt.Errorf("Could not find %+v to trace on any device", traceURI)
}
if len(found) == 0 {
return fmt.Errorf("Could not find %+v to trace on any device", traceURI)
}

if len(found) > 1 {
sb := strings.Builder{}
fmt.Fprintf(&sb, "Found %v candidates: \n", traceURI)
for i, f := range found {
if i == 0 || found[i-1].deviceName != f.deviceName {
fmt.Fprintf(&sb, " %v:\n", f.deviceName)
if len(found) > 1 {
sb := strings.Builder{}
fmt.Fprintf(&sb, "Found %v candidates: \n", traceURI)
for i, f := range found {
if i == 0 || found[i-1].deviceName != f.deviceName {
fmt.Fprintf(&sb, " %v:\n", f.deviceName)
}
fmt.Fprintf(&sb, " %v\n", f.uri)
}
fmt.Fprintf(&sb, " %v\n", f.uri)
return log.Errf(ctx, nil, "%v", sb.String())
}
return log.Errf(ctx, nil, "%v", sb.String())
}

fmt.Printf("Tracing %+v\n", found[0].uri)
out = found[0].name + ".gfxtrace"
uri = found[0].uri
traceDevice = found[0].device
fmt.Printf("Tracing %+v\n", found[0].uri)
out = found[0].name + ".gfxtrace"
target = func(opts *service.TraceOptions) {
opts.Device = found[0].device
opts.App = &service.TraceOptions_Uri{
Uri: found[0].uri,
}
}
}
}

if verb.Out != "" {
out = verb.Out
}

options := &service.TraceOptions{
Device: traceDevice,
Apis: []string{},
AdditionalCommandLineArgs: verb.AdditionalArgs,
Cwd: verb.WorkingDir,
Expand All @@ -186,16 +206,7 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
ServerLocalSavePath: out,
PipeName: verb.PipeName,
}

if uri != "" {
options.App = &service.TraceOptions_Uri{
uri,
}
} else {
options.App = &service.TraceOptions_Port{
port,
}
}
target(options)

switch verb.API {
case "vulkan":
Expand Down Expand Up @@ -225,7 +236,7 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
}
log.I(ctx, "Trace Status %+v", status)

handlerInstalled := false
handlerInstalled := verb.For > 0

return task.Retry(ctx, 0, time.Second*3, func(ctx context.Context) (retry bool, err error) {
status, err = handler.Event(ctx, service.TraceEvent_Status)
Expand Down
8 changes: 4 additions & 4 deletions core/app/layout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var osToDir = map[device.OSKind]string{
}

func (l pkgLayout) Gapir(ctx context.Context, abi *device.ABI) (file.Path, error) {
if hostOS(ctx) == abi.OS {
if abi == nil || hostOS(ctx) == abi.OS {
return l.root.Join(withExecutablePlatformSuffix("gapir", hostOS(ctx))), nil
}
return l.root.Join(osToDir[abi.OS], withExecutablePlatformSuffix("gapir", abi.OS)), nil
Expand All @@ -141,7 +141,7 @@ func (l pkgLayout) GapidApk(ctx context.Context, abi *device.ABI) (file.Path, er
}

func (l pkgLayout) Library(ctx context.Context, lib LibraryType, abi *device.ABI) (file.Path, error) {
if hostOS(ctx) == abi.OS {
if abi == nil || hostOS(ctx) == abi.OS {
return l.root.Join("lib", withLibraryPlatformSuffix(libTypeToName[lib], hostOS(ctx))), nil
}
return l.root.Join(osToDir[abi.OS], "lib", withLibraryPlatformSuffix(libTypeToName[lib], abi.OS)), nil
Expand Down Expand Up @@ -361,7 +361,7 @@ func (l *ZipLayout) Gapit(ctx context.Context) (*zip.File, error) {

// Gapir returns the path to the gapir binary in this layout.
func (l *ZipLayout) Gapir(ctx context.Context, abi *device.ABI) (*zip.File, error) {
if l.os == abi.OS {
if abi == nil || l.os == abi.OS {
return l.file(withExecutablePlatformSuffix("gapir", l.os))
}
return l.file(osToDir[abi.OS] + "/" + withExecutablePlatformSuffix("gapir", abi.OS))
Expand All @@ -379,7 +379,7 @@ func (l *ZipLayout) GapidApk(ctx context.Context, abi *device.ABI) (*zip.File, e

// Library returns the path to the requested library.
func (l *ZipLayout) Library(ctx context.Context, lib LibraryType, abi *device.ABI) (*zip.File, error) {
if l.os == abi.OS {
if abi == nil || l.os == abi.OS {
return l.file("lib/" + withLibraryPlatformSuffix(libTypeToName[lib], l.os))
}
return l.file(osToDir[abi.OS] + "lib/" + withLibraryPlatformSuffix(libTypeToName[lib], abi.OS))
Expand Down
12 changes: 12 additions & 0 deletions core/os/android/apk/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ func engine(files []*zip.File) string {
}
return "<unknown>"
}

func (i *Information) URI() string {
var uri string
if i.Action != "" {
uri = i.Action + ":"
}
uri += i.Package
if i.Activity != "" {
uri += "/" + i.Activity
}
return uri
}
8 changes: 6 additions & 2 deletions core/os/file/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ func ZIP(out io.Writer, in Path) error {
if r == "." {
r = in.Basename()
}

fw, err := w.Create(r)
h, err := zip.FileInfoHeader(info)
if err != nil {
return err
}
h.Name = r
fw, err := w.CreateHeader(h)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions gapis/trace/android/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ func (t *androidTracer) InstallPackage(ctx context.Context, o *service.TraceOpti
pkg.Uninstall(ctx)
}
}

o.App = &service.TraceOptions_Uri{
Uri: info.URI(),
}
return pkg, cleanup, nil
}

Expand Down Expand Up @@ -401,7 +405,6 @@ func (t *androidTracer) SetupTrace(ctx context.Context, o *service.TraceOptions)
if len(o.GetUploadApplication()) > 0 {
pkg, cleanup, err = t.InstallPackage(ctx, o)
if err != nil {
cleanup()
return ret, nil, err
}
}
Expand All @@ -424,9 +427,6 @@ func (t *androidTracer) SetupTrace(ctx context.Context, o *service.TraceOptions)
match = re.FindStringSubmatch(o.GetUri())

if len(match) == 4 {
if err != nil {
return ret, nil, err
}
packages, err := t.b.InstalledPackages(ctx)
if err != nil {
return ret, nil, err
Expand Down
6 changes: 4 additions & 2 deletions test/robot/build/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func (a *artifacts) get(ctx context.Context, id string, builderAbi *device.ABI)
l := layout.NewZipLayout(zipFile, builderAbi.OS)

toolSet := ToolSet{Abi: builderAbi, Host: new(HostToolSet)}
if toolSet.Host.Gapir, err = a.getID(ctx, l.Gapir, "gapir"); err != nil {
if toolSet.Host.Gapir, err = a.getID(ctx, func(ctx context.Context) (*zip.File, error) {
return l.Gapir(ctx, nil)
}, "gapir"); err != nil {
return nil, err
}
if toolSet.Host.Gapis, err = a.getID(ctx, l.Gapis, "gapis"); err != nil {
Expand All @@ -138,7 +140,7 @@ func (a *artifacts) get(ctx context.Context, id string, builderAbi *device.ABI)
return nil, err
}
if toolSet.Host.VirtualSwapChainLib, err = a.getID(ctx, func(ctx context.Context) (*zip.File, error) {
return l.Library(ctx, layout.LibVirtualSwapChain)
return l.Library(ctx, layout.LibVirtualSwapChain, nil)
}, "libVirtualSwapChain"); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion test/robot/job/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (l *devices) get(ctx context.Context, info *device.Instance) (*Device, erro
entry := l.find(ctx, info)
if entry == nil {
entry = &Device{
Id: l.uniqueName(ctx, info.Id.ID().String()),
Id: l.uniqueName(ctx, info.ID.ID().String()),
Information: info,
}
if err := l.ledger.Add(ctx, entry); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/robot/replay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func doReplay(ctx context.Context, action string, in *Input, store *stash.Client
if err != nil {
return nil, err
}
gapir, err := extractedLayout.Gapir(ctx)
gapir, err := extractedLayout.Gapir(ctx, nil)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions test/robot/scheduler/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (s schedule) doTrace(ctx context.Context, subj *monitor.Subject, tools *bui
input := &trace.Input{
Subject: subj.Id,
Obb: subj.Obb,
Gapis: tools.Host.Gapis,
Gapit: tools.Host.Gapit,
GapidApk: androidTools.GapidApk,
Package: s.pkg.Id,
Expand Down
17 changes: 13 additions & 4 deletions test/robot/trace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func doTrace(ctx context.Context, action string, in *Input, store *stash.Client,
return nil, err
}

gapis, err := extractedLayout.Gapis(ctx)
if err != nil {
return nil, err
}

gapit, err := extractedLayout.Gapit(ctx)
if err != nil {
return nil, err
Expand All @@ -137,6 +142,9 @@ func doTrace(ctx context.Context, action string, in *Input, store *stash.Client,
if err := store.GetFile(ctx, in.Subject, subject); err != nil {
return nil, err
}
if err := store.GetFile(ctx, in.Gapis, gapis); err != nil {
return nil, err
}
if err := store.GetFile(ctx, in.Gapit, gapit); err != nil {
return nil, err
}
Expand All @@ -147,12 +155,11 @@ func doTrace(ctx context.Context, action string, in *Input, store *stash.Client,
params := []string{
"trace",
"-out", tracefile.System(),
"-apk", subject.System(),
"-for", traceTime.String(),
"-disable-pcs",
"-observe-frames", strconv.Itoa(observeEveryNthFrame),
"-record-errors",
"-gapii-device", d.Instance().Serial,
"-serial", d.Instance().Serial,
"-api", in.GetHints().GetAPI(),
}

Expand All @@ -166,9 +173,11 @@ func doTrace(ctx context.Context, action string, in *Input, store *stash.Client,
defer func() {
file.Remove(obb)
}()
params = append(params, "-obb", obb.System())
// TODO fix this
// params = append(params, "-obb", obb.System())
return log.Errf(ctx, nil, "OBBs are currently not supported")
}
cmd := shell.Command(gapit.System(), params...)
cmd := shell.Command(gapit.System(), append(params, "apk:"+subject.System())...)
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
outputObj := &Output{}
Expand Down
2 changes: 2 additions & 0 deletions test/robot/trace/trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import "core/os/device/device.proto";
message Input {
// Subject is the stash id of the trace subject.
string subject = 1;
// Gapis is the stash id of the graphics server tool to use.
string gapis = 8;
// Gapit is the stash id of the graphics analysis tool to use.
string gapit = 2;
// GapidApk is the stash id of the gapid.apk to use.
Expand Down