diff --git a/scripts/weight-diff.sh b/scripts/weight-diff.sh index 161c9941b8e..ae52c2c55c3 100755 --- a/scripts/weight-diff.sh +++ b/scripts/weight-diff.sh @@ -53,3 +53,4 @@ git checkout "$current_branch" cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag +cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag diff --git a/utils/weight-diff/src/main.rs b/utils/weight-diff/src/main.rs index 22dcdda5abf..f99233311d9 100644 --- a/utils/weight-diff/src/main.rs +++ b/utils/weight-diff/src/main.rs @@ -76,6 +76,7 @@ enum Runtime { enum WeightsKind { Instruction, HostFn, + Memory, } #[derive(Debug, Serialize)] @@ -97,6 +98,7 @@ struct DeserializableDump { struct DeserializableSchedule { instruction_weights: IndexMap, host_fn_weights: IndexMap, + memory_weights: IndexMap, } impl DeserializableSchedule { @@ -127,6 +129,18 @@ impl DeserializableSchedule { map } + + fn memory_weights(&self) -> IndexMap { + let mut map = IndexMap::new(); + + for (k, v) in self.memory_weights.clone() { + if let Ok(v) = serde_json::from_value::(v) { + map.insert(k, v.ref_time()); + } + } + + map + } } fn format_weight(weight: u64) -> String { @@ -214,6 +228,7 @@ fn main() { schedule2.instruction_weights(), ), WeightsKind::HostFn => (schedule1.host_fn_weights(), schedule2.host_fn_weights()), + WeightsKind::Memory => (schedule1.memory_weights(), schedule2.memory_weights()), }; let mut result_map = IndexMap::new();