github.com/guyezi/gofrontend@v0.0.0-20200228202240-7a62a49e62c0/libgo/go/runtime/testdata/testprog/vdso.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Invoke signal hander in the VDSO context (see issue 32912). 6 7 package main 8 9 import ( 10 "fmt" 11 "io/ioutil" 12 "os" 13 "runtime/pprof" 14 "time" 15 ) 16 17 func init() { 18 register("SignalInVDSO", signalInVDSO) 19 } 20 21 func signalInVDSO() { 22 f, err := ioutil.TempFile("", "timeprofnow") 23 if err != nil { 24 fmt.Fprintln(os.Stderr, err) 25 os.Exit(2) 26 } 27 28 if err := pprof.StartCPUProfile(f); err != nil { 29 fmt.Fprintln(os.Stderr, err) 30 os.Exit(2) 31 } 32 33 t0 := time.Now() 34 t1 := t0 35 // We should get a profiling signal 100 times a second, 36 // so running for 1 second should be sufficient. 37 for t1.Sub(t0) < time.Second { 38 t1 = time.Now() 39 } 40 41 pprof.StopCPUProfile() 42 43 name := f.Name() 44 if err := f.Close(); err != nil { 45 fmt.Fprintln(os.Stderr, err) 46 os.Exit(2) 47 } 48 49 if err := os.Remove(name); err != nil { 50 fmt.Fprintln(os.Stderr, err) 51 os.Exit(2) 52 } 53 54 fmt.Println("success") 55 }