Skip to content

Commit 5582742

Browse files
committed
fix: pass structured diff and indexed diff flow as paths, not contents
otherwise it wasn't working when the files were a bit bigger: CLI args are limited storage for this goal, for now we don't remove the temp folder where we unzip the multitrace on `replay`: this is imo ok for MVP; but we need to decide on a strategy
1 parent 00c2595 commit 5582742

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

src/ct/trace/multitrace.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ proc makeMultitraceArchive(traceFolders: seq[string], rawDiff: string, structure
163163

164164
zipFolder(folder, outputPath)
165165

166-
removeDir(folder)
166+
# TODO: decide here: only when flag archive? or always? removeDir(folder)
167167

168168
proc makeMultitrace*(traceIdList: seq[int], diffSpecification: string, outputPath: string) =
169169
# make a folder , copy those traces , find this diff, eventually parse it and store it

src/ct/trace/replay.nim

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,8 @@ proc replayMultitrace*(archivePath: string, indexDiff: bool = false): bool =
3030
echo fmt"ERROR: couldn't import the trace with name {traceDir.extractFilename} from the multitrace"
3131
quit(1)
3232

33-
# TODO: improve this: use paths or temp folder or read from zip
34-
# currently we pass them through as CLI args, but they're probably with limited memory/size
35-
var structuredDiffJson = ""
36-
var indexDiffJson = ""
37-
3833
var structuredDiffPath = outputFolder / "diff.json"
39-
try:
40-
structuredDiffJson = readFile(structuredDiffPath)
41-
except CatchableError: # assume file read error for now
42-
# if no diff.json recorded: that's ok
43-
# we might have just a multitrace to replay multiple traces at once without a diff
44-
# in the future
45-
structuredDiffPath = ""
46-
structuredDiffJson = ""
47-
4834
var diffIndexPath = ""
49-
echo "index diff ", indexDiff
5035

5136
if indexDiff:
5237
let backend = if trace.lang.isDbBased:
@@ -61,40 +46,38 @@ proc replayMultitrace*(archivePath: string, indexDiff: bool = false): bool =
6146

6247
var eventualDiffIndexPath = outputFolder / "diff_index.json"
6348
if not fileExists(eventualDiffIndexPath):
64-
let process = startProcess(backend, args = @["index-diff", structuredDiffJson, traceDir, outputFolder], options={poParentStreams})
49+
let process = startProcess(backend, args = @["index-diff", structuredDiffPath, traceDir, outputFolder], options={poParentStreams})
6550
let exitCode = waitForExit(process)
6651

6752
if exitCode == 0:
6853
# replace with an archive with the indexed data
6954
removeFile(archivePath)
7055
zipFolder(outputFolder, archivePath)
7156
diffIndexPath = eventualDiffIndexPath
72-
indexDiffJson = readFile(diffIndexPath)
7357
else:
7458
echo "WARN: a problem with indexing diff: no diff index"
75-
diffIndexPath = "" # some kind of a problem
76-
indexDiffJson = ""
59+
diffIndexPath = "" # some kind of a problem # indexDiffJson = ""
7760

7861
# if ok: trace patched, diff indexed: archive still accessible
79-
# remove only the temp extracted folder
62+
# remove only the temp extracted folder: ok here for index-diff; not for `replay` in the next case for now
8063
removeDir(outputFolder)
8164
return false # this means it shouldn't restart: for now restart maybe supported in dev mode only for replays
8265
else:
8366
var eventualDiffIndexPath = outputFolder / "diff_index.json"
8467
if fileExists(eventualDiffIndexPath):
8568
diffIndexPath = eventualDiffIndexPath
86-
indexDiffJson = readFile(eventualDiffIndexPath)
8769
else:
8870
diffIndexPath = ""
89-
indexDiffJson = ""
90-
71+
9172
# trace imported, diff and eventually index copied: archive still accessible
92-
# remove only the temp extracted folder
93-
removeDir(outputFolder)
73+
# remove only the temp extracted folder?
74+
# TODO: stopped removing it (or remove after replay):
75+
# decide what to do for this folder: for now depend on it for index/run:
76+
# removeDir(outputFolder)
9477

9578
let recordCore = envLoadRecordCore()
9679

97-
return runRecordedTrace(trace, test=false, structuredDiffJson=structuredDiffJson, indexDiffJson=indexDiffJson, recordCore=recordCore)
80+
return runRecordedTrace(trace, test=false, structuredDiffPath=structuredDiffPath, indexDiffPath=diffIndexPath, recordCore=recordCore)
9881

9982
proc indexDiff*(multitracePath: string) =
10083
discard replayMultitrace(multitracePath, indexDiff=true)

src/ct/trace/run.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import std/[osproc, strformat, sequtils],
1010
proc runRecordedTrace*(
1111
trace: Trace,
1212
test: bool,
13-
structuredDiffJson: string = "",
14-
indexDiffJson: string = "",
13+
structuredDiffPath: string = "",
14+
indexDiffPath: string = "",
1515
recordCore: bool = false
1616
): bool =
1717
var args = if test: @[$trace.id, "--test"] else: @[$trace.id]
18-
if structuredDiffJson.len > 0:
18+
if structuredDiffPath.len > 0:
1919
args.add("--diff")
20-
args.add(structuredDiffJson)
21-
if indexDiffJson.len > 0:
20+
args.add(structuredDiffPath)
21+
if indexDiffPath.len > 0:
2222
args.add("--diff-index")
23-
args.add(indexDiffJson)
23+
args.add(indexDiffPath)
2424
return launchElectron(args, trace, ElectronLaunchMode.Default, recordCore, test)
2525

2626

@@ -57,7 +57,7 @@ proc runWithRestart(
5757
if not afterRestart:
5858
# for now assume not a multitrace/no diff
5959
# .. returns true if it should restart
60-
runRecordedTrace(recordedTrace, test, structuredDiffJson="", indexDiffJson="", recordCore=recordCore)
60+
runRecordedTrace(recordedTrace, test, structuredDiffPath="", indexDiffPath="", recordCore=recordCore)
6161
else:
6262
let process = startProcess(codetracerExe, args = @["replay", fmt"--id={recordedTrace.id}"], options = {poParentStreams})
6363
waitForExit(process) == RESTART_EXIT_CODE

src/db-backend/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ enum Commands {
6565
stdio: bool,
6666
},
6767
IndexDiff {
68-
structured_diff_raw: String, // _path: std::path::PathBuf,
68+
structured_diff_path: std::path::PathBuf,
6969
trace_folder: std::path::PathBuf,
7070
multitrace_folder: std::path::PathBuf,
7171
},
@@ -139,13 +139,12 @@ fn main() -> Result<(), Box<dyn Error>> {
139139
};
140140
}
141141
Commands::IndexDiff {
142-
structured_diff_raw,
142+
structured_diff_path,
143143
trace_folder,
144144
multitrace_folder,
145145
} => {
146-
// TODO: eventually structured diff path? big diff-s might not fit into CLI args
147-
// let raw = std::fs::read_to_string(structured_diff_path)?;
148-
let structured_diff = serde_json::from_str::<diff::Diff>(&structured_diff_raw)?;
146+
let raw = std::fs::read_to_string(structured_diff_path)?;
147+
let structured_diff = serde_json::from_str::<diff::Diff>(&raw)?;
149148
diff::index_diff(structured_diff, &trace_folder, &multitrace_folder)?;
150149
}
151150
}

src/frontend/index/args.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ proc parseArgs* =
4848
data.startOptions.inTest = true
4949
elif arg == cstring"--diff":
5050
if i + 1 < args.len:
51-
data.startOptions.diff = cast[Diff](JSON.parse(args[i + 1]))
51+
data.startOptions.diff = cast[Diff](JSON.parse(fs.readFileSync(args[i + 1], cstring"utf8")))
5252
data.startOptions.withDiff = true
5353
i += 2
5454
continue
@@ -57,7 +57,7 @@ proc parseArgs* =
5757
break
5858
elif arg == cstring"--diff-index":
5959
if i + 1 < args.len:
60-
data.startOptions.rawDiffIndex = args[i + 1]
60+
data.startOptions.rawDiffIndex = fs.readFileSync(args[i + 1], cstring"utf-8")
6161
i += 2
6262
continue
6363
else:

0 commit comments

Comments
 (0)