func assessidle() {
	log.Printf("Launching %v for idle state resource usage assessment", icmd.Path)
	log.Println("Trying to determine idle state resource usage (no external traffic)")
	icmd.Run()
	f := Findings{}
	if icmd.ProcessState != nil {
		f.MemoryMaxRSS = int64(icmd.ProcessState.SysUsage().(*syscall.Rusage).Maxrss)
		f.CPUuser = int64(icmd.ProcessState.SysUsage().(*syscall.Rusage).Utime.Usec)
		f.CPUsys = int64(icmd.ProcessState.SysUsage().(*syscall.Rusage).Stime.Usec)
	}
	idlef <- f
}
assessidle performs the idle state resource usage assessment, that is,
the memory and CPU usage of the process without external traffic
package main
import (
	"bufio"
	"bytes"
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	"strings"
	"syscall"
	"time"
)
type Findings struct {
	MemoryMaxRSS int64 `json:"memory_in_bytes"`
	CPUuser      int64 `json:"cpuuser_in_usec"`
	CPUsys       int64 `json:"cpusys_in_usec"`
}
var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)
var icmd, pcmd *exec.Cmd
var idlef, peakf chan Findings
func main() {
	flag.Usage = func() {
		fmt.Printf("Usage:\n %s --target $BINARY \n [--api-path $HTTP_URL_PATH --api-port $HTTP_PORT --peak-delay $TIME_MS --sampletime-idle $TIME_SEC --sampletime-peak $TIME_SEC --export-findings $FILE --output json|openmetrics]\n", os.Args[0])
		fmt.Println("Example usage:\n rsg --target test/test --api-path /ping --api-port 8080 2>/dev/null")
		fmt.Println("Arguments:")
		flag.PrintDefaults()
	}
	target := flag.String("target", "", "The filesystem path of the binary or script to assess")
	idlest := flag.Int("sampletime-idle", 2, "[OPTIONAL] The time in seconds to perform idle resource usage assessment")
	peakst := flag.Int("sampletime-peak", 10, "[OPTIONAL] The time in seconds to perform peak resource usage assessment")
	apibaseurl := flag.String("api-baseurl", "http://127.0.0.1", "[OPTIONAL] The base URL component of the HTTP API to use for peak resource usage assessment")
	apipath := flag.String("api-path", "", "[OPTIONAL] The URL path component of the HTTP API to use for peak resource usage assessment")
	apiport := flag.String("api-port", "", "[OPTIONAL] The TCP port of the HTTP API to use for peak resource usage assessment")
	peakdelay := flag.Int("delay-peak", 10, "[OPTIONAL] The time in milliseconds to wait between two consecutive HTTP GET requests for peak resource usage assessment")
	exportfile := flag.String("export-findings", "", "[OPTIONAL] The filesystem path to export findings to; if not provided the results will be written to stdout")
	outputformat := flag.String("output", "json", "[OPTIONAL] The output format, valid values are 'json' and 'openmetrics'")
	showversion := flag.Bool("version", false, "Print the version of rsg and exit")
	flag.Parse()
	if *showversion {
		fmt.Printf("%v, commit %v, built at %v\n", version, commit, date)
		os.Exit(0)
	}
	if len(os.Args) == 0 || *target == "" {
		fmt.Printf("Need at least the target program to proceed\n\n")
		flag.Usage()
		os.Exit(1)
	}
	isampletime := time.Duration(*idlest) * time.Second
	psampletime := time.Duration(*peakst) * time.Second
	peakhammerpause := time.Duration(*peakdelay) * time.Millisecond
	idlef = make(chan Findings, 1)
	peakf = make(chan Findings, 1)
	icmd = exec.Command(*target)
	pcmd = exec.Command(*target)
	ifs := Findings{}
	pfs := Findings{}
	go assessidle()
	<-time.After(isampletime)
	log.Printf("Idle state assessment of %v completed\n", *target)
	if icmd.Process != nil {
		err := icmd.Process.Signal(os.Interrupt)
		if err != nil {
			log.Fatalf("Can't stop process: %v\n", err)
		}
	}
	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)
	if *apipath != "" && *apiport != "" {
		go assesspeak(*apibaseurl, *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)
	}
	export(ifs, pfs, *exportfile, *outputformat, *target)
}