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/11244
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Dmitry Vyukov 2015-06-18 16:27:29 +02:00
parent 6fe9c4a7bd
commit 1cbbd7f545
3 changed files with 1013 additions and 949 deletions

View file

@ -2,7 +2,7 @@ This directory contains helper file for trace viewer (`go tool trace`).
`trace_viewer_lean.html` was generated by following
[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$ cp bin/trace_viewer_lean.html $GOROOT/misc/trace/

File diff suppressed because one or more lines are too long

View file

@ -132,14 +132,15 @@ type frameNode struct {
type ViewerData struct {
Events []*ViewerEvent `json:"traceEvents"`
Frames map[string]ViewerFrame `json:"stackFrames"`
TimeUnit string `json:"displayTimeUnit"`
}
type ViewerEvent struct {
Name string `json:"name,omitempty"`
Phase string `json:"ph"`
Scope string `json:"s,omitempty"`
Time int64 `json:"ts"`
Dur int64 `json:"dur,omitempty"`
Time float64 `json:"ts"`
Dur float64 `json:"dur,omitempty"`
Pid uint64 `json:"pid"`
Tid uint64 `json:"tid"`
ID uint64 `json:"id,omitempty"`
@ -172,6 +173,7 @@ func generateTrace(params *traceParams) ViewerData {
ctx := &traceContext{traceParams: params}
ctx.frameTree.children = make(map[uint64]frameNode)
ctx.data.Frames = make(map[string]ViewerFrame)
ctx.data.TimeUnit = "ns"
maxProc := 0
gnames := make(map[uint64]string)
for _, ev := range ctx.events {
@ -322,12 +324,9 @@ func (ctx *traceContext) emit(e *ViewerEvent) {
ctx.data.Events = append(ctx.data.Events, e)
}
func (ctx *traceContext) time(ev *trace.Event) int64 {
// NOTE: trace viewer wants timestamps in microseconds and it does not
// handle fractional timestamps (rounds them). We give it timestamps
// in nanoseconds to avoid rounding. See:
// https://github.com/google/trace-viewer/issues/624
return ev.Ts - ctx.startTime
func (ctx *traceContext) time(ev *trace.Event) float64 {
// Trace viewer wants timestamps in microseconds.
return float64(ev.Ts-ctx.startTime) / 1000
}
func (ctx *traceContext) proc(ev *trace.Event) uint64 {
@ -408,6 +407,12 @@ func (ctx *traceContext) emitArrow(ev *trace.Event, name string) {
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.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)})