File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,10 @@ import (
5
5
"flag"
6
6
"log"
7
7
"os"
8
+ "os/signal"
9
+ "runtime/pprof"
8
10
"strings"
11
+ "syscall"
9
12
10
13
"github.com/pelletier/go-toml/v2"
11
14
)
@@ -35,8 +38,29 @@ func sshmuxServer(configFile string) (*Server, error) {
35
38
36
39
func main () {
37
40
var configFile string
41
+ var pprofFile string
38
42
flag .StringVar (& configFile , "c" , "/etc/sshmux/config.toml" , "config file" )
43
+ flag .StringVar (& pprofFile , "pprof" , "" , "write pprof data to file" )
39
44
flag .Parse ()
45
+ if pprofFile != "" {
46
+ f , err := os .Create (pprofFile )
47
+ if err != nil {
48
+ log .Fatal ("failed to create pprof file: %w" , err )
49
+ }
50
+ defer f .Close ()
51
+ if err := pprof .StartCPUProfile (f ); err != nil {
52
+ log .Fatal ("failed to start pprof: %w" , err )
53
+ }
54
+ defer pprof .StopCPUProfile ()
55
+ // Handle SIGINT/SIGTERM
56
+ signalChan := make (chan os.Signal , 1 )
57
+ signal .Notify (signalChan , syscall .SIGINT , syscall .SIGTERM )
58
+ go func () {
59
+ <- signalChan
60
+ pprof .StopCPUProfile ()
61
+ os .Exit (0 )
62
+ }()
63
+ }
40
64
sshmux , err := sshmuxServer (configFile )
41
65
if err != nil {
42
66
log .Fatal (err )
You can’t perform that action at this time.
0 commit comments