Skip to content

Commit 7250308

Browse files
committed
fix: finish initial adapting to simpler rr support record: reuse importTrace
1 parent a8aa4a3 commit 7250308

File tree

5 files changed

+66
-37
lines changed

5 files changed

+66
-37
lines changed

src/ct/db_backend_record.nim

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ proc recordWithRR(
7373
echo fmt"error: ct-rr-support returned exit code ", code
7474
quit(code)
7575

76-
var trace = Json.decode(readFile(traceDbMetadataPath), Trace)
77-
trace.id = traceId
78-
79-
result = importDbTrace(traceMetadataPath, traceId, recordPid, lang, DB_SELF_CONTAINED_DEFAULT)
76+
# record pid and lang in trace_db_metadata.json
77+
result = importTrace(traceFolder, traceId, NO_PID, LangUnknown, DB_SELF_CONTAINED_DEFAULT, traceKind="rr")
8078

8179

8280
# rr patches for ruby/other vm-s: not supported now, instead
@@ -182,7 +180,7 @@ proc recordDb(
182180
echo fmt"error: recorder exited with {exitCode} for {lang}"
183181
quit(1)
184182

185-
result = importDbTrace(traceMetadataPath, traceId, recordPid, lang, DB_SELF_CONTAINED_DEFAULT)
183+
result = importTrace(traceFolder, traceId, recordPid, lang, DB_SELF_CONTAINED_DEFAULT, traceKind="db")
186184

187185

188186
# record a program run
@@ -313,9 +311,14 @@ proc record(
313311
traceId,
314312
pythonActivationPath = activationPathResolved)
315313
elif traceKind == "rr":
316-
echo "TODO rr"
314+
echo "rr"
317315
echo rrSupportPath
318-
quit(1)
316+
return recordWithRR(
317+
rrSupportPath,
318+
executable,
319+
args,
320+
outputFolder,
321+
traceId)
319322
else:
320323
echo fmt"ERROR: unsupported lang {lang}"
321324
quit(1)

src/ct/online_sharing/download.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ proc downloadTrace*(url: string): int =
3838
let lang = detectLang(pathValue.extractFilename, LangUnknown, isWasm)
3939
let recordPid = NO_PID # for now not processing the pid , but it can be
4040
# accessed from trace metadata file if we need it in the future
41-
discard importDbTrace(traceMetadataPath, traceId, recordPid, lang, DB_SELF_CONTAINED_DEFAULT, url)
41+
discard importTrace(unzippedLocation, traceId, recordPid, lang, DB_SELF_CONTAINED_DEFAULT, url)
4242
return traceId
4343

4444
proc downloadTraceCommand*(traceDownloadUrl: string) =

src/ct/trace/replay.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ proc replay*(
139139
trace = findTraceForArgs(patternArg, traceIdArg, traceFolderArg)
140140

141141
if trace.isNil and traceFolderArg.isSome:
142-
trace = importDbTrace(traceFolderArg.get() / "trace_metadata.json", NO_TRACE_ID, NO_PID, LangUnknown)
142+
trace = importTrace(traceFolderArg.get(), NO_TRACE_ID, NO_PID, LangUnknown)
143143
if trace.isNil:
144144
echo "ERROR: can't find or import trace"
145145
quit(1)

src/ct/trace/storage_and_import.nim

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ proc processSourceFoldersList*(folderSet: HashSet[string], programDir: string =
8383
result = sortedFolders
8484

8585

86-
proc importDbTrace*(
87-
traceMetadataPath: string,
86+
proc importTrace*(
87+
traceFolder: string,
8888
traceIdArg: int,
8989
recordPid: int,
9090
langArg: Lang = LangNoir,
@@ -93,7 +93,15 @@ proc importDbTrace*(
9393
traceKind: string = "db",
9494
): Trace =
9595

96-
# for rr: trace_db_metadata.json: has those fields but also many others
96+
# for now support different files with the same subset of fields:
97+
# db: trace_metadata.json
98+
# rr: trace_db_metadata.json:
99+
# both should have `program`, `args`, `workdir`(but maybe also others)
100+
let traceMetadataPath = if traceKind == "db":
101+
traceFolder / "trace_metadata.json"
102+
else:
103+
traceFolder / "trace_db_metadata.json"
104+
97105
echo traceMetadataPath
98106
let rawTraceMetadata = readFile(traceMetadataPath)
99107
let untypedJson = parseJson(rawTraceMetadata)
@@ -120,7 +128,11 @@ proc importDbTrace*(
120128
traceFolder
121129
if traceIdArg == NO_TRACE_ID:
122130
createDir(outputFolder)
123-
copyFile(traceMetadataPath, outputFolder / "trace_metadata.json")
131+
if traceMetadataPath.endsWith("trace_metadata.json"):
132+
copyFile(traceMetadataPath, outputFolder / "trace_metadata.json")
133+
elif traceMetadataPath.endsWith("trace_db_metadata.json"):
134+
copyFile(traceMetadataPath, outputFolder / "trace_db_metadata.json")
135+
124136
try:
125137
copyFile(tracePathsPath, outputFolder / "trace_paths.json")
126138
except CatchableError as e:
@@ -152,9 +164,9 @@ proc importDbTrace*(
152164
# for now assume this is used only for db traces
153165
# and that C/C++/Rust there can come only from wasm targets currently
154166
if traceLang == LangRust:
155-
lang = LangRustWasm
167+
lang = if traceKind == "db": LangRustWasm else: LangRust
156168
elif traceLang in {LangC, LangCpp}:
157-
lang = LangCppWasm
169+
lang = if traceKind == "db": LangCppWasm else: traceLang
158170
else:
159171
lang = traceLang
160172
break # for now assume the first detected lang is ok
@@ -176,27 +188,41 @@ proc importDbTrace*(
176188
let sourceFolders = processSourceFoldersList(sourceFoldersInitialSet, workdir)
177189
let sourceFoldersText = sourceFolders.join(" ")
178190

179-
trace_index.recordTrace(
180-
traceID,
181-
program = program,
182-
args = args,
183-
compileCommand = "",
184-
env = "",
185-
workdir = workdir,
186-
lang = lang,
187-
sourceFolders = sourceFoldersText,
188-
lowLevelFolder = "",
189-
outputFolder = outputFolder,
190-
test = false,
191-
imported = selfContained,
192-
shellID = -1,
193-
rrPid = recordPid,
194-
exitCode = -1,
195-
calltrace = true,
196-
# for now always use FullRecord for db-backend
197-
# and ignore possible env var override
198-
calltraceMode = CalltraceMode.FullRecord,
199-
fileId = downloadUrl)
191+
echo "traceKind ", traceKind
192+
if traceKind == "db":
193+
trace_index.recordTrace(
194+
traceID,
195+
program = program,
196+
args = args,
197+
compileCommand = "",
198+
env = "",
199+
workdir = workdir,
200+
lang = lang,
201+
sourceFolders = sourceFoldersText,
202+
lowLevelFolder = "",
203+
outputFolder = outputFolder,
204+
test = false,
205+
imported = selfContained,
206+
shellID = -1,
207+
rrPid = recordPid,
208+
exitCode = -1,
209+
calltrace = true,
210+
# for now always use FullRecord for db-backend
211+
# and ignore possible env var override
212+
calltraceMode = CalltraceMode.FullRecord,
213+
fileId = downloadUrl)
214+
else:
215+
try:
216+
var trace = Json.decode(readFile(traceMetadataPath), Trace)
217+
trace.id = traceID
218+
# trace.sourceFolders = sourceFolders
219+
trace.outputFolder = outputFolder
220+
trace.imported = selfContained
221+
echo trace.repr
222+
trace_index.recordTrace(trace, test=false)
223+
except CatchableError as e:
224+
echo "[codetracer importTrace error]: ", e.repr
225+
quit(1)
200226

201227
proc getFolderSize(folderPath: string): int64 =
202228
var totalSize: int64 = 0

src/db-backend/src/dap_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn launch(
119119
Ok(handler)
120120
} else {
121121
warn!("problem with reading metadata or path trace files: try rr?");
122-
let path = trace_folder.join("rr").join("latest-trace");
122+
let path = trace_folder.join("rr");
123123
if path.exists() {
124124
let db = Db::new(&PathBuf::from(""));
125125
let ct_rr_args = CtRRArgs {

0 commit comments

Comments
 (0)