This repository was archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreplay.go
More file actions
66 lines (57 loc) · 1.41 KB
/
replay.go
File metadata and controls
66 lines (57 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"errors"
"os"
"github.com/stealthrocket/timecraft/internal/timecraft"
)
const replayUsage = `
Usage: timecraft replay [options] <process id>
Options:
-c, --config path Path to the timecraft configuration file (overrides TIMECRAFTCONFIG)
-h, --help Show this usage information
-q, --quiet Do not output the recording of stdout/stderr during the replay
-T, --trace Enable strace-like logging of host function calls
`
func replay(ctx context.Context, args []string) error {
var (
quiet = false
trace = false
)
flagSet := newFlagSet("timecraft replay", replayUsage)
boolVar(flagSet, &quiet, "q", "quiet")
boolVar(flagSet, &trace, "T", "trace")
args, err := parseFlags(flagSet, args)
if err != nil {
return err
}
if len(args) != 1 {
return errors.New(`expected exactly one process id as argument`)
}
processID, err := parseProcessID(args[0])
if err != nil {
return err
}
config, err := timecraft.LoadConfig()
if err != nil {
return err
}
registry, err := timecraft.OpenRegistry(config)
if err != nil {
return err
}
runtime, err := timecraft.NewRuntime(ctx, config)
if err != nil {
return err
}
defer runtime.Close(ctx)
replay := timecraft.NewReplay(registry, runtime, processID)
if !quiet {
replay.SetStdout(os.Stdout)
replay.SetStderr(os.Stderr)
}
if trace {
replay.SetTrace(os.Stderr)
}
return replay.Replay(ctx)
}