Source file src/runtime/traceexp.go

     1  // Copyright 2024 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 runtime
     6  
     7  // expWriter returns a traceWriter that writes into the current M's stream for
     8  // the given experiment.
     9  func (tl traceLocker) expWriter(exp traceExperiment) traceWriter {
    10  	return traceWriter{traceLocker: tl, traceBuf: tl.mp.trace.buf[tl.gen%2][exp], exp: exp}
    11  }
    12  
    13  // unsafeTraceExpWriter produces a traceWriter for experimental trace batches
    14  // that doesn't lock the trace. Data written to experimental batches need not
    15  // conform to the standard trace format.
    16  //
    17  // It should only be used in contexts where either:
    18  // - Another traceLocker is held.
    19  // - trace.gen is prevented from advancing.
    20  //
    21  // This does not have the same stack growth restrictions as traceLocker.writer.
    22  //
    23  // buf may be nil.
    24  func unsafeTraceExpWriter(gen uintptr, buf *traceBuf, exp traceExperiment) traceWriter {
    25  	return traceWriter{traceLocker: traceLocker{gen: gen}, traceBuf: buf, exp: exp}
    26  }
    27  
    28  // traceExperiment is an enumeration of the different kinds of experiments supported for tracing.
    29  type traceExperiment uint8
    30  
    31  const (
    32  	// traceNoExperiment indicates no experiment.
    33  	traceNoExperiment traceExperiment = iota
    34  
    35  	// traceExperimentAllocFree is an experiment to add alloc/free events to the trace.
    36  	traceExperimentAllocFree
    37  
    38  	// traceNumExperiments is the number of trace experiments (and 1 higher than
    39  	// the highest numbered experiment).
    40  	traceNumExperiments
    41  )
    42  
    43  // Experimental events.
    44  const (
    45  	_ traceEv = 127 + iota
    46  
    47  	// Experimental events for ExperimentAllocFree.
    48  
    49  	// Experimental heap span events. IDs map reversibly to base addresses.
    50  	traceEvSpan      // heap span exists [timestamp, id, npages, type/class]
    51  	traceEvSpanAlloc // heap span alloc [timestamp, id, npages, type/class]
    52  	traceEvSpanFree  // heap span free [timestamp, id]
    53  
    54  	// Experimental heap object events. IDs map reversibly to addresses.
    55  	traceEvHeapObject      // heap object exists [timestamp, id, type]
    56  	traceEvHeapObjectAlloc // heap object alloc [timestamp, id, type]
    57  	traceEvHeapObjectFree  // heap object free [timestamp, id]
    58  
    59  	// Experimental goroutine stack events. IDs map reversibly to addresses.
    60  	traceEvGoroutineStack      // stack exists [timestamp, id, order]
    61  	traceEvGoroutineStackAlloc // stack alloc [timestamp, id, order]
    62  	traceEvGoroutineStackFree  // stack free [timestamp, id]
    63  )
    64  

View as plain text