Skip to content

Commit 654d7ba

Browse files
committed
refactor: continue with flow_preloader refactoring: a bit more left
1 parent ff56336 commit 654d7ba

File tree

8 files changed

+235
-117
lines changed

8 files changed

+235
-117
lines changed

src/db-backend/src/db.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,15 @@ pub struct BreakpointRecord {
784784
pub struct DbReplay {
785785
pub db: Box<Db>,
786786
pub step_id: StepId,
787+
pub call_key: CallKey,
787788
pub breakpoint_list: Vec<HashMap<usize, BreakpointRecord>>,
788789
}
789790

790791
impl DbReplay {
791792
pub fn new(db: Box<Db>) -> DbReplay {
792793
let mut breakpoint_list: Vec<HashMap<usize, BreakpointRecord>> = Default::default();
793794
breakpoint_list.resize_with(db.paths.len(), HashMap::new);
794-
DbReplay { db, step_id: StepId(0), breakpoint_list }
795+
DbReplay { db, step_id: StepId(0), call_key: CallKey(0), breakpoint_list }
795796
}
796797

797798
pub fn step_id_jump(&mut self, step_id: StepId) {
@@ -925,6 +926,7 @@ impl Replay for DbReplay {
925926
fn load_location(&mut self, expr_loader: &mut ExprLoader) -> Result<Location, Box<dyn Error>> {
926927
info!("load_location: db replay");
927928
let call_key = self.db.call_key_for_step(self.step_id);
929+
self.call_key = call_key;
928930
Ok(self.db.load_location(self.step_id, call_key, expr_loader))
929931
}
930932

@@ -999,6 +1001,27 @@ impl Replay for DbReplay {
9991001
Ok(locals)
10001002
}
10011003

1004+
fn load_value(&mut self, expression: &str) -> Result<ValueRecord, Box<dyn Error>> {
1005+
// TODO: a more optimal way: cache a hashmap? or change structure?
1006+
// or again start directly loading available values matching all expressions in the same time?:
1007+
// taking a set of expressions: probably best(maybe add an additional load_values)
1008+
for variable in &self.db.variables[self.step_id] {
1009+
if self.db.variable_names[variable.variable_id] == expression {
1010+
return Ok(variable.value.clone())
1011+
}
1012+
}
1013+
return Err(format!("variable {expression} not found on this step").into())
1014+
}
1015+
1016+
fn load_return_value(&mut self) -> Result<ValueRecord, Box<dyn Error>> {
1017+
// assumes self.load_location() has been ran, and that we have the current call key
1018+
Ok(self.db.calls[self.call_key].return_value.clone())
1019+
}
1020+
1021+
fn load_step_events(&mut self, step_id: StepId, exact: bool) -> Vec<DbRecordEvent> {
1022+
self.db.load_step_events(step_id, exact)
1023+
}
1024+
10021025
fn jump_to(&mut self, step_id: StepId) -> Result<bool, Box<dyn Error>> {
10031026
self.step_id = step_id;
10041027
Ok(true)

src/db-backend/src/diff.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use num_derive::FromPrimitive;
88
use runtime_tracing::FunctionId;
99
use log::info;
1010

11-
use crate::db::Db;
11+
use crate::db::{Db,DbReplay};
1212
use crate::trace_processor::{load_trace_data, load_trace_metadata, TraceProcessor};
1313
use crate::flow_preloader::FlowPreloader;
1414

@@ -146,7 +146,8 @@ pub fn index_diff(diff: Diff, trace_folder: &Path, multitrace_folder: &Path) ->
146146

147147
info!("diff_lines {diff_lines:?}");
148148
let mut flow_preloader = FlowPreloader::new();
149-
let flow_update = flow_preloader.load_diff_flow(diff_lines, &db);
149+
let mut replay = Box::new(DbReplay::new(db.clone()));
150+
let flow_update = flow_preloader.load_diff_flow(diff_lines, &db, &mut replay);
150151

151152
let raw = serde_json::to_string(&flow_update)?;
152153
std::fs::write(multitrace_folder.join("diff_index.json"), raw)?;

src/db-backend/src/expr_loader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ impl ExprLoader {
382382
Ok(())
383383
}
384384

385-
pub fn load_branch_for_step(&self, step: &DbStep, path: &PathBuf) -> HashMap<usize, BranchState> {
386-
let position = Position(step.line.0);
385+
pub fn load_branch_for_position(&self, position: Position, path: &PathBuf) -> HashMap<usize, BranchState> {
387386
let mut results: HashMap<usize, BranchState> = HashMap::default();
388387
if self.processed_files[path].position_branches.contains_key(&position) {
389388
let mut branch = self.processed_files[path].position_branches[&position].clone();
@@ -413,13 +412,13 @@ impl ExprLoader {
413412
results
414413
}
415414

416-
pub fn get_loop_shape(&self, step: &DbStep, path: &PathBuf) -> Option<LoopShape> {
415+
pub fn get_loop_shape(&self, line: Position, path: &PathBuf) -> Option<LoopShape> {
417416
info!("path {}", path.display());
418417
info!(
419418
"get_loop_shape {} {:?}",
420-
step.line.0, self.processed_files[path].position_loops
419+
line.0, self.processed_files[path].position_loops
421420
);
422-
if let Some(loop_shape_id) = self.processed_files[path].position_loops.get(&Position(step.line.0)) {
421+
if let Some(loop_shape_id) = self.processed_files[path].position_loops.get(&line) {
423422
return Some(self.processed_files[path].loop_shapes[loop_shape_id.0 as usize].clone());
424423
}
425424
None

0 commit comments

Comments
 (0)