diff --git a/pkg/edgeview/src/basics.go b/pkg/edgeview/src/basics.go index 71942ab92f..c19c5e1bcc 100644 --- a/pkg/edgeview/src/basics.go +++ b/pkg/edgeview/src/basics.go @@ -75,7 +75,6 @@ func initOpts() { "tcpdump", "trace", "url", - "pprof", "wireless"} pubsubopts = []string{ @@ -133,6 +132,7 @@ func initOpts() { "techsupport", "top", "volume", + "pprof", } logdirectory = []string{ @@ -676,6 +676,8 @@ func printHelp(opt string) { helpExample("cat/ -line ", "display only of lines, like 'head' if is positive, like 'tail' if the is negative", false) case "datastore": helpOn("datastore", "display the device current datastore: EQDN, type, cipher information") + case "pprof": + helpOn("pprof", "pprof/on to turn on pprof; pprof/off to turn off again") case "dmesg": helpOn("dmesg", "display the device current dmesg information") case "download": diff --git a/pkg/edgeview/src/edge-view.go b/pkg/edgeview/src/edge-view.go index c2774c6d47..eba6030f31 100644 --- a/pkg/edgeview/src/edge-view.go +++ b/pkg/edgeview/src/edge-view.go @@ -202,13 +202,6 @@ func main() { pnetopt = pqueryopt } else if strings.HasPrefix(pqueryopt, "app") { psysopt = pqueryopt - } else if pqueryopt == "pprof" { - var ok bool - ok, tcpclientCnt, remotePorts = processTCPcmd("tcp/localhost:6543", remotePorts) - if !ok { - return - } - pnetopt = pqueryopt } else if strings.HasPrefix(pqueryopt, "tcp/") { var ok bool ok, tcpclientCnt, remotePorts = processTCPcmd(pqueryopt, remotePorts) diff --git a/pkg/edgeview/src/network.go b/pkg/edgeview/src/network.go index 2544a63338..03486a2eb4 100644 --- a/pkg/edgeview/src/network.go +++ b/pkg/edgeview/src/network.go @@ -121,8 +121,6 @@ func runNetwork(netw string) { runmDNS(substring) } else if opt == "tcp" { // tcp and proxy are special setAndStartProxyTCP(substring) - } else if opt == "pprof" { - runPprof() } else if opt == "showcerts" { getPeerCerts(substring) } else if opt == "addhost" { diff --git a/pkg/edgeview/src/system.go b/pkg/edgeview/src/system.go index de657e1c9e..6b66a8989e 100644 --- a/pkg/edgeview/src/system.go +++ b/pkg/edgeview/src/system.go @@ -13,6 +13,7 @@ import ( "encoding/base64" "encoding/json" "encoding/pem" + "errors" "fmt" "io" "net/http" @@ -96,6 +97,8 @@ func runSystem(cmds cmdOpt, sysOpt string) { getDmesg() } else if strings.HasPrefix(opt, "tar/") { getTarFile(opt) + } else if strings.HasPrefix(opt, "pprof") { + togglePprof(opt) } else { fmt.Printf("opt %s: not supported yet\n", opt) } @@ -980,6 +983,21 @@ func dispAFile(f os.FileInfo) { fmt.Printf("%s, %v, %d, %s\n", f.Mode().String(), f.ModTime(), f.Size(), f.Name()) } +func togglePprof(opt string) { + toggle := strings.SplitN(opt, "pprof/", 2) + if len(toggle) != 2 { + fmt.Printf("pprof needs to be either pprof/on or pprof/off\n") + return + } + + if toggle[1] == "on" { + runPprof() + } + if toggle[1] == "off" { + stopPprof() + } +} + func runPprof() { cmd := exec.Command("/usr/bin/pkill", "-USR2", "/opt/zededa/bin/zedbox") @@ -987,11 +1005,11 @@ func runPprof() { if err != nil { fmt.Printf("could not signal zedbox to run pprof") } +} - setAndStartProxyTCP("localhost:6543") - - _, err = http.Post("http://localhost:6543/stop", "", nil) - if err != nil { +func stopPprof() { + _, err := http.Post("http://localhost:6543/stop", "", nil) + if err != nil && !errors.Is(err, io.EOF) { fmt.Printf("could not stop pprof: %+v\n", err) } }