mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: tricky replacements of _g_ in trace.go
Like previous CLs, cases where the getg() G is used only to access the M are replaced with direct uses of mp. Change-Id: I4740c80d6b4997d051a52afcfa8c087e0317dab3 Reviewed-on: https://go-review.googlesource.com/c/go/+/418579 Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
222799fde6
commit
74cee276fe
1 changed files with 9 additions and 12 deletions
|
|
@ -232,14 +232,12 @@ func StartTrace() error {
|
||||||
// - or GoSysExit appears for a goroutine for which we don't emit EvGoInSyscall below.
|
// - or GoSysExit appears for a goroutine for which we don't emit EvGoInSyscall below.
|
||||||
// To instruct traceEvent that it must not ignore events below, we set startingtrace.
|
// To instruct traceEvent that it must not ignore events below, we set startingtrace.
|
||||||
// trace.enabled is set afterwards once we have emitted all preliminary events.
|
// trace.enabled is set afterwards once we have emitted all preliminary events.
|
||||||
_g_ := getg()
|
mp := getg().m
|
||||||
_g_.m.startingtrace = true
|
mp.startingtrace = true
|
||||||
|
|
||||||
// Obtain current stack ID to use in all traceEvGoCreate events below.
|
// Obtain current stack ID to use in all traceEvGoCreate events below.
|
||||||
mp := acquirem()
|
|
||||||
stkBuf := make([]uintptr, traceStackSize)
|
stkBuf := make([]uintptr, traceStackSize)
|
||||||
stackID := traceStackID(mp, stkBuf, 2)
|
stackID := traceStackID(mp, stkBuf, 2)
|
||||||
releasem(mp)
|
|
||||||
|
|
||||||
profBuf := newProfBuf(2, profBufWordCount, profBufTagCount) // after the timestamp, header is [pp.id, gp.goid]
|
profBuf := newProfBuf(2, profBufWordCount, profBufTagCount) // after the timestamp, header is [pp.id, gp.goid]
|
||||||
trace.cpuLogRead = profBuf
|
trace.cpuLogRead = profBuf
|
||||||
|
|
@ -293,7 +291,7 @@ func StartTrace() error {
|
||||||
trace.strings = make(map[string]uint64)
|
trace.strings = make(map[string]uint64)
|
||||||
|
|
||||||
trace.seqGC = 0
|
trace.seqGC = 0
|
||||||
_g_.m.startingtrace = false
|
mp.startingtrace = false
|
||||||
trace.enabled = true
|
trace.enabled = true
|
||||||
|
|
||||||
// Register runtime goroutine labels.
|
// Register runtime goroutine labels.
|
||||||
|
|
@ -782,19 +780,18 @@ func traceReadCPU() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func traceStackID(mp *m, buf []uintptr, skip int) uint64 {
|
func traceStackID(mp *m, buf []uintptr, skip int) uint64 {
|
||||||
_g_ := getg()
|
gp := getg()
|
||||||
gp := mp.curg
|
curgp := mp.curg
|
||||||
var nstk int
|
var nstk int
|
||||||
if gp == _g_ {
|
if curgp == gp {
|
||||||
nstk = callers(skip+1, buf)
|
nstk = callers(skip+1, buf)
|
||||||
} else if gp != nil {
|
} else if curgp != nil {
|
||||||
gp = mp.curg
|
nstk = gcallers(curgp, skip, buf)
|
||||||
nstk = gcallers(gp, skip, buf)
|
|
||||||
}
|
}
|
||||||
if nstk > 0 {
|
if nstk > 0 {
|
||||||
nstk-- // skip runtime.goexit
|
nstk-- // skip runtime.goexit
|
||||||
}
|
}
|
||||||
if nstk > 0 && gp.goid == 1 {
|
if nstk > 0 && curgp.goid == 1 {
|
||||||
nstk-- // skip runtime.main
|
nstk-- // skip runtime.main
|
||||||
}
|
}
|
||||||
id := trace.stackTab.put(buf[:nstk])
|
id := trace.stackTab.put(buf[:nstk])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue