-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime/trace: add missing events for the locked g in extra M.
Extra Ms may lead to the "no consistent ordering of events possible" error when parsing trace file with cgo enabled, since: 1. The gs in the extra Ms may be in `_Gdead` status while starting trace by invoking `runtime.StartTrace`, 2. and these gs will trigger `traceEvGoSysExit` events in `runtime.exitsyscall` when invoking go functions from c, 3. then, the events of those gs are under non-consistent ordering, due to missing the previous events. Add two events, `traceEvGoCreate` and `traceEvGoInSyscall`, in `runtime.StartTrace`, will make the trace parser happy. Fixes #29707 Change-Id: I2fd9d1713cda22f0ddb36efe1ab351f88da10881 GitHub-Last-Rev: 7bbfddb GitHub-Pull-Request: #54974 Reviewed-on: https://go-review.googlesource.com/c/go/+/429858 Run-TryBot: Michael Pratt <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: xie cui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
- Loading branch information
1 parent
48a58c5
commit fb6c210
Showing
6 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2011 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !plan9 && !windows | ||
// +build !plan9,!windows | ||
|
||
// This is for issue #29707 | ||
|
||
package main | ||
|
||
/* | ||
#include <pthread.h> | ||
extern void* callbackTraceParser(void*); | ||
typedef void* (*cbTraceParser)(void*); | ||
static void testCallbackTraceParser(cbTraceParser cb) { | ||
pthread_t thread_id; | ||
pthread_create(&thread_id, NULL, cb, NULL); | ||
pthread_join(thread_id, NULL); | ||
} | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
traceparser "internal/trace" | ||
"runtime/trace" | ||
"time" | ||
"unsafe" | ||
) | ||
|
||
func init() { | ||
register("CgoTraceParser", CgoTraceParser) | ||
} | ||
|
||
//export callbackTraceParser | ||
func callbackTraceParser(unsafe.Pointer) unsafe.Pointer { | ||
time.Sleep(time.Millisecond) | ||
return nil | ||
} | ||
|
||
func CgoTraceParser() { | ||
buf := new(bytes.Buffer) | ||
|
||
trace.Start(buf) | ||
C.testCallbackTraceParser(C.cbTraceParser(C.callbackTraceParser)) | ||
trace.Stop() | ||
|
||
_, err := traceparser.Parse(buf, "") | ||
if err != nil { | ||
fmt.Println("Parse error: ", err) | ||
} else { | ||
fmt.Println("OK") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters