Skip to content

Commit 81f4470

Browse files
committed
add self_time_change to summarize diff
self_time_change is percentage change of self_time from base. change to if base have value but the change do not the base values is inverted and if the change have value but the base do not the changes values is used.
1 parent 9476b16 commit 81f4470

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- `flamegraph`: new tool that uses the `inferno` crate to generate flamegraph svg files ([GH-73])
66
- `crox`: Added the `--dir` parameter to merge all events files in dir in to one trace file ([GH-84])
77
- `crox`: Added possibility to add multiple `file_prefix` parameters to merge all them to one trace file ([GH-84])
8+
- `summarize`: Added self_time_change as percentage change of self_time from base to the `diff` sub command ([GH-87])
89

910
### Changed
1011
- `measureme`: Events are recorded in a more compact format ([GH-76])
@@ -50,3 +51,4 @@
5051
[GH-73]: https://github.com/rust-lang/measureme/pull/73
5152
[GH-76]: https://github.com/rust-lang/measureme/pull/76
5253
[GH-84]: https://github.com/rust-lang/measureme/pull/84
54+
[GH-87]: https://github.com/rust-lang/measureme/pull/87

summarize/src/diff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn calculate_diff(base: Results, change: Results) -> DiffResults {
4444

4545
match (b, c) {
4646
(Some(b), Some(c)) => c.clone() - b.clone(),
47-
(Some(b), None) => b.as_query_data_diff(),
48-
(None, Some(c)) => c.invert(),
47+
(Some(b), None) => b.invert(),
48+
(None, Some(c)) => c.as_query_data_diff(),
4949
(None, None) => unreachable!(),
5050
}
5151
})

summarize/src/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error>> {
8888
table.add_row(row!(
8989
"Item",
9090
"Self Time",
91+
"Self Time Change",
9192
"Item count",
9293
"Cache hits",
9394
"Blocked time",
@@ -100,19 +101,12 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error>> {
100101
continue;
101102
}
102103

103-
fn print_i64(i: i64) -> String {
104-
if i >= 0 {
105-
format!("+{}", i)
106-
} else {
107-
format!("{}", i)
108-
}
109-
}
110-
111104
table.add_row(row![
112105
query_data.label,
113106
format!("{:.2?}", query_data.self_time),
114-
print_i64(query_data.invocation_count),
115-
print_i64(query_data.number_of_cache_hits),
107+
format!("{:+.2}%", query_data.self_time_change),
108+
format!("{:+}", query_data.invocation_count),
109+
format!("{:+}", query_data.number_of_cache_hits),
116110
format!("{:.2?}", query_data.blocked_time),
117111
format!("{:.2?}", query_data.incremental_load_time),
118112
]);

summarize/src/query_data.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl QueryData {
3838
QueryDataDiff {
3939
label: self.label.clone(),
4040
self_time: invert(self.self_time),
41+
self_time_change: -100.0,
4142
number_of_cache_misses: -(self.number_of_cache_misses as i64),
4243
number_of_cache_hits: -(self.number_of_cache_hits as i64),
4344
invocation_count: -(self.invocation_count as i64),
@@ -50,6 +51,7 @@ impl QueryData {
5051
QueryDataDiff {
5152
label: self.label.clone(),
5253
self_time: self.self_time.into(),
54+
self_time_change: std::f64::INFINITY,
5355
number_of_cache_misses: self.number_of_cache_misses as i64,
5456
number_of_cache_hits: self.number_of_cache_hits as i64,
5557
invocation_count: self.invocation_count as i64,
@@ -63,6 +65,7 @@ impl QueryData {
6365
pub struct QueryDataDiff {
6466
pub label: String,
6567
pub self_time: SignedDuration,
68+
pub self_time_change: f64,
6669
pub number_of_cache_misses: i64,
6770
pub number_of_cache_hits: i64,
6871
pub invocation_count: i64,
@@ -87,6 +90,7 @@ impl Sub for QueryData {
8790
QueryDataDiff {
8891
label: self.label,
8992
self_time: sd(self.self_time) - sd(rhs.self_time),
93+
self_time_change: percentage_change(rhs.self_time, self.self_time),
9094
number_of_cache_misses: i(self.number_of_cache_misses) - i(rhs.number_of_cache_misses),
9195
number_of_cache_hits: i(self.number_of_cache_hits) - i(rhs.number_of_cache_hits),
9296
invocation_count: i(self.invocation_count) - i(rhs.invocation_count),
@@ -96,6 +100,11 @@ impl Sub for QueryData {
96100
}
97101
}
98102

103+
fn percentage_change(base: Duration, change: Duration) -> f64 {
104+
let self_time_nanos = change.as_nanos() as i128 - base.as_nanos() as i128;
105+
self_time_nanos as f64 / base.as_nanos() as f64 * 100.0
106+
}
107+
99108
#[derive(Serialize, Deserialize)]
100109
pub struct Results {
101110
pub query_data: Vec<QueryData>,

0 commit comments

Comments
 (0)