-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
68 lines (55 loc) · 1.33 KB
/
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
64
65
66
67
68
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"runtime/debug"
"github.com/becheran/roumon/internal/client"
"github.com/becheran/roumon/internal/model"
"github.com/becheran/roumon/internal/ui"
)
func main() {
var host string
var dbgFile string
var port int
var versionFlag bool
flag.StringVar(&host, "host", "localhost", "The pprof server IP or hostname")
flag.IntVar(&port, "port", 6060, "The pprof server port")
flag.StringVar(&dbgFile, "debug", "", "Path to debug file")
flag.BoolVar(&versionFlag, "v", false, "Print version of roumon and exit")
flag.Parse()
version := "dev"
if info, ok := debug.ReadBuildInfo(); ok {
version = info.Main.Version
}
if versionFlag {
fmt.Println(version)
return
}
if len(dbgFile) > 0 {
f, err := os.OpenFile(dbgFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(io.Discard)
}
log.Printf("Start roumon (%s)", version)
c := client.NewClient(host, port)
ui := ui.NewUI()
terminate := make(chan error)
routinesUpdate := make(chan []model.Goroutine)
go c.Run(terminate, routinesUpdate)
go ui.Run(terminate, routinesUpdate)
err := <-terminate
ui.Stop()
if err != nil {
fmt.Println(err.Error())
log.Print(err.Error())
}
log.Print("Stopped")
}