...
1
2
3
4
5 package main
6
7 import (
8 "fmt"
9 "os"
10 "runtime/pprof"
11 "time"
12 )
13
14 func init() {
15 register("TimeProf", TimeProf)
16 }
17
18 func TimeProf() {
19 f, err := os.CreateTemp("", "timeprof")
20 if err != nil {
21 fmt.Fprintln(os.Stderr, err)
22 os.Exit(2)
23 }
24
25 if err := pprof.StartCPUProfile(f); err != nil {
26 fmt.Fprintln(os.Stderr, err)
27 os.Exit(2)
28 }
29
30 t0 := time.Now()
31
32
33 for time.Since(t0) < time.Second/10 {
34 }
35
36 pprof.StopCPUProfile()
37
38 name := f.Name()
39 if err := f.Close(); err != nil {
40 fmt.Fprintln(os.Stderr, err)
41 os.Exit(2)
42 }
43
44 fmt.Println(name)
45 }
46
View as plain text