/
pprof.go
66 lines (58 loc) · 1.24 KB
/
pprof.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
package main
import (
"fmt"
"github.com/projectdiscovery/gologger"
"github.com/wjlin0/pathScan/v2/pkg/runner"
"log"
"os"
"os/signal"
"runtime"
"runtime/pprof"
)
var (
cpuprofile = "cpu.pprof"
memprofile = "mem.pprof"
)
func main() {
f1, err := os.Create(cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f1.Close()
if err := pprof.StartCPUProfile(f1); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
run, err := runner.NewRunner(runner.ParserOptions())
if err != nil {
gologger.Print().Msg(fmt.Sprintf("Unable to create Runner:%s", err.Error()))
os.Exit(-1)
}
if run == nil {
os.Exit(0)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
gologger.Info().Msg("ctrl+c press: exiting")
run.Close()
os.Exit(-1)
}
}()
err = run.RunEnumeration()
if err != nil {
gologger.Fatal().Msgf("Unable to run: %s", err.Error())
os.Exit(0)
}
f, err := os.Create(memprofile)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer f.Close()
runtime.GC()
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("cound not write memory profile: ", err)
}
run.Close()
}