...
1
2
3
4
5
6
7
8
9
10 package main
11
12
24 import "C"
25
26 import (
27 "bytes"
28 "fmt"
29 traceparser "internal/trace"
30 "runtime/trace"
31 "time"
32 "unsafe"
33 )
34
35 func init() {
36 register("CgoTraceParser", CgoTraceParser)
37 }
38
39
40 func callbackTraceParser(unsafe.Pointer) unsafe.Pointer {
41 time.Sleep(time.Millisecond)
42 return nil
43 }
44
45 func CgoTraceParser() {
46 buf := new(bytes.Buffer)
47
48 trace.Start(buf)
49 C.testCallbackTraceParser(C.cbTraceParser(C.callbackTraceParser))
50 trace.Stop()
51
52 _, err := traceparser.Parse(buf, "")
53 if err == traceparser.ErrTimeOrder {
54 fmt.Println("ErrTimeOrder")
55 } else if err != nil {
56 fmt.Println("Parse error: ", err)
57 } else {
58 fmt.Println("OK")
59 }
60 }
61
View as plain text