/
main.go
74 lines (61 loc) · 1.59 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
72
73
74
package main
import (
"flag"
"fmt"
"os"
"runtime"
"runtime/pprof"
_ "github.com/project-flogo/core/data/expression/script"
"github.com/project-flogo/core/engine"
)
var (
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cfgEngine string
cfgCompressed bool
)
func main() {
cpuProfiling := false
flag.Parse()
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
os.Exit(1)
}
if err = pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
os.Exit(1)
}
cpuProfiling = true
}
cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
os.Exit(1)
}
e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
os.Exit(1)
}
code := engine.RunEngine(e)
if *memProfile != "" {
f, err := os.Create(*memProfile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err)
os.Exit(1)
}
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
os.Exit(1)
}
_ = f.Close()
}
if cpuProfiling {
pprof.StopCPUProfile()
}
os.Exit(code)
}