github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/runtime/pagetrace_on.go (about) 1 // Copyright 2022 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 //go:build goexperiment.pagetrace 6 7 // Page tracer. 8 // 9 // This file contains an implementation of page trace instrumentation for tracking 10 // the way the Go runtime manages pages of memory. The trace may be enabled at program 11 // startup with the GODEBUG option pagetrace. 12 // 13 // Each page trace event is either 8 or 16 bytes wide. The first 14 // 8 bytes follow this format for non-sync events: 15 // 16 // [16 timestamp delta][35 base address][10 npages][1 isLarge][2 pageTraceEventType] 17 // 18 // If the "large" bit is set then the event is 16 bytes wide with the second 8 byte word 19 // containing the full npages value (the npages bitfield is 0). 20 // 21 // The base address's bottom pageShift bits are always zero hence why we can pack other 22 // data in there. We ignore the top 16 bits, assuming a 48 bit address space for the 23 // heap. 24 // 25 // The timestamp delta is computed from the difference between the current nanotime 26 // timestamp and the last sync event's timestamp. The bottom pageTraceTimeLostBits of 27 // this delta is removed and only the next pageTraceTimeDeltaBits are kept. 28 // 29 // A sync event is emitted at the beginning of each trace buffer and whenever the 30 // timestamp delta would not fit in an event. 31 // 32 // Sync events have the following structure: 33 // 34 // [61 timestamp or P ID][1 isPID][2 pageTraceSyncEvent] 35 // 36 // In essence, the "large" bit repurposed to indicate whether it's a timestamp or a P ID 37 // (these are typically uint32). Note that we only have 61 bits for the 64-bit timestamp, 38 // but like for the delta we drop the bottom pageTraceTimeLostBits here as well. 39 40 package runtime