-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
63 lines (46 loc) · 913 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"os"
"pg_flame/pkg/html"
"pg_flame/pkg/plan"
)
var (
// goreleaser automatically overrides this based on the tag
version = "dev"
hFlag = flag.Bool("h", false, "print help info")
helpFlag = flag.Bool("help", false, "print help info")
)
func main() {
flag.Parse()
if *hFlag || *helpFlag {
printHelp()
}
p, err := plan.New(os.Stdin)
if err != nil {
handleErr(err)
}
err = html.Generate(os.Stdout, p)
if err != nil {
handleErr(err)
}
}
func handleErr(err error) {
fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(1)
}
func printHelp() {
help := `pg_flame %s
Turn Postgres query plans into flamegraphs.
Usage:
pg_flame [options]
Without Options:
Reads a JSON query plan from standard input and writes the
flamegraph html to standard output.
Options:
-h, --help print help information
`
fmt.Printf(help, version)
os.Exit(0)
}