@@ -54,80 +54,95 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
54
54
55
55
traceURI := verb .URI
56
56
57
- if traceURI == "" {
57
+ if traceURI == "" && verb . Local . Port == 0 {
58
58
if flags .NArg () != 1 {
59
59
app .Usage (ctx , "Expected application name" )
60
60
return nil
61
61
}
62
62
traceURI = flags .Arg (0 )
63
63
}
64
64
65
- uris := []string {}
66
- traceDevices := []string {}
67
65
var traceDevice * path.Device
68
- names := []string {}
69
- // Find the actual trace URI from all of the devices
66
+ out := "capture.gfxtrace"
67
+ var port uint32
68
+ var uri string
70
69
71
- devices , err := filterDevices (ctx , & verb .DeviceFlags , client )
72
- if err != nil {
73
- return err
74
- }
75
-
76
- if len (devices ) == 0 {
77
- return fmt .Errorf ("Could not find matching device" )
78
- }
79
-
80
- for _ , dev := range devices {
81
- tttn , err := client .FindTraceTarget (ctx , & service.FindTraceTargetRequest {
82
- Device : dev ,
83
- Uri : traceURI ,
84
- })
70
+ if verb .Local .Port != 0 {
71
+ serverInfo , err := client .GetServerInfo (ctx )
85
72
if err != nil {
86
- continue
73
+ return err
87
74
}
88
-
89
- dd , err := client .Get (ctx , dev .Path ())
75
+ traceDevice = serverInfo .GetServerLocalDevice ()
76
+ if traceDevice .GetID () == nil {
77
+ return fmt .Errorf ("The server was not started with a local device for tracing" )
78
+ }
79
+ port = uint32 (verb .Local .Port )
80
+ } else {
81
+ uris := []string {}
82
+ traceDevices := []string {}
83
+ names := []string {}
84
+ // Find the actual trace URI from all of the devices
85
+
86
+ devices , err := filterDevices (ctx , & verb .DeviceFlags , client )
90
87
if err != nil {
91
88
return err
92
89
}
93
- d := dd .(* device.Instance )
94
-
95
- uris = append (uris , tttn .Uri )
96
- traceDevices = append (traceDevices , d .Name )
97
- traceDevice = dev
98
- if tttn .FriendlyApplication != "" {
99
- names = append (names , tttn .FriendlyApplication )
100
- } else if tttn .FriendlyExecutable != "" {
101
- names = append (names , tttn .FriendlyExecutable )
102
- } else {
103
- names = append (names , tttn .Name )
90
+
91
+ if len (devices ) == 0 {
92
+ return fmt .Errorf ("Could not find matching device" )
104
93
}
105
- }
106
94
107
- if len (uris ) == 0 {
108
- return fmt .Errorf ("Could not find %+v to trace on any device" , traceURI )
109
- }
95
+ for _ , dev := range devices {
96
+ tttn , err := client .FindTraceTarget (ctx , & service.FindTraceTargetRequest {
97
+ Device : dev ,
98
+ Uri : traceURI ,
99
+ })
100
+ if err != nil {
101
+ continue
102
+ }
110
103
111
- if len (uris ) > 1 {
112
- output := fmt .Sprintf ("Found %+v on multiple devices: \n " , traceURI )
113
- for i := range uris {
114
- output += fmt .Sprintf (" %+v: %+v\n " , traceDevices [i ], uris [i ])
104
+ dd , err := client .Get (ctx , dev .Path ())
105
+ if err != nil {
106
+ return err
107
+ }
108
+ d := dd .(* device.Instance )
109
+
110
+ uris = append (uris , tttn .Uri )
111
+ traceDevices = append (traceDevices , d .Name )
112
+ traceDevice = dev
113
+ if tttn .FriendlyApplication != "" {
114
+ names = append (names , tttn .FriendlyApplication )
115
+ } else if tttn .FriendlyExecutable != "" {
116
+ names = append (names , tttn .FriendlyExecutable )
117
+ } else {
118
+ names = append (names , tttn .Name )
119
+ }
120
+ }
121
+
122
+ if len (uris ) == 0 {
123
+ return fmt .Errorf ("Could not find %+v to trace on any device" , traceURI )
124
+ }
125
+
126
+ if len (uris ) > 1 {
127
+ output := fmt .Sprintf ("Found %+v on multiple devices: \n " , traceURI )
128
+ for i := range uris {
129
+ output += fmt .Sprintf (" %+v: %+v\n " , traceDevices [i ], uris [i ])
130
+ }
131
+ return fmt .Errorf ("%s" , output )
115
132
}
116
- return fmt .Errorf ("%s" , output )
133
+
134
+ fmt .Printf ("Tracing %+v" , uris )
135
+ out = names [0 ] + ".gfxtrace"
136
+ uri = uris [0 ]
117
137
}
118
138
119
- fmt .Printf ("Tracing %+v" , uris )
120
- out := names [0 ] + ".gfxtrace"
121
139
if verb .Out != "" {
122
140
out = verb .Out
123
141
}
124
142
125
143
options := & service.TraceOptions {
126
144
Device : traceDevice ,
127
- App : & service.TraceOptions_Uri {
128
- uris [0 ],
129
- },
130
- Apis : []string {},
145
+ Apis : []string {},
131
146
AdditionalCommandLineArgs : verb .AdditionalArgs ,
132
147
Cwd : verb .WorkingDir ,
133
148
Environment : verb .Env ,
@@ -145,6 +160,16 @@ func (verb *traceVerb) Run(ctx context.Context, flags flag.FlagSet) error {
145
160
ServerLocalSavePath : out ,
146
161
}
147
162
163
+ if uri != "" {
164
+ options .App = & service.TraceOptions_Uri {
165
+ uri ,
166
+ }
167
+ } else {
168
+ options .App = & service.TraceOptions_Port {
169
+ port ,
170
+ }
171
+ }
172
+
148
173
switch verb .API {
149
174
case "vulkan" :
150
175
options .Apis = []string {"Vulkan" }
0 commit comments