@@ -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
201227proc getFolderSize (folderPath: string ): int64 =
202228 var totalSize: int64 = 0
0 commit comments