diff options
| author | Hana Kim <hakim@google.com> | 2018-04-19 14:58:42 -0400 |
|---|---|---|
| committer | Hyang-Ah Hana Kim <hyangah@gmail.com> | 2018-04-24 16:33:15 +0000 |
| commit | c2d10243688194346f660591fe4159e30a8d20ec (patch) | |
| tree | 9c3bf5c9b2f307ce2a655ef97fac72f2e1fe430f /src/internal/trace/parser.go | |
| parent | fb017c60bc60f8df771ac2a9119ec55ea915929c (diff) | |
| download | go-c2d10243688194346f660591fe4159e30a8d20ec.tar.xz | |
runtime/trace: rename "Span" with "Region"
"Span" is a commonly used term in many distributed tracing systems
(Dapper, OpenCensus, OpenTracing, ...). They use it to refer to a
period of time, not necessarily tied into execution of underlying
processor, thread, or goroutine, unlike the "Span" of runtime/trace
package.
Since distributed tracing and go runtime execution tracing are
already similar enough to cause confusion, this CL attempts to avoid
using the same word if possible.
"Region" is being used in a certain tracing system to refer to a code
region which is pretty close to what runtime/trace.Span currently
refers to. So, replace that.
https://software.intel.com/en-us/itc-user-and-reference-guide-defining-and-recording-functions-or-regions
This CL also tweaks APIs a bit based on jbd and heschi's comments:
NewContext -> NewTask
and it now returns a Task object that exports End method.
StartSpan -> StartRegion
and it now returns a Region object that exports End method.
Also, changed WithSpan to WithRegion and it now takes func() with no
context. Another thought is to get rid of WithRegion. It is a nice
concept but in practice, it seems problematic (a lot of code churn,
and polluting stack trace). Already, the tracing concept is very low
level, and we hope this API to be used with great care.
Recommended usage will be
defer trace.StartRegion(ctx, "someRegion").End()
Left old APIs untouched in this CL. Once the usage of them are cleaned
up, they will be removed in a separate CL.
Change-Id: I73880635e437f3aad51314331a035dd1459b9f3a
Reviewed-on: https://go-review.googlesource.com/108296
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: JBD <jbd@google.com>
Diffstat (limited to 'src/internal/trace/parser.go')
| -rw-r--r-- | src/internal/trace/parser.go | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/internal/trace/parser.go b/src/internal/trace/parser.go index 6d142a593f..c371ff3092 100644 --- a/src/internal/trace/parser.go +++ b/src/internal/trace/parser.go @@ -56,7 +56,7 @@ type Event struct { // for GoSysExit: the next GoStart // for GCMarkAssistStart: the associated GCMarkAssistDone // for UserTaskCreate: the UserTaskEnd - // for UserSpan: if the start span, the corresponding UserSpan end event + // for UserRegion: if the start region, the corresponding UserRegion end event Link *Event } @@ -442,7 +442,7 @@ func parseEvents(ver int, rawEvents []rawEvent, strings map[uint64]string) (even case EvUserTaskCreate: // e.Args 0: taskID, 1:parentID, 2:nameID e.SArgs = []string{strings[e.Args[2]]} - case EvUserSpan: + case EvUserRegion: // e.Args 0: taskID, 1: mode, 2:nameID e.SArgs = []string{strings[e.Args[2]]} case EvUserLog: @@ -583,8 +583,8 @@ func postProcessTrace(ver int, events []*Event) error { gs := make(map[uint64]gdesc) ps := make(map[int]pdesc) - tasks := make(map[uint64]*Event) // task id to task creation events - activeSpans := make(map[uint64][]*Event) // goroutine id to stack of spans + tasks := make(map[uint64]*Event) // task id to task creation events + activeRegions := make(map[uint64][]*Event) // goroutine id to stack of regions gs[0] = gdesc{state: gRunning} var evGC, evSTW *Event @@ -730,12 +730,12 @@ func postProcessTrace(ver int, events []*Event) error { g.state = gDead p.g = 0 - if ev.Type == EvGoEnd { // flush all active spans - spans := activeSpans[ev.G] - for _, s := range spans { + if ev.Type == EvGoEnd { // flush all active regions + regions := activeRegions[ev.G] + for _, s := range regions { s.Link = ev } - delete(activeSpans, ev.G) + delete(activeRegions, ev.G) } case EvGoSched, EvGoPreempt: @@ -811,29 +811,29 @@ func postProcessTrace(ver int, events []*Event) error { taskCreateEv.Link = ev delete(tasks, taskid) } - case EvUserSpan: + case EvUserRegion: mode := ev.Args[1] - spans := activeSpans[ev.G] - if mode == 0 { // span start - activeSpans[ev.G] = append(spans, ev) // push - } else if mode == 1 { // span end - n := len(spans) - if n > 0 { // matching span start event is in the trace. - s := spans[n-1] - if s.Args[0] != ev.Args[0] || s.SArgs[0] != ev.SArgs[0] { // task id, span name mismatch - return fmt.Errorf("misuse of span in goroutine %d: span end %q when the inner-most active span start event is %q", ev.G, ev, s) + regions := activeRegions[ev.G] + if mode == 0 { // region start + activeRegions[ev.G] = append(regions, ev) // push + } else if mode == 1 { // region end + n := len(regions) + if n > 0 { // matching region start event is in the trace. + s := regions[n-1] + if s.Args[0] != ev.Args[0] || s.SArgs[0] != ev.SArgs[0] { // task id, region name mismatch + return fmt.Errorf("misuse of region in goroutine %d: span end %q when the inner-most active span start event is %q", ev.G, ev, s) } - // Link span start event with span end event + // Link region start event with span end event s.Link = ev if n > 1 { - activeSpans[ev.G] = spans[:n-1] + activeRegions[ev.G] = regions[:n-1] } else { - delete(activeSpans, ev.G) + delete(activeRegions, ev.G) } } } else { - return fmt.Errorf("invalid user span mode: %q", ev) + return fmt.Errorf("invalid user region mode: %q", ev) } } @@ -1056,7 +1056,7 @@ const ( EvGCMarkAssistDone = 44 // GC mark assist done [timestamp] EvUserTaskCreate = 45 // trace.NewContext [timestamp, internal task id, internal parent id, stack, name string] EvUserTaskEnd = 46 // end of task [timestamp, internal task id, stack] - EvUserSpan = 47 // trace.WithSpan [timestamp, internal task id, mode(0:start, 1:end), stack, name string] + EvUserRegion = 47 // trace.WithRegion [timestamp, internal task id, mode(0:start, 1:end), stack, name string] EvUserLog = 48 // trace.Log [timestamp, internal id, key string id, stack, value string] EvCount = 49 ) @@ -1115,6 +1115,6 @@ var EventDescriptions = [EvCount]struct { EvGCMarkAssistDone: {"GCMarkAssistDone", 1009, false, []string{}, nil}, EvUserTaskCreate: {"UserTaskCreate", 1011, true, []string{"taskid", "pid", "typeid"}, []string{"name"}}, EvUserTaskEnd: {"UserTaskEnd", 1011, true, []string{"taskid"}, nil}, - EvUserSpan: {"UserSpan", 1011, true, []string{"taskid", "mode", "typeid"}, []string{"name"}}, + EvUserRegion: {"UserRegion", 1011, true, []string{"taskid", "mode", "typeid"}, []string{"name"}}, EvUserLog: {"UserLog", 1011, true, []string{"id", "keyid"}, []string{"category", "message"}}, } |
