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