traceviewer

Imports

Imports #

"encoding/json"
"fmt"
"internal/trace"
"internal/trace/traceviewer/format"
"io"
"strconv"
"time"
"fmt"
"html/template"
"math"
"strings"
"time"
"embed"
"fmt"
"html/template"
"net/http"
"strings"
"encoding/json"
"fmt"
"internal/trace"
"log"
"math"
"net/http"
"strconv"
"strings"
"sync"
"time"
"bufio"
"fmt"
"internal/profile"
"internal/trace"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"

Constants & Variables

CommonStyle const #

const CommonStyle = `
/* See https://github.com/golang/pkgsite/blob/master/static/shared/typography/typography.css */
body {
  font-family:	-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  font-size:	1rem;
  line-height:	normal;
  max-width:	9in;
  margin:	1em;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.375rem; }
h1,h2 {
  font-weight: 600;
  line-height: 1.25em;
  word-break: break-word;
}
p  { color: grey85; font-size:85%; }
code,
pre,
textarea.code {
  font-family: SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.875rem;
  line-height: 1.5em;
}

pre,
textarea.code {
  background-color: var(--color-background-accented);
  border: var(--border);
  border-radius: var(--border-radius);
  color: var(--color-text);
  overflow-x: auto;
  padding: 0.625rem;
  tab-size: 4;
  white-space: pre;
}
`

GDead const #

const GDead GState = iota

GRunnable const #

const GRunnable

GRunning const #

const GRunning

GWaiting const #

const GWaiting

GWaitingGC const #

const GWaitingGC

ModeGoroutineOriented const #

const ModeGoroutineOriented Mode = *ast.BinaryExpr

ModeTaskOriented const #

const ModeTaskOriented

ModeThreadOriented const #

const ModeThreadOriented

ThreadStateInSyscall const #

const ThreadStateInSyscall ThreadState = iota

ThreadStateInSyscallRuntime const #

const ThreadStateInSyscallRuntime

ThreadStateRunning const #

const ThreadStateRunning

ViewProc const #

const ViewProc ViewType = "proc"

ViewThread const #

const ViewThread ViewType = "thread"

colorAnotherGrey const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorAnotherGrey = "cq_build_attempt_failed"

colorBlack const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorBlack = "black"

colorBlue const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorBlue = "vsync_highlight_color"

colorCornflowerBlue const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorCornflowerBlue = "rail_response"

colorDarkGoldenrod const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorDarkGoldenrod = "bad"

colorDarkGrey const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorDarkGrey = "heap_dump_stack_frame"

colorDeepMagenta const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorDeepMagenta = "detailed_memory_dump"

colorForTask var #

var colorForTask = []string{...}

colorGreen const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorGreen = "good"

colorGreenishYellow const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorGreenishYellow = "startup"

colorGrey const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorGrey = "generic_work"

colorIrisBlue const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorIrisBlue = "background_memory_dump"

colorKellyGreen const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorKellyGreen = "cq_build_attempt_passed"

colorLemon const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorLemon = "cq_build_running"

colorLightGrey const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorLightGrey = "grey"

colorLightMauve const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorLightMauve = "thread_state_uninterruptible"

colorLime const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorLime = "cq_build_passed"

colorManzGreen const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorManzGreen = "cq_build_attempt_runnig"

colorMidnightBlue const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorMidnightBlue = "light_memory_dump"

colorOlive const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorOlive = "olive"

colorOrange const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorOrange = "thread_state_iowait"

colorPeach const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorPeach = "terrible"

colorPink const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorPink = "cq_build_failed"

colorSeafoamGreen const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorSeafoamGreen = "thread_state_running"

colorShamrockGreen const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorShamrockGreen = "rail_load"

colorSilver const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorSilver = "cq_build_abandoned"

colorSunsetOrange const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorSunsetOrange = "rail_animation"

colorTan const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorTan = "thread_state_unknown"

colorTangerine const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorTangerine = "rail_idle"

colorTawny const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorTawny = "heap_dump_child_node_arrow"

colorVistaBlue const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorVistaBlue = "thread_state_runnable"

colorWhite const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorWhite = "white"

colorYellow const #

Mapping from more reasonable color names to the reserved color names in https://github.com/catapult-project/catapult/blob/master/tracing/tracing/base/color_scheme.html#L50 The chrome trace viewer allows only those as cname values.

const colorYellow = "yellow"

gStateCount const #

const gStateCount

logDiv var #

Five buckets for every power of 10.

var logDiv = *ast.CallExpr

staticContent var #

go:embed static/trace_viewer_full.html static/webcomponents.min.js

var staticContent embed.FS

templMMU var #

