Skip to content

Commit 2d21614

Browse files
felixgegopherbot
authored andcommitted
internal/trace: expose clock snapshot timestamps on sync event
Add ClockSnapshot field to the Sync event type and populate it with the information from the new EvClockSnapshot event when available. For #69869 Change-Id: I3b24b5bfa15cc7a7dba270f5e6bf189adb096840 Reviewed-on: https://go-review.googlesource.com/c/go/+/653576 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
1 parent 112c236 commit 2d21614

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/internal/trace/event.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,22 @@ func (e Event) Sync() Sync {
665665
if e.Kind() != EventSync {
666666
panic("Sync called on non-Sync event")
667667
}
668-
var expBatches map[string][]ExperimentalBatch
668+
s := Sync{N: int(e.base.args[0])}
669669
if e.table != nil {
670-
expBatches = make(map[string][]ExperimentalBatch)
670+
expBatches := make(map[string][]ExperimentalBatch)
671671
for exp, batches := range e.table.expBatches {
672672
expBatches[tracev2.Experiments()[exp]] = batches
673673
}
674+
s.ExperimentalBatches = expBatches
675+
if e.table.hasClockSnapshot {
676+
s.ClockSnapshot = &ClockSnapshot{
677+
Trace: e.table.freq.mul(e.table.snapTime),
678+
Wall: e.table.snapWall,
679+
Mono: e.table.snapMono,
680+
}
681+
}
674682
}
675-
return Sync{
676-
N: int(e.base.args[0]),
677-
ExperimentalBatches: expBatches,
678-
}
683+
return s
679684
}
680685

681686
// Sync contains details potentially relevant to all the following events, up to but excluding
@@ -684,10 +689,30 @@ type Sync struct {
684689
// N indicates that this is the Nth sync event in the trace.
685690
N int
686691

692+
// ClockSnapshot is a snapshot of different clocks taken in close in time
693+
// that can be used to correlate trace events with data captured by other
694+
// tools. May be nil for older trace versions.
695+
ClockSnapshot *ClockSnapshot
696+
687697
// ExperimentalBatches contain all the unparsed batches of data for a given experiment.
688698
ExperimentalBatches map[string][]ExperimentalBatch
689699
}
690700

701+
// ClockSnapshot represents a near-simultaneous clock reading of several
702+
// different system clocks. The snapshot can be used as a reference to convert
703+
// timestamps to different clocks, which is helpful for correlating timestamps
704+
// with data captured by other tools.
705+
type ClockSnapshot struct {
706+
// Trace is a snapshot of the trace clock.
707+
Trace Time
708+
709+
// Wall is a snapshot of the system's wall clock.
710+
Wall time.Time
711+
712+
// Mono is a snapshot of the system's monotonic clock.
713+
Mono uint64
714+
}
715+
691716
// Experimental returns a view of the raw event for an experimental event.
692717
//
693718
// Panics if Kind != EventExperimental.
@@ -844,6 +869,16 @@ func (e Event) String() string {
844869
fmt.Fprintf(&sb, "%s=%s", arg, r.ArgValue(i).String())
845870
}
846871
fmt.Fprintf(&sb, "]")
872+
case EventSync:
873+
s := e.Sync()
874+
fmt.Fprintf(&sb, " N=%d", s.N)
875+
if s.ClockSnapshot != nil {
876+
fmt.Fprintf(&sb, " Trace=%d Mono=%d Wall=%s",
877+
s.ClockSnapshot.Trace,
878+
s.ClockSnapshot.Mono,
879+
s.ClockSnapshot.Wall.Format(time.RFC3339),
880+
)
881+
}
847882
}
848883
if stk := e.Stack(); stk != NoStack {
849884
fmt.Fprintln(&sb)

0 commit comments

Comments
 (0)