File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ func dumpHeapProfile() {
61
61
// If CPU profiling is enabled (ZGRAB2_CPUPROFILE is not empty), start tracking
62
62
// CPU profiling in the configured file. Caller is responsible for invoking
63
63
// stopCPUProfile() when finished.
64
- func startCPUProfile () {
64
+ func startCPUProfile () * os. File {
65
65
if file := getCPUProfileFile (); file != "" {
66
66
now := time .Now ()
67
67
fullFile := getFormattedFile (file , now )
@@ -72,24 +72,30 @@ func startCPUProfile() {
72
72
if err := pprof .StartCPUProfile (f ); err != nil {
73
73
log .Fatal ("could not start CPU profile: " , err )
74
74
}
75
+ return f
75
76
}
77
+
78
+ return nil
76
79
}
77
80
78
81
// If CPU profiling is enabled (ZGRAB2_CPUPROFILE is not empty), stop profiling
79
82
// CPU usage.
80
- func stopCPUProfile () {
83
+ func stopCPUProfile (f * os. File ) {
81
84
if getCPUProfileFile () != "" {
82
85
pprof .StopCPUProfile ()
83
86
}
87
+ if f != nil {
88
+ f .Close ()
89
+ }
84
90
}
85
91
86
92
// ZGrab2Main should be called by func main() in a binary. The caller is
87
93
// responsible for importing any modules in use. This allows clients to easily
88
94
// include custom sets of scan modules by creating new main packages with custom
89
95
// sets of ZGrab modules imported with side-effects.
90
96
func ZGrab2Main () {
91
- startCPUProfile ()
92
- defer stopCPUProfile ()
97
+ f := startCPUProfile ()
98
+ defer stopCPUProfile (f )
93
99
defer dumpHeapProfile ()
94
100
_ , moduleType , flag , err := zgrab2 .ParseCommandLine (os .Args [1 :])
95
101
You can’t perform that action at this time.
0 commit comments