var templMMU = `

  
    
    
    
    
    
  
  
    
Loading plot...

View
?Consider whole system utilization. For example, if one of four procs is available to the mutator, mutator utilization will be 0.25. This is the standard definition of an MMU.
?Consider per-goroutine utilization. When even one goroutine is interrupted by GC, mutator utilization is 0.

Include
?Stop-the-world stops all goroutines simultaneously.
?Background workers are GC-specific goroutines. 25% of the CPU is dedicated to background workers during GC.
?Mark assists are performed by allocation to prevent the mutator from outpacing GC.
?Sweep reclaims unused memory between GCs. (Enabling this may be very slow.).

Display
?Display percentile mutator utilization in addition to minimum. E.g., p99 MU drops the worst 1% of windows.

Select a point for details.
`

templMain var #

var templMain = *ast.CallExpr

templTrace var #

https://chromium.googlesource.com/catapult/+/9508452e18f130c98499cb4c4f1e1efaedee8962/tracing/docs/embedding-trace-viewer.md This is almost verbatim copy of https://chromium-review.googlesource.com/c/catapult/+/2062938/2/tracing/bin/index.html

var templTrace = `













`

threadStateCount const #

const threadStateCount

utilFlagNames var #

var utilFlagNames = map[string]trace.UtilFlags{...}

Type Aliases

GState type #

type GState int

Mode type #

type Mode int

MutatorUtilFunc type #

type MutatorUtilFunc func(trace.UtilFlags) ([][]trace.MutatorUtil, error)

ProfileFunc type #

type ProfileFunc func(r *http.Request) ([]ProfileRecord, error)

ThreadState type #

type ThreadState int

ViewType type #

type ViewType string

Structs

ArrowEvent struct #

type ArrowEvent struct {
Name string
Start time.Duration
End time.Duration
FromResource uint64
FromStack int
ToResource uint64
}

AsyncSliceEvent struct #

type AsyncSliceEvent struct {
SliceEvent
Category string
Scope string
TaskColorIndex uint64
}

Emitter struct #

type Emitter struct {
c TraceConsumer
rangeStart time.Duration
rangeEnd time.Duration
heapStats heapStats
prevHeapStats heapStats
gstates [gStateCount]int64
prevGstates [gStateCount]int64
threadStats [threadStateCount]int64
prevThreadStats [threadStateCount]int64
gomaxprocs uint64
frameTree frameNode
frameSeq int
arrowSeq uint64
filter func(uint64) bool
resourceType string
resources map[uint64]string
focusResource uint64
tasks map[uint64]task
asyncSliceSeq uint64
}

InstantEvent struct #

type InstantEvent struct {
Ts time.Duration
Name string
Category string
Resource uint64
Stack int
Arg any
}

ProfileRecord struct #

type ProfileRecord struct {
Stack []*trace.Frame
Count uint64
Time time.Duration
}

Range struct #

type Range struct {
Name string
Start int
End int
StartTime int64
EndTime int64
}

SliceEvent struct #

type SliceEvent struct {
Name string
Ts time.Duration
Dur time.Duration
Resource uint64
Stack int
EndStack int
Arg any
}

TimeHistogram struct #

TimeHistogram is an high-dynamic-range histogram for durations.

type TimeHistogram struct {
Count int
Buckets []int
MinBucket int
MaxBucket int
}

TraceConsumer struct #

type TraceConsumer struct {
ConsumeTimeUnit func(unit string)
ConsumeViewerEvent func(v *format.Event, required bool)
ConsumeViewerFrame func(key string, f format.Frame)
Flush func()
}

View struct #

type View struct {
Type ViewType
Ranges []Range
}

countingWriter struct #

type countingWriter struct {
size int
}

frameNode struct #

type frameNode struct {
id int
children map[uint64]frameNode
}

heapStats struct #

type heapStats struct {
heapAlloc uint64
nextGC uint64
}

linkedUtilWindow struct #

type linkedUtilWindow struct {
trace.UtilWindow
URL string
}

mmu struct #

type mmu struct {
mu sync.Mutex
cache map[trace.UtilFlags]*mmuCacheEntry
f MutatorUtilFunc
ranges []Range
}

mmuCacheEntry struct #

type mmuCacheEntry struct {
init sync.Once
util [][]trace.MutatorUtil
mmuCurve *trace.MMUCurve
err error
}

splitter struct #

type splitter struct {
Ranges []Range
}

task struct #

type task struct {
name string
sortIndex int
}

Functions

Add method #

Add adds a single sample to the histogram.

func (h *TimeHistogram) Add(d time.Duration)

Arrow method #

func (e *Emitter) Arrow(a ArrowEvent)

AsyncSlice method #

func (e *Emitter) AsyncSlice(s AsyncSliceEvent)

BucketMin method #

BucketMin returns the minimum duration value for a provided bucket.

func (h *TimeHistogram) BucketMin(bucket int) time.Duration

BuildProfile function #

func BuildProfile(prof []ProfileRecord) *profile.Profile

Err method #

Err returns an error if the emitter is in an invalid state.

func (e *Emitter) Err() error

Event method #

func (e *Emitter) Event(ev *format.Event)

Flush method #

func (e *Emitter) Flush()

Focus method #

func (e *Emitter) Focus(id uint64)

Gomaxprocs method #

func (e *Emitter) Gomaxprocs(v uint64)

GoroutineTransition method #

