Skip to content

Commit c954e8c

Browse files
committed
dump mermaid graph of dependencies
1 parent 18ddca6 commit c954e8c

File tree

2 files changed

+76
-10
lines changed

2 files changed

+76
-10
lines changed

src/function/execute.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use std::sync::Arc;
22

33
use crate::{
4-
local_state::ActiveQueryGuard, runtime::StampedValue, storage::DatabaseGen, Cycle, Database,
5-
Event, EventKind,
4+
durability::Durability,
5+
local_state::{ActiveQueryGuard, EdgeKind, QueryOrigin},
6+
runtime::StampedValue,
7+
storage::DatabaseGen,
8+
Cycle, Database, Event, EventKind,
69
};
710

811
use super::{memo::Memo, Configuration, IngredientImpl};
@@ -87,6 +90,39 @@ where
8790
self.diff_outputs(db, database_key_index, old_memo, &revisions);
8891
}
8992

93+
let id = format!(
94+
"id_{}_{}",
95+
database_key_index.ingredient_index.as_usize(),
96+
key.as_u32(),
97+
);
98+
println!(r#" {id}("{:?}")"#, database_key_index,);
99+
println!(
100+
" style {id} fill:#{}",
101+
match revisions.durability {
102+
Durability::LOW => "666",
103+
Durability::MEDIUM => "333",
104+
_ => "000",
105+
}
106+
);
107+
match &revisions.origin {
108+
QueryOrigin::Derived(edges) => {
109+
for (edge_kind, dependency_index) in edges.input_outputs.iter() {
110+
if let Some(key_index) = dependency_index.key_index {
111+
let dep_id = format!(
112+
"id_{}_{}",
113+
dependency_index.ingredient_index.as_usize(),
114+
key_index.as_u32()
115+
);
116+
println!(r#" {dep_id}("{:?}")"#, dependency_index);
117+
match edge_kind {
118+
EdgeKind::Input => println!(" {id}-->{dep_id}"),
119+
EdgeKind::Output => println!(" {dep_id}-->{id}"),
120+
};
121+
}
122+
}
123+
}
124+
_ => {}
125+
};
90126
let value = self
91127
.insert_memo(
92128
db,

src/input.rs

+38-8
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,28 @@ impl<C: Configuration> IngredientImpl<C> {
102102
}
103103

104104
let next_id = Id::from_u32(self.counter.fetch_add(1, Ordering::Relaxed));
105+
let durability = stamps[0].durability;
105106
let value = Value {
106107
id: next_id,
107108
fields,
108109
stamps,
109110
};
110-
self.struct_map.insert(value)
111+
let struct_ = self.struct_map.insert(value);
112+
let id = format!(
113+
"id_{}_{}",
114+
self.ingredient_index.as_usize(),
115+
next_id.as_u32(),
116+
);
117+
println!(r#" {id}("{:?}")"#, self.database_key_index(struct_));
118+
println!(
119+
" style {id} fill:#{}",
120+
match durability {
121+
Durability::LOW => "666",
122+
Durability::MEDIUM => "333",
123+
_ => "000",
124+
}
125+
);
126+
struct_
111127
}
112128

113129
/// Change the value of the field `field_index` to a new value.
@@ -161,17 +177,31 @@ impl<C: Configuration> IngredientImpl<C> {
161177
) -> &'db C::Fields {
162178
local_state::attach(db, |state| {
163179
let field_ingredient_index = self.ingredient_index.successor(field_index);
180+
let input_db_key_index = self.database_key_index(id);
164181
let id = id.as_id();
165182
let value = self.struct_map.get(id);
166183
let stamp = &value.stamps[field_index];
167-
state.report_tracked_read(
168-
DependencyIndex {
169-
ingredient_index: field_ingredient_index,
170-
key_index: Some(id),
171-
},
172-
stamp.durability,
173-
stamp.changed_at,
184+
let dep_index = DependencyIndex {
185+
ingredient_index: field_ingredient_index,
186+
key_index: Some(id),
187+
};
188+
let input_id = format!(
189+
" id_{}_{}",
190+
input_db_key_index.ingredient_index.as_usize(),
191+
input_db_key_index.key_index.as_u32()
192+
);
193+
let id = format!("id_{}_{}", field_ingredient_index.as_usize(), id.as_u32(),);
194+
println!(r#" {id}("{:?}")"#, dep_index);
195+
println!(
196+
" style {id} fill:#{}",
197+
match stamp.durability {
198+
Durability::LOW => "666",
199+
Durability::MEDIUM => "333",
200+
_ => "000",
201+
}
174202
);
203+
println!(" {id}-->{input_id}");
204+
state.report_tracked_read(dep_index, stamp.durability, stamp.changed_at);
175205
&value.fields
176206
})
177207
}

0 commit comments

Comments
 (0)