@@ -174,6 +174,20 @@ type mTraceState struct {
174
174
startingTrace bool // this M is in TraceStart, potentially before traceEnabled is true
175
175
}
176
176
177
+ // pTraceState is per-P state for the tracer.
178
+ type pTraceState struct {
179
+ buf traceBufPtr
180
+
181
+ // inSweep indicates the sweep events should be traced.
182
+ // This is used to defer the sweep start event until a span
183
+ // has actually been swept.
184
+ inSweep bool
185
+
186
+ // swept and reclaimed track the number of bytes swept and reclaimed
187
+ // by sweeping in the current sweep loop (while inSweep was true).
188
+ swept , reclaimed uintptr
189
+ }
190
+
177
191
// traceLockInit initializes global trace locks.
178
192
func traceLockInit () {
179
193
lockInit (& trace .bufLock , lockRankTraceBuf )
@@ -379,10 +393,10 @@ func StopTrace() {
379
393
// Loop over all allocated Ps because dead Ps may still have
380
394
// trace buffers.
381
395
for _ , p := range allp [:cap (allp )] {
382
- buf := p .tracebuf
396
+ buf := p .trace . buf
383
397
if buf != 0 {
384
398
traceFullQueue (buf )
385
- p .tracebuf = 0
399
+ p .trace . buf = 0
386
400
}
387
401
}
388
402
if trace .buf != 0 {
@@ -429,7 +443,7 @@ func StopTrace() {
429
443
// The lock protects us from races with StartTrace/StopTrace because they do stop-the-world.
430
444
lock (& trace .lock )
431
445
for _ , p := range allp [:cap (allp )] {
432
- if p .tracebuf != 0 {
446
+ if p .trace . buf != 0 {
433
447
throw ("trace: non-empty trace buffer in proc" )
434
448
}
435
449
}
@@ -650,8 +664,8 @@ func traceReaderAvailable() *g {
650
664
//
651
665
//go:systemstack
652
666
func traceProcFree (pp * p ) {
653
- buf := pp .tracebuf
654
- pp .tracebuf = 0
667
+ buf := pp .trace . buf
668
+ pp .trace . buf = 0
655
669
if buf == 0 {
656
670
return
657
671
}
@@ -980,7 +994,7 @@ func traceAcquireBuffer() (mp *m, pid int32, bufp *traceBufPtr) {
980
994
981
995
mp = acquirem ()
982
996
if p := mp .p .ptr (); p != nil {
983
- return mp , p .id , & p .tracebuf
997
+ return mp , p .id , & p .trace . buf
984
998
}
985
999
lock (& trace .bufLock )
986
1000
return mp , traceGlobProc , & trace .buf
@@ -1480,10 +1494,10 @@ func traceGCSweepStart() {
1480
1494
// Delay the actual GCSweepStart event until the first span
1481
1495
// sweep. If we don't sweep anything, don't emit any events.
1482
1496
pp := getg ().m .p .ptr ()
1483
- if pp .traceSweep {
1497
+ if pp .trace . inSweep {
1484
1498
throw ("double traceGCSweepStart" )
1485
1499
}
1486
- pp .traceSweep , pp .traceSwept , pp .traceReclaimed = true , 0 , 0
1500
+ pp .trace . inSweep , pp .trace . swept , pp .trace . reclaimed = true , 0 , 0
1487
1501
}
1488
1502
1489
1503
// traceGCSweepSpan traces the sweep of a single page.
@@ -1492,23 +1506,23 @@ func traceGCSweepStart() {
1492
1506
// pair; however, it will not emit any trace events in this case.
1493
1507
func traceGCSweepSpan (bytesSwept uintptr ) {
1494
1508
pp := getg ().m .p .ptr ()
1495
- if pp .traceSweep {
1496
- if pp .traceSwept == 0 {
1509
+ if pp .trace . inSweep {
1510
+ if pp .trace . swept == 0 {
1497
1511
traceEvent (traceEvGCSweepStart , 1 )
1498
1512
}
1499
- pp .traceSwept += bytesSwept
1513
+ pp .trace . swept += bytesSwept
1500
1514
}
1501
1515
}
1502
1516
1503
1517
func traceGCSweepDone () {
1504
1518
pp := getg ().m .p .ptr ()
1505
- if ! pp .traceSweep {
1519
+ if ! pp .trace . inSweep {
1506
1520
throw ("missing traceGCSweepStart" )
1507
1521
}
1508
- if pp .traceSwept != 0 {
1509
- traceEvent (traceEvGCSweepDone , - 1 , uint64 (pp .traceSwept ), uint64 (pp .traceReclaimed ))
1522
+ if pp .trace . swept != 0 {
1523
+ traceEvent (traceEvGCSweepDone , - 1 , uint64 (pp .trace . swept ), uint64 (pp .trace . reclaimed ))
1510
1524
}
1511
- pp .traceSweep = false
1525
+ pp .trace . inSweep = false
1512
1526
}
1513
1527
1514
1528
func traceGCMarkAssistStart () {
0 commit comments