1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-29 21:56:56 +02:00

Ensure ^C captures profile information.

This commit is contained in:
Alec Thomas 2017-06-07 20:39:58 +10:00
parent a0db747409
commit a3862242d5

View File

@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"os/signal"
"runtime/pprof"
"strings"
@ -38,6 +39,13 @@ func main() {
f, err := os.Create(*profileFlag)
kingpin.FatalIfError(err, "")
pprof.StartCPUProfile(f)
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
go func() {
<-signals
pprof.StopCPUProfile()
os.Exit(128 + 3)
}()
defer pprof.StopCPUProfile()
}
w := bufio.NewWriterSize(os.Stdout, 16384)