add realtime, use flags

pull/3/head
Simon Let 7 years ago
parent 1c1eed9fe5
commit 876e5e3c37
  1. 7
      bashrc.sh
  2. 30
      collect/resh-collect.go
  3. 3
      common/resh-common.go

@ -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
}

@ -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))
}

@ -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"`
}

Loading…
Cancel
Save