-
Notifications
You must be signed in to change notification settings - Fork 126
/
main.go
71 lines (60 loc) · 1.29 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
69
70
71
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
output := flag.String("o", "", "Output trace in JSON format to this file")
flag.Usage = Usage
flag.Parse()
args := flag.Args()
var src EventSource
if len(args) == 1 {
if strings.HasSuffix(args[0], ".json") {
commands, err := ioutil.ReadFile(args[0])
if err != nil {
panic(err)
}
_ = commands
//ProcessCommands(*output, commands)
return
}
src = NewNativeRun(args[0])
} else if len(args) == 2 {
src = NewTraceSource(args[0], args[1])
} else {
Usage()
os.Exit(1)
}
events, err := src.Events()
if err != nil {
panic(err)
}
commands, err := ConvertEvents(events)
if err != nil {
panic(err)
}
ProcessCommands(*output, commands)
}
// ProcessCommands processes command list.
func ProcessCommands(out string, cmds Commands) {
params := GuessParams(cmds)
data := cmds.toJSON()
if out != "" {
err := ioutil.WriteFile(out, data, 0644)
if err != nil {
panic(err)
}
fmt.Printf("Written commands to %s\n", out)
return
}
StartServer(":2000", data, params)
}
// Usage prints usage information, overriding default one.
func Usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [-o file] [trace.out trace.bin] or [trace.json] or [main.go]\n", os.Args[0])
flag.PrintDefaults()
}