We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 86766ab commit bc1fc56Copy full SHA for bc1fc56
pprof/03-trace.go
@@ -0,0 +1,44 @@
1
+package main
2
+
3
+import (
4
+ "flag"
5
+ "log"
6
+ "os"
7
+ "runtime"
8
+ "runtime/trace"
9
+ "sync"
10
+)
11
12
+func counter(wg *sync.WaitGroup) {
13
+ wg.Done()
14
+ slice := []int{0}
15
+ c := 1
16
+ for i := 0; i < 100000; i++ {
17
+ mutex.Lock()
18
+ c = i + 1 + 2 + 3 + 4 + 5
19
+ slice = append(slice, c)
20
+ mutex.Unlock()
21
+ }
22
+}
23
24
+func main() {
25
+ runtime.GOMAXPROCS(5)
26
+ var traceProfile = flag.String("traceprofile", "", "write trace profile to file")
27
+ flag.Parse()
28
+ if *traceProfile != "" {
29
+ f, err := os.Create(*traceProfile)
30
+ if err != nil {
31
+ log.Fatal(err)
32
33
+ trace.Start(f)
34
+ defer f.Close()
35
+ defer trace.Stop()
36
37
38
+ var wg sync.WaitGroup
39
+ wg.Add(3)
40
+ for i := 0; i < 3; i++ {
41
+ go counter(&wg)
42
43
+ wg.Wait()
44
0 commit comments