From 876e5e3c3741c3177a9c428d16f83481f32962bb Mon Sep 17 00:00:00 2001 From: Simon Let Date: Thu, 16 May 2019 01:46:38 +0200 Subject: [PATCH] add realtime, use flags --- bashrc.sh | 7 ++++++- collect/resh-collect.go | 30 ++++++++++++++++++++++-------- common/resh-common.go | 3 +++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bashrc.sh b/bashrc.sh index 52a527e..6f415a5 100644 --- a/bashrc.sh +++ b/bashrc.sh @@ -6,12 +6,17 @@ preexec() { __RESH_COLLECT=1 __RESH_PWD="$PWD" __RESH_CMDLINE="$1" + __RESH_RT_BEFORE=$EPOCHREALTIME } precmd() { __RESH_EXIT_CODE=$? + __RESH_RT_AFTER=$EPOCHREALTIME if [ ! -z ${__RESH_COLLECT+x} ]; then - resh-collect $__RESH_EXIT_CODE "$PWD" "$__RESH_CMDLINE" + resh-collect -cmd "$__RESH_CMDLINE" -status $__RESH_EXIT_CODE \ + -pwd "$PWD" \ + -realtimeBefore $__RESH_RT_BEFORE \ + -realtimeAfter $__RESH_RT_AFTER fi unset __RESH_COLLECT } diff --git a/collect/resh-collect.go b/collect/resh-collect.go index 7344e54..ce97c0e 100644 --- a/collect/resh-collect.go +++ b/collect/resh-collect.go @@ -7,6 +7,7 @@ import ( "os/exec" "os/user" "path/filepath" + "flag" "log" "net/http" "strconv" @@ -26,19 +27,32 @@ func main() { return } - exitCode, err := strconv.Atoi(os.Args[1]) + cmdLine := flag.String("cmd", "", "command line") + exitCode := flag.Int("status", -1, "exit code") + pwd := flag.String("pwd", "", "present working directory") + rtb := flag.String("realtimeBefore", "-1", "before $EPOCHREALTIME") + rta := flag.String("realtimeAfter", "-1", "after $EPOCHREALTIME") + flag.Parse() + + realtimeAfter, err := strconv.ParseFloat(*rta, 64) + realtimeBefore, err := strconv.ParseFloat(*rtb, 64) + realtimeDuration := realtimeAfter - realtimeBefore + if err != nil { + log.Fatal("Flag Parsing error:", err) + } if err != nil { - // log this - log.Fatal("First arg is not a number! (expecting $?)", err) + log.Fatal("Flag Parsing error:", err) } - pwd := os.Args[2] - cmdLine := os.Args[3] + rec := common.Record{ - CmdLine: cmdLine, - Pwd: pwd, + CmdLine: *cmdLine, + Pwd: *pwd, GitWorkTree: getGitDir(), Shell: os.Getenv("SHELL"), - ExitCode: exitCode, + ExitCode: *exitCode, + RealtimeBefore: realtimeBefore, + RealtimeAfter: realtimeAfter, + RealtimeDuration: realtimeDuration, } sendRecord(rec, strconv.Itoa(config.Port)) } diff --git a/common/resh-common.go b/common/resh-common.go index cdae3b2..8c51d01 100644 --- a/common/resh-common.go +++ b/common/resh-common.go @@ -6,6 +6,9 @@ type Record struct { GitWorkTree string `json:"gitWorkTree"` Shell string `json:"shell"` ExitCode int `json:"exitCode"` + RealtimeBefore float64 `json:"realtimeBefore"` + RealtimeAfter float64 `json:"realtimeAfter"` + RealtimeDuration float64 `json:"realtimeDuration"` //Logs []string `json: "logs"` }