Source file src/cmd/trace/viewer.go

     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  	for f := range stk.Frames() {
    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  	}
    26  	return frames
    27  }
    28  
    29  func viewerGState(state trace.GoState, inMarkAssist bool) traceviewer.GState {
    30  	switch state {
    31  	case trace.GoUndetermined:
    32  		return traceviewer.GDead
    33  	case trace.GoNotExist:
    34  		return traceviewer.GDead
    35  	case trace.GoRunnable:
    36  		return traceviewer.GRunnable
    37  	case trace.GoRunning:
    38  		return traceviewer.GRunning
    39  	case trace.GoWaiting:
    40  		if inMarkAssist {
    41  			return traceviewer.GWaitingGC
    42  		}
    43  		return traceviewer.GWaiting
    44  	case trace.GoSyscall:
    45  		// N.B. A goroutine in a syscall is considered "executing" (state.Executing() == true).
    46  		return traceviewer.GRunning
    47  	default:
    48  		panic(fmt.Sprintf("unknown GoState: %s", state.String()))
    49  	}
    50  }
    51  
    52  func viewerTime(t time.Duration) float64 {
    53  	return float64(t) / float64(time.Microsecond)
    54  }
    55  

View as plain text