diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2024-05-20 20:31:36 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-22 20:31:27 +0000 |
| commit | efe7a1f5d3ccdef5c25cb4d8386492a7b1785600 (patch) | |
| tree | 17d999b94c25ecd3f5e54bac6426b10e08dc4661 /src/runtime/traceallocfree.go | |
| parent | fb5d0cdd491017db1978001b5054cd19569aa8de (diff) | |
| download | go-efe7a1f5d3ccdef5c25cb4d8386492a7b1785600.tar.xz | |
runtime: write out a batch with alignment info for traceallocfree
Currently the traceallocfree experiment is missing info in the trace for
interpeting the produced events. Most notably, the base heap address is
missing. While not technically necessary, it is useful for getting an
accurate picture of the program's memory layout, and will be useful for
future trace experiments. Since we want to emit a batch for this, we
should also emit a batch for all the alignment info that's used to
compress the addresses (IDs) produced for the alloc/free events.
This CL distinguishes the different formats of the experimental batches
(note that there's already batches containing type information in this
experiment) by putting a byte at the beginning of each experimental
batch indicating its format.
Change-Id: Ifc4e77a23458713b7d95e0dfa056a29e1629ccd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/586997
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/traceallocfree.go')
| -rw-r--r-- | src/runtime/traceallocfree.go | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/runtime/traceallocfree.go b/src/runtime/traceallocfree.go index 3067e16670..67c6f40926 100644 --- a/src/runtime/traceallocfree.go +++ b/src/runtime/traceallocfree.go @@ -11,13 +11,38 @@ import ( "runtime/internal/sys" ) +// Batch type values for the alloc/free experiment. +const ( + traceAllocFreeTypesBatch = iota // Contains types. [{id, address, size, ptrspan, name length, name string} ...] + traceAllocFreeInfoBatch // Contains info for interpreting events. [min heap addr, page size, min heap align, min stack align] +) + // traceSnapshotMemory takes a snapshot of all runtime memory that there are events for // (heap spans, heap objects, goroutine stacks, etc.) and writes out events for them. // // The world must be stopped and tracing must be enabled when this function is called. -func traceSnapshotMemory() { +func traceSnapshotMemory(gen uintptr) { assertWorldStopped() + // Write a batch containing information that'll be necessary to + // interpret the events. + var flushed bool + w := unsafeTraceExpWriter(gen, nil, traceExperimentAllocFree) + w, flushed = w.ensure(1 + 4*traceBytesPerNumber) + if flushed { + // Annotate the batch as containing additional info. + w.byte(byte(traceAllocFreeInfoBatch)) + } + + // Emit info. + w.varint(uint64(trace.minPageHeapAddr)) + w.varint(uint64(pageSize)) + w.varint(uint64(minHeapAlign)) + w.varint(uint64(fixedStack)) + + // Finish writing the batch. + w.flush().end() + // Start tracing. trace := traceAcquire() if !trace.ok() { @@ -103,7 +128,7 @@ func (tl traceLocker) HeapObjectFree(addr uintptr) { // traceHeapObjectID creates a trace ID for a heap object at address addr. func traceHeapObjectID(addr uintptr) traceArg { - return traceArg(uint64(addr)-trace.minPageHeapAddr) / 8 + return traceArg(uint64(addr)-trace.minPageHeapAddr) / minHeapAlign } // GoroutineStackExists records that a goroutine stack already exists at address base with the provided size. |
