aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/trace.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/trace.go')
-rw-r--r--src/runtime/trace.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime/trace.go b/src/runtime/trace.go
index 33062daa46..169b650eb4 100644
--- a/src/runtime/trace.go
+++ b/src/runtime/trace.go
@@ -187,6 +187,9 @@ func StartTrace() error {
// paired with an end).
stopTheWorldGC("start tracing")
+ // Prevent sysmon from running any code that could generate events.
+ lock(&sched.sysmonlock)
+
// We are in stop-the-world, but syscalls can finish and write to trace concurrently.
// Exitsyscall could check trace.enabled long before and then suddenly wake up
// and decide to write to trace at a random point in time.
@@ -196,6 +199,7 @@ func StartTrace() error {
if trace.enabled || trace.shutdown {
unlock(&trace.bufLock)
+ unlock(&sched.sysmonlock)
startTheWorldGC()
return errorString("tracing is already enabled")
}
@@ -267,6 +271,8 @@ func StartTrace() error {
unlock(&trace.bufLock)
+ unlock(&sched.sysmonlock)
+
startTheWorldGC()
return nil
}
@@ -279,10 +285,14 @@ func StopTrace() {
stopTheWorldGC("stop tracing")
// See the comment in StartTrace.
+ lock(&sched.sysmonlock)
+
+ // See the comment in StartTrace.
lock(&trace.bufLock)
if !trace.enabled {
unlock(&trace.bufLock)
+ unlock(&sched.sysmonlock)
startTheWorldGC()
return
}
@@ -320,6 +330,8 @@ func StopTrace() {
trace.shutdown = true
unlock(&trace.bufLock)
+ unlock(&sched.sysmonlock)
+
startTheWorldGC()
// The world is started but we've set trace.shutdown, so new tracing can't start.