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_COLLECT=1
__RESH_PWD="$PWD" __RESH_PWD="$PWD"
__RESH_CMDLINE="$1" __RESH_CMDLINE="$1"
__RESH_RT_BEFORE=$EPOCHREALTIME
} }
precmd() { precmd() {
__RESH_EXIT_CODE=$? __RESH_EXIT_CODE=$?
__RESH_RT_AFTER=$EPOCHREALTIME
if [ ! -z ${__RESH_COLLECT+x} ]; then 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 fi
unset __RESH_COLLECT unset __RESH_COLLECT
} }

@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"os/user" "os/user"
"path/filepath" "path/filepath"
"flag"
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
@ -26,19 +27,32 @@ func main() {
return 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 { if err != nil {
// log this log.Fatal("Flag Parsing error:", err)
log.Fatal("First arg is not a number! (expecting $?)", err)
} }
pwd := os.Args[2]
cmdLine := os.Args[3]
rec := common.Record{ rec := common.Record{
CmdLine: cmdLine, CmdLine: *cmdLine,
Pwd: pwd, Pwd: *pwd,
GitWorkTree: getGitDir(), GitWorkTree: getGitDir(),
Shell: os.Getenv("SHELL"), Shell: os.Getenv("SHELL"),
ExitCode: exitCode, ExitCode: *exitCode,
RealtimeBefore: realtimeBefore,
RealtimeAfter: realtimeAfter,
RealtimeDuration: realtimeDuration,
} }
sendRecord(rec, strconv.Itoa(config.Port)) sendRecord(rec, strconv.Itoa(config.Port))
} }

@ -6,6 +6,9 @@ type Record struct {
GitWorkTree string `json:"gitWorkTree"` GitWorkTree string `json:"gitWorkTree"`
Shell string `json:"shell"` Shell string `json:"shell"`
ExitCode int `json:"exitCode"` ExitCode int `json:"exitCode"`
RealtimeBefore float64 `json:"realtimeBefore"`
RealtimeAfter float64 `json:"realtimeAfter"`
RealtimeDuration float64 `json:"realtimeDuration"`
//Logs []string `json: "logs"` //Logs []string `json: "logs"`
} }

Loading…
Cancel
Save