...

Source file src/cmd/trace/viewer.go

Documentation: cmd/trace

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"internal/trace"
    10  	"internal/trace/traceviewer"
    11  	"time"
    12  )
    13  
    14  // viewerFrames returns the frames of the stack of ev. The given frame slice is
    15  // used to store the frames to reduce allocations.
    16  func viewerFrames(stk trace.Stack) []*trace.Frame {
    17  	var frames []*trace.Frame
    18  	stk.Frames(func(f trace.StackFrame) bool {
    19  		frames = append(frames, &trace.Frame{
    20  			PC:   f.PC,
    21  			Fn:   f.Func,
    22  			File: f.File,
    23  			Line: int(f.Line),
    24  		})
    25  		return true
    26  	})
    27  	return frames
    28  }
    29  
    30  func viewerGState(state trace.GoState, inMarkAssist bool) traceviewer.GState {
    31  	switch state {
    32  	case trace.GoUndetermined:
    33  		return traceviewer.GDead
    34  	case trace.GoNotExist:
    35  		return traceviewer.GDead
    36  	case trace.GoRunnable:
    37  		return traceviewer.GRunnable
    38  	case trace.GoRunning:
    39  		return traceviewer.GRunning
    40  	case trace.GoWaiting:
    41  		if inMarkAssist {
    42  			return traceviewer.GWaitingGC
    43  		}
    44  		return traceviewer.GWaiting
    45  	case trace.GoSyscall:
    46  		// N.B. A goroutine in a syscall is considered "executing" (state.Executing() == true).
    47  		return traceviewer.GRunning
    48  	default:
    49  		panic(fmt.Sprintf("unknown GoState: %s", state.String()))
    50  	}
    51  }
    52  
    53  func viewerTime(t time.Duration) float64 {
    54  	return float64(t) / float64(time.Microsecond)
    55  }
    56  

View as plain text