MCPcopy Create free account
hub / github.com/google/gapid / Capture

Method Capture

gapii/client/capture.go:154–220  ·  view source on GitHub ↗

Capture opens up the specified port and then waits for a capture to be delivered using the specified capture options o. It copies the capture into the supplied writer. If the process was started with the DeferStart flag, then tracing will wait until start is fired. Capturing will stop when the stop

(ctx context.Context, start task.Signal, stop task.Signal, w io.Writer, written *int64)

Source from the content-addressed store, hash-verified

152// Capturing will stop when the stop signal is fired (clean stop) or the
153// context is cancelled (abort).
154func (p *Process) Capture(ctx context.Context, start task.Signal, stop task.Signal, w io.Writer, written *int64) (size int64, err error) {
155 stopTiming := analytics.SendTiming("trace", "duration")
156 defer func() {
157 stopTiming(analytics.Size(size))
158 var label string
159 if (p.Options.Flags & DeferStart) != 0 {
160 label = "mec"
161 }
162 if err != nil {
163 analytics.SendEvent("trace", "failed", label, analytics.Size(size),
164 analytics.TargetDevice(p.Device.Instance().GetConfiguration()))
165
166 } else {
167 analytics.SendEvent("trace", "succeeded", label, analytics.Size(size),
168 analytics.TargetDevice(p.Device.Instance().GetConfiguration()))
169 }
170 }()
171
172 if p.conn == nil {
173 if err := p.connect(ctx, 0, ""); err != nil {
174 return 0, err
175 }
176 }
177 status.Event(ctx, status.ProcessScope, "Trace Connected")
178
179 conn := p.conn
180 defer conn.Close()
181
182 var count siSize
183 started := false
184 for {
185 if task.Stopped(ctx) || stop.Fired() {
186 log.I(ctx, "Stop: %v", count)
187 break
188 }
189 if (p.Options.Flags & DeferStart) != 0 {
190 if !started && start.Fired() {
191 started = true
192 w := endian.Writer(conn, device.LittleEndian)
193 w.Uint32(startMidExecutionCapture)
194 }
195 }
196 now := time.Now()
197 conn.SetReadDeadline(now.Add(time.Millisecond * 500)) // Allow for stop event and UI refreshes.
198 n, err := io.CopyN(w, conn, 1024*64)
199 count += siSize(n)
200 atomic.StoreInt64(written, int64(count))
201 switch {
202 case errors.Cause(err) == io.EOF:
203 // End of stream. End.
204 log.I(ctx, "EOF: %v", count)
205 return int64(count), nil
206 case err != nil && count > 0:
207 err, isnet := err.(net.Error)
208 if !isnet || (!err.Temporary() && !err.Timeout()) {
209 log.I(ctx, "Connection error: %v", err)
210 // Got an error mid-stream terminate.
211 return int64(count), err

Callers

nothing calls this directly

Calls 13

connectMethod · 0.95
siSizeTypeAlias · 0.85
IMethod · 0.80
WriterMethod · 0.80
SizeMethod · 0.65
SendEventMethod · 0.65
InstanceMethod · 0.65
EventMethod · 0.65
CloseMethod · 0.65
FiredMethod · 0.65
Uint32Method · 0.65
AddMethod · 0.65

Tested by

no test coverage detected