@@ -18,10 +18,15 @@ package main
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"os"
23
+ "runtime"
24
+ "runtime/pprof"
22
25
23
26
"github.com/fatih/color"
24
27
28
+ "github.com/deckhouse/dmt/internal/flags"
29
+ "github.com/deckhouse/dmt/internal/fsutils"
25
30
"github.com/deckhouse/dmt/internal/logger"
26
31
"github.com/deckhouse/dmt/internal/manager"
27
32
"github.com/deckhouse/dmt/internal/metrics"
@@ -32,7 +37,32 @@ func main() {
32
37
execute ()
33
38
}
34
39
35
- func runLint (dir string ) {
40
+ func runLint (dir string ) error {
41
+ if flags .PprofFile != "" {
42
+ logger .InfoF ("Profiling enabled. Profile file: %s" , flags .PprofFile )
43
+ defer func () {
44
+ pproFile , err := fsutils .ExpandDir (flags .PprofFile )
45
+ if err != nil {
46
+ logger .ErrorF ("could not get current working directory: %s" , err )
47
+ return
48
+ }
49
+ logger .InfoF ("Writing memory profile to %s" , pproFile )
50
+ f , err := os .Create (pproFile )
51
+ if err != nil {
52
+ logger .ErrorF ("could not create memory profile: %s" , err )
53
+ return
54
+ }
55
+ defer f .Close ()
56
+ runtime .GC ()
57
+ // Lookup("allocs") creates a profile similar to go test -memprofile.
58
+ // Alternatively, use Lookup("heap") for a profile
59
+ // that has inuse_space as the default index.
60
+ if err := pprof .Lookup ("allocs" ).WriteTo (f , 0 ); err != nil {
61
+ logger .ErrorF ("could not write memory profile: %s" , err )
62
+ return
63
+ }
64
+ }()
65
+ }
36
66
color .NoColor = false
37
67
logger .InfoF ("DMT version: %s" , version )
38
68
logger .InfoF ("Dir: %v" , dir )
@@ -56,6 +86,8 @@ func runLint(dir string) {
56
86
metricsClient .Send (context .Background ())
57
87
58
88
if mng .HasCriticalErrors () {
59
- os . Exit ( 1 )
89
+ return errors . New ( "critical errors found" )
60
90
}
91
+
92
+ return nil
61
93
}
0 commit comments