Skip to content

Commit 23c82f4

Browse files
pxoralehander92
authored andcommitted
feat: Add a start_backend command for ct and start db-backend from same executable
1 parent b91b4d1 commit 23c82f4

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/ct/codetracerconf.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type
5353
# summary,
5454
# `report-bug`,
5555
`trace-metadata`, # TODO .hidden?
56+
start_backend,
5657

5758
type
5859
# the following TODOs are for changes in confutils
@@ -478,6 +479,18 @@ type
478479
name: "test",
479480
defaultValue: false,
480481
.}: bool
482+
of start_backend:
483+
backendKind* {.
484+
argument
485+
desc: "This is the backend kind - either 'db' or 'rr'"
486+
.}: string
487+
isStdio* {.
488+
name: "stdio",
489+
defaultValue: false,
490+
.}: bool
491+
socketPath* {.
492+
name: "socket-path",
493+
.}: Option[string]
481494

482495
proc customValidateConfig*(conf: CodetracerConf) =
483496
case conf.cmd:

src/ct/launch/backends.nim

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,51 @@
11
import
2-
std/[strformat, strutils, osproc, posix, posix_utils],
3-
../../common/[start_utils, types, trace_index],
2+
std/[strformat, strutils, osproc, posix, posix_utils, os, options],
3+
../../common/[start_utils, types, trace_index, paths, config],
44
../utilities/[env],
55
../cli/[logging],
66
cleanup
77

88
var coreProcessId* = -1
99

10+
proc startBackend*(backendKind: string, isStdio: bool, socketPath: Option[string]) =
11+
let backendExe =
12+
if backendKind == "db":
13+
dbBackendExe
14+
elif backendKind == "rr":
15+
let ctConfig = loadConfig(folder=getCurrentDir(), inTest=false)
16+
if ctConfig.rrBackend.enabled:
17+
ctConfig.rrBackend.path
18+
else:
19+
echo "ERROR: rr backend not enabled!"
20+
quit(1)
21+
else:
22+
echo "ERROR: Backend kind not recognized, needs to be 'rr' or 'db'"
23+
quit(1)
24+
25+
let args =
26+
if isStdio:
27+
@["--stdio"]
28+
elif socketPath.isSome:
29+
@[socketPath.get()]
30+
else:
31+
echo "ERRROR: Needs to have either --stdio or a valid socket path"
32+
quit(1)
33+
34+
let process = startProcess(
35+
backendExe,
36+
args = args,
37+
options = { poParentStreams }
38+
)
39+
40+
coreProcessId = process.processId
41+
onSignal(SIGTERM):
42+
if coreProcessId != -1:
43+
echo "ct: stopping core process"
44+
sendSignal(coreProcessId.Pid, SIGTERM)
45+
46+
let code = waitForExit(process)
47+
quit(code)
48+
1049
proc startCore*(traceArg: string, callerPid: int, test: bool) =
1150
# start_core <trace-program-pattern> <caller-pid> [--test]
1251
let recordCore = envLoadRecordCore()

src/ct/launch/launch.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,5 @@ proc runInitial*(conf: CodetracerConf) =
182182
conf.traceMetadataRecent,
183183
conf.traceMetadataRecentLimit,
184184
conf.traceMetadataTest)
185+
of StartupCommand.start_backend:
186+
startBackend(conf.backendKind, conf.isStdio, conf.socketPath)

0 commit comments

Comments
 (0)