Skip to content

Commit 8b4c13b

Browse files
mknyszekgopherbot
authored andcommitted
trace: handle end-of-generation in flight recorder
CL 693398 introduced an end-of-generation signal, but the x/exp flight recorder wasn't updated to handle it. Luckily, we can do something trivial and just pass it through, since the old way still works, so we don't need to add full support. Fixes golang/go#75085. Change-Id: I2aeb723dc727eb308004140d04ef3e4e1c1b66b9 Reviewed-on: https://go-review.googlesource.com/c/exp/+/697417 Auto-Submit: Carlos Amedee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent f6d41f0 commit 8b4c13b

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

trace/flightrecorder.go

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func (w *recorder) Write(p []byte) (n int, err error) {
151151
if err != nil {
152152
return len(p) - rd.Len(), err
153153
}
154+
if b.isEndOfGeneration() {
155+
gen = r.active.gen
156+
}
154157

155158
// Check if we're entering a new generation.
156159
if r.active.gen != 0 && r.active.gen+1 == gen {
@@ -200,18 +203,20 @@ func (w *recorder) Write(p []byte) (n int, err error) {
200203
}
201204

202205
// Append the batch to the current generation.
203-
if r.active.gen == 0 {
204-
r.active.gen = gen
205-
}
206-
if r.active.minTime == 0 || r.active.minTime > b.time {
207-
r.active.minTime = b.time
206+
if !b.isEndOfGeneration() {
207+
if r.active.gen == 0 {
208+
r.active.gen = gen
209+
}
210+
if r.active.minTime == 0 || r.active.minTime > b.time {
211+
r.active.minTime = b.time
212+
}
213+
r.active.size += 1
214+
r.active.size += uvarintSize(gen)
215+
r.active.size += uvarintSize(uint64(b.m))
216+
r.active.size += uvarintSize(uint64(b.time))
217+
r.active.size += uvarintSize(uint64(len(b.data)))
218+
r.active.size += len(b.data)
208219
}
209-
r.active.size += 1
210-
r.active.size += uvarintSize(gen)
211-
r.active.size += uvarintSize(uint64(b.m))
212-
r.active.size += uvarintSize(uint64(b.time))
213-
r.active.size += uvarintSize(uint64(len(b.data)))
214-
r.active.size += len(b.data)
215220
r.active.batches = append(r.active.batches, b)
216221

217222
return len(p) - rd.Len(), nil
@@ -322,23 +327,26 @@ func (r *FlightRecorder) WriteTo(w io.Writer) (total int, err error) {
322327
// Write all the data.
323328
for _, gen := range gens {
324329
for _, batch := range gen.batches {
325-
// Rewrite the batch header event with four arguments: gen, M ID, timestamp, and data length.
326-
n, err := w.Write([]byte{byte(tracev2.EvEventBatch)})
327-
total += n
328-
if err != nil {
329-
return total, err
330-
}
331-
if err := writeUvarint(gen.gen); err != nil {
332-
return total, err
333-
}
334-
if err := writeUvarint(uint64(batch.m)); err != nil {
335-
return total, err
336-
}
337-
if err := writeUvarint(uint64(batch.time)); err != nil {
338-
return total, err
339-
}
340-
if err := writeUvarint(uint64(len(batch.data))); err != nil {
341-
return total, err
330+
var n int
331+
if !batch.isEndOfGeneration() {
332+
// Rewrite the batch header event with four arguments: gen, M ID, timestamp, and data length.
333+
n, err := w.Write([]byte{byte(tracev2.EvEventBatch)})
334+
total += n
335+
if err != nil {
336+
return total, err
337+
}
338+
if err := writeUvarint(gen.gen); err != nil {
339+
return total, err
340+
}
341+
if err := writeUvarint(uint64(batch.m)); err != nil {
342+
return total, err
343+
}
344+
if err := writeUvarint(uint64(batch.time)); err != nil {
345+
return total, err
346+
}
347+
if err := writeUvarint(uint64(len(batch.data))); err != nil {
348+
return total, err
349+
}
342350
}
343351

344352
// Write batch data.

0 commit comments

Comments
 (0)