func (e *Emitter) GoroutineTransition(ts time.Duration, from GState, to GState)

HandleDetails method #

HandleDetails serves details of an MMU graph at a particular window.

func (m *mmu) HandleDetails(w http.ResponseWriter, r *http.Request)

HandlePlot method #

HandlePlot serves the JSON data for the MMU plot.

func (m *mmu) HandlePlot(w http.ResponseWriter, r *http.Request)

HeapAlloc method #

func (e *Emitter) HeapAlloc(ts time.Duration, v uint64)

HeapGoal method #

func (e *Emitter) HeapGoal(ts time.Duration, v uint64)

IncThreadStateCount method #

func (e *Emitter) IncThreadStateCount(ts time.Duration, state ThreadState, delta int64)

Instant method #

func (e *Emitter) Instant(i InstantEvent)

MMUHandlerFunc function #

func MMUHandlerFunc(ranges []Range, f MutatorUtilFunc) http.HandlerFunc

MainHandler function #

func MainHandler(views []View) http.Handler

NewEmitter function #

NewEmitter returns a new Emitter that writes to c. The rangeStart and rangeEnd args are used for splitting large traces.

func NewEmitter(c TraceConsumer, rangeStart time.Duration, rangeEnd time.Duration) *Emitter

OptionalEvent method #

OptionalEvent emits ev if it's within the time range of the consumer, i.e. the selected trace split range.

func (e *Emitter) OptionalEvent(ev *format.Event)

Resource method #

func (e *Emitter) Resource(id uint64, name string)

SVGProfileHandlerFunc function #

SVGProfileHandlerFunc serves pprof-like profile generated by prof as svg.

func SVGProfileHandlerFunc(f ProfileFunc) http.HandlerFunc

SetResourceFilter method #

func (e *Emitter) SetResourceFilter(filter func(uint64) bool)

SetResourceType method #

func (e *Emitter) SetResourceType(name string)

Slice method #

func (e *Emitter) Slice(s SliceEvent)

SplittingTraceConsumer function #

func SplittingTraceConsumer(max int) (*splitter, TraceConsumer)

Stack method #

Stack emits the given frames and returns a unique id for the stack. No pointers to the given data are being retained beyond the call to Stack.

func (e *Emitter) Stack(stk []*trace.Frame) int

StaticHandler function #

func StaticHandler() http.Handler

Task method #

func (e *Emitter) Task(id uint64, name string, sortIndex int)

TaskArrow method #

func (e *Emitter) TaskArrow(a ArrowEvent)

TaskSlice method #

func (e *Emitter) TaskSlice(s SliceEvent)

ToHTML method #

ToHTML renders the histogram as HTML.

func (h *TimeHistogram) ToHTML(urlmaker func(min time.Duration, max time.Duration) string) template.HTML

TraceHandler function #

func TraceHandler() http.Handler

URL method #

func (r Range) URL(viewType ViewType) string

URL method #

func (v View) URL(rangeIdx int) string

ViewerDataTraceConsumer function #

ViewerDataTraceConsumer returns a TraceConsumer that writes to w. The startIdx and endIdx are used for splitting large traces. They refer to indexes in the traceEvents output array, not the events in the trace input.

func ViewerDataTraceConsumer(w io.Writer, startIdx int64, endIdx int64) TraceConsumer

WalkStackFrames function #

WalkStackFrames calls fn for id and all of its parent frames from allFrames.

func WalkStackFrames(allFrames map[string]format.Frame, id int, fn func(id int))

Write method #

func (cw *countingWriter) Write(data []byte) (int, error)

arrow method #

func (e *Emitter) arrow(a ArrowEvent, sectionID uint64)

buildBranch method #

buildBranch builds one branch in the prefix tree rooted at ctx.frameTree.

func (e *Emitter) buildBranch(parent frameNode, stk []*trace.Frame) int

emitHeapCounters method #

func (e *Emitter) emitHeapCounters(ts time.Duration)

get method #

func (m *mmu) get(flags trace.UtilFlags) ([][]trace.MutatorUtil, *trace.MMUCurve, error)

goCmd function #

func goCmd() string

newLinkedUtilWindow method #

func (m *mmu) newLinkedUtilWindow(ui trace.UtilWindow, window time.Duration) linkedUtilWindow

pickTaskColor function #

func pickTaskColor(id uint64) string

processMeta method #

func (e *Emitter) processMeta(sectionID uint64, name string, priority int)

requestUtilFlags function #

func requestUtilFlags(r *http.Request) trace.UtilFlags

slice method #

func (e *Emitter) slice(s SliceEvent, sectionID uint64, cname string)

stackFrameEncodedSize function #

func stackFrameEncodedSize(id uint, f format.Frame) int

threadMeta method #

func (e *Emitter) threadMeta(sectionID uint64, tid uint64, name string, priority int)

tsWithinRange method #

func (e *Emitter) tsWithinRange(ts time.Duration) bool

viewerTime function #

func viewerTime(t time.Duration) float64

Generated with Arrow