diff --git a/README.md b/README.md index b32c6d6..c32b179 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ $ rsg --target test/test --api-path /ping --api-port 8080 You can also specify a file explicitly and suppress the status updates, like so: ```sh -$ go run main.go --target test/test \ - --api-path /ping --api-port 8080 \ - --export-findings ./results.json 2>/dev/null +$ rsg --target test/test \ + --api-path /ping --api-port 8080 \ + --export-findings ./results.json 2>/dev/null ``` Then, you could pull out specific results, say, using `jq`: diff --git a/main.go b/main.go index ffc9ce0..991af86 100644 --- a/main.go +++ b/main.go @@ -54,6 +54,8 @@ func main() { peakf = make(chan Findings, 1) icmd = exec.Command(*target) pcmd = exec.Command(*target) + ifs := Findings{} + pfs := Findings{} // Perform idle state assessment: go assessidle() @@ -65,28 +67,29 @@ func main() { log.Fatalf("Can't stop process: %v\n", err) } } - ifs := <-idlef + ifs = <-idlef log.Printf("Found idle state resource usage. MEMORY: %vkB CPU: %vms (user)/%vms (sys)", ifs.MemoryMaxRSS/1000, ifs.CPUuser/1000, ifs.CPUsys/1000) // Perform peak state assessment: - go assesspeak(*apiport, *apipath, peakhammerpause) - <-time.After(psampletime) - log.Printf("Peak state assessment of %v completed\n", *target) - if pcmd.Process != nil { - err := pcmd.Process.Signal(os.Interrupt) - if err != nil { - log.Fatalf("Can't stop process: %v\n", err) + if *apipath != "" && *apiport != "" { + go assesspeak(*apiport, *apipath, peakhammerpause) + <-time.After(psampletime) + log.Printf("Peak state assessment of %v completed\n", *target) + if pcmd.Process != nil { + err := pcmd.Process.Signal(os.Interrupt) + if err != nil { + log.Fatalf("Can't stop process: %v\n", err) + } } + pfs = <-peakf + log.Printf("Found peak state resource usage. MEMORY: %vkB CPU: %vms (user)/%vms (sys)", + pfs.MemoryMaxRSS/1000, + pfs.CPUuser/1000, + pfs.CPUsys/1000) } - pfs := <-peakf - log.Printf("Found peak state resource usage. MEMORY: %vkB CPU: %vms (user)/%vms (sys)", - pfs.MemoryMaxRSS/1000, - pfs.CPUuser/1000, - pfs.CPUsys/1000) - // Handle export of findings: export(ifs, pfs, *exportfile) }