@@ -9,42 +9,43 @@ import (
9
9
10
10
_ "github.com/project-flogo/core/data/expression/script"
11
11
"github.com/project-flogo/core/engine"
12
- "github.com/project-flogo/core/support/log"
13
-
14
- _ "github.com/project-flogo/contrib/trigger/rest"
15
- _ "github.com/project-flogo/rules/ruleaction"
16
-
17
12
)
18
13
19
14
var (
20
- cpuProfile = flag .String ("cpuprofile" , "" , "Writes CPU profile to the specified file" )
21
- memProfile = flag .String ("memprofile" , "" , "Writes memory profile to the specified file" )
22
- cfgJson string
15
+ cpuProfile = flag .String ("cpuprofile" , "" , "Writes CPU profile to the specified file" )
16
+ memProfile = flag .String ("memprofile" , "" , "Writes memory profile to the specified file" )
17
+ cfgJson string
18
+ cfgEngine string
23
19
cfgCompressed bool
24
20
)
25
21
26
22
func main () {
27
23
24
+ cpuProfiling := false
25
+
28
26
flag .Parse ()
29
27
if * cpuProfile != "" {
30
28
f , err := os .Create (* cpuProfile )
31
29
if err != nil {
32
- fmt .Println ( fmt . Sprintf ( "Failed to create CPU profiling file due to error - %s " , err . Error ()) )
30
+ fmt .Fprintf ( os . Stderr , "Failed to create CPU profiling file: %v \n " , err )
33
31
os .Exit (1 )
34
32
}
35
- pprof .StartCPUProfile (f )
36
- defer pprof .StopCPUProfile ()
33
+ if err = pprof .StartCPUProfile (f ); err != nil {
34
+ fmt .Fprintf (os .Stderr , "Failed to start CPU profiling: %v\n " , err )
35
+ os .Exit (1 )
36
+ }
37
+ cpuProfiling = true
37
38
}
38
39
39
40
cfg , err := engine .LoadAppConfig (cfgJson , cfgCompressed )
40
41
if err != nil {
41
- log . RootLogger (). Errorf ( "Failed to create engine: %s " , err . Error () )
42
+ fmt . Fprintf ( os . Stderr , "Failed to create engine: %v \n " , err )
42
43
os .Exit (1 )
43
44
}
44
45
45
- e , err := engine .New (cfg )
46
+ e , err := engine .New (cfg , engine . ConfigOption ( cfgEngine , cfgCompressed ) )
46
47
if err != nil {
47
- log . RootLogger (). Errorf ( "Failed to create engine: %s " , err . Error () )
48
+ fmt . Fprintf ( os . Stderr , "Failed to create engine: %v \n " , err )
48
49
os .Exit (1 )
49
50
}
50
51
@@ -53,17 +54,21 @@ func main() {
53
54
if * memProfile != "" {
54
55
f , err := os .Create (* memProfile )
55
56
if err != nil {
56
- fmt .Println ( fmt . Sprintf ( "Failed to create memory profiling file due to error - %s " , err . Error ()) )
57
+ fmt .Fprintf ( os . Stderr , "Failed to create memory profiling file: %v \n " , err )
57
58
os .Exit (1 )
58
59
}
59
60
60
61
runtime .GC () // get up-to-date statistics
61
62
if err := pprof .WriteHeapProfile (f ); err != nil {
62
- fmt .Println ( fmt . Sprintf ( "Failed to write memory profiling data to file due to error - %s " , err . Error ()) )
63
+ fmt .Fprintf ( os . Stderr , "Failed to write memory profiling data: %v " , err )
63
64
os .Exit (1 )
64
65
}
65
- f .Close ()
66
+ _ = f .Close ()
67
+ }
68
+
69
+ if cpuProfiling {
70
+ pprof .StopCPUProfile ()
66
71
}
67
72
68
73
os .Exit (code )
69
- }
74
+ }
0 commit comments