Commit 1cbbd7f5 authored by Dmitry Vyukov's avatar Dmitry Vyukov

cmd/trace: fix time scale

Integrate the latest trace-viewer changes.
It now handles nanoseconds without any issues (thanks to @egonelbre!).
So change timestamps from microseconds to nanoseconds.

Change-Id: I010f27effde7e80c9992e6f276f6912354d27df4
Reviewed-on: https://go-review.googlesource.com/11244Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarEgon Elbre <egonelbre@gmail.com>
parent 6fe9c4a7
...@@ -2,7 +2,7 @@ This directory contains helper file for trace viewer (`go tool trace`). ...@@ -2,7 +2,7 @@ This directory contains helper file for trace viewer (`go tool trace`).
`trace_viewer_lean.html` was generated by following `trace_viewer_lean.html` was generated by following
[instructions](https://github.com/google/trace-viewer/wiki/Embedding) [instructions](https://github.com/google/trace-viewer/wiki/Embedding)
on revision `3c695b420a09db9933686fa958f1765c373c372e` using: on revision `280626ef607decf36291e290d5f0322b173e8a7f` using:
``` ```
trace-viewer$ ./vulcanize_trace_viewer --config=lean trace-viewer$ ./vulcanize_trace_viewer --config=lean
trace-viewer$ cp bin/trace_viewer_lean.html $GOROOT/misc/trace/ trace-viewer$ cp bin/trace_viewer_lean.html $GOROOT/misc/trace/
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -130,16 +130,17 @@ type frameNode struct { ...@@ -130,16 +130,17 @@ type frameNode struct {
} }
type ViewerData struct { type ViewerData struct {
Events []*ViewerEvent `json:"traceEvents"` Events []*ViewerEvent `json:"traceEvents"`
Frames map[string]ViewerFrame `json:"stackFrames"` Frames map[string]ViewerFrame `json:"stackFrames"`
TimeUnit string `json:"displayTimeUnit"`
} }
type ViewerEvent struct { type ViewerEvent struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Phase string `json:"ph"` Phase string `json:"ph"`
Scope string `json:"s,omitempty"` Scope string `json:"s,omitempty"`
Time int64 `json:"ts"` Time float64 `json:"ts"`
Dur int64 `json:"dur,omitempty"` Dur float64 `json:"dur,omitempty"`
Pid uint64 `json:"pid"` Pid uint64 `json:"pid"`
Tid uint64 `json:"tid"` Tid uint64 `json:"tid"`
ID uint64 `json:"id,omitempty"` ID uint64 `json:"id,omitempty"`
...@@ -172,6 +173,7 @@ func generateTrace(params *traceParams) ViewerData { ...@@ -172,6 +173,7 @@ func generateTrace(params *traceParams) ViewerData {
ctx := &traceContext{traceParams: params} ctx := &traceContext{traceParams: params}
ctx.frameTree.children = make(map[uint64]frameNode) ctx.frameTree.children = make(map[uint64]frameNode)
ctx.data.Frames = make(map[string]ViewerFrame) ctx.data.Frames = make(map[string]ViewerFrame)
ctx.data.TimeUnit = "ns"
maxProc := 0 maxProc := 0
gnames := make(map[uint64]string) gnames := make(map[uint64]string)
for _, ev := range ctx.events { for _, ev := range ctx.events {
...@@ -322,12 +324,9 @@ func (ctx *traceContext) emit(e *ViewerEvent) { ...@@ -322,12 +324,9 @@ func (ctx *traceContext) emit(e *ViewerEvent) {
ctx.data.Events = append(ctx.data.Events, e) ctx.data.Events = append(ctx.data.Events, e)
} }
func (ctx *traceContext) time(ev *trace.Event) int64 { func (ctx *traceContext) time(ev *trace.Event) float64 {
// NOTE: trace viewer wants timestamps in microseconds and it does not // Trace viewer wants timestamps in microseconds.
// handle fractional timestamps (rounds them). We give it timestamps return float64(ev.Ts-ctx.startTime) / 1000
// in nanoseconds to avoid rounding. See:
// https://github.com/google/trace-viewer/issues/624
return ev.Ts - ctx.startTime
} }
func (ctx *traceContext) proc(ev *trace.Event) uint64 { func (ctx *traceContext) proc(ev *trace.Event) uint64 {
...@@ -408,6 +407,12 @@ func (ctx *traceContext) emitArrow(ev *trace.Event, name string) { ...@@ -408,6 +407,12 @@ func (ctx *traceContext) emitArrow(ev *trace.Event, name string) {
return return
} }
if ev.P == trace.NetpollP || ev.P == trace.TimerP || ev.P == trace.SyscallP {
// Trace-viewer discards arrows if they don't start/end inside of a slice or instant.
// So emit a fake instant at the start of the arrow.
ctx.emitInstant(&trace.Event{P: ev.P, Ts: ev.Ts}, "unblock")
}
ctx.arrowSeq++ ctx.arrowSeq++
ctx.emit(&ViewerEvent{Name: name, Phase: "s", Tid: ctx.proc(ev), ID: ctx.arrowSeq, Time: ctx.time(ev), Stack: ctx.stack(ev.Stk)}) ctx.emit(&ViewerEvent{Name: name, Phase: "s", Tid: ctx.proc(ev), ID: ctx.arrowSeq, Time: ctx.time(ev), Stack: ctx.stack(ev.Stk)})
ctx.emit(&ViewerEvent{Name: name, Phase: "t", Tid: ctx.proc(ev.Link), ID: ctx.arrowSeq, Time: ctx.time(ev.Link)}) ctx.emit(&ViewerEvent{Name: name, Phase: "t", Tid: ctx.proc(ev.Link), ID: ctx.arrowSeq, Time: ctx.time(ev.Link)})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment