Skip to content

Commit 1cfe8bc

Browse files
committed
Handle artifact sizes
1 parent e6b27c0 commit 1cfe8bc

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

summarize/src/analysis.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::query_data::{QueryData, Results};
1+
use crate::query_data::{ArtifactSize, QueryData, Results};
22
use analyzeme::{Event, EventPayload, ProfilingData, Timestamp};
33
use measureme::rustc::*;
44
use rustc_hash::FxHashMap;
@@ -116,6 +116,7 @@ pub fn perform_analysis(data: ProfilingData) -> Results {
116116
}
117117

118118
let mut query_data = FxHashMap::<String, QueryData>::default();
119+
let mut artifact_sizes = Vec::<ArtifactSize>::default();
119120
let mut threads = FxHashMap::<_, PerThreadState>::default();
120121

121122
let mut record_event_data = |label: &Cow<'_, str>, f: &dyn Fn(&mut QueryData)| {
@@ -252,7 +253,9 @@ pub fn perform_analysis(data: ProfilingData) -> Results {
252253
// Bring the stack up-to-date
253254
thread.stack.push(current_event)
254255
}
255-
EventPayload::Integer(_) => todo!("Handle integers"),
256+
EventPayload::Integer(value) => {
257+
artifact_sizes.push(ArtifactSize::new(current_event.label.into_owned(), value))
258+
}
256259
}
257260
}
258261

@@ -263,6 +266,7 @@ pub fn perform_analysis(data: ProfilingData) -> Results {
263266

264267
Results {
265268
query_data: query_data.drain().map(|(_, value)| value).collect(),
269+
artifact_sizes,
266270
total_time,
267271
}
268272
}

summarize/src/diff.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
use crate::query_data::{QueryData, QueryDataDiff, Results};
1+
use crate::query_data::{ArtifactSize, ArtifactSizeDiff, QueryData, QueryDataDiff, Results};
22
use crate::signed_duration::SignedDuration;
33
use rustc_hash::{FxHashMap, FxHashSet};
44
use serde::{Deserialize, Serialize};
5+
use std::collections::HashSet;
56
use std::time::Duration;
67

78
#[derive(Serialize, Deserialize)]
89
pub struct DiffResults {
910
pub query_data: Vec<QueryDataDiff>,
11+
pub artifact_sizes: Vec<ArtifactSizeDiff>,
1012
pub total_time: SignedDuration,
1113
}
1214

1315
fn build_query_lookup(query_data: &[QueryData]) -> FxHashMap<&str, usize> {
1416
let mut lookup = FxHashMap::with_capacity_and_hasher(query_data.len(), Default::default());
15-
for i in 0..query_data.len() {
16-
lookup.insert(&query_data[i].label[..], i);
17+
for (i, data) in query_data.iter().enumerate() {
18+
lookup.insert(&data.label[..], i);
19+
}
20+
21+
lookup
22+
}
23+
24+
fn build_artifact_lookup(artifact_sizes: &[ArtifactSize]) -> FxHashMap<&str, usize> {
25+
let mut lookup = FxHashMap::with_capacity_and_hasher(artifact_sizes.len(), Default::default());
26+
for (i, data) in artifact_sizes.iter().enumerate() {
27+
lookup.insert(&data.label[..], i);
1728
}
1829

1930
lookup
@@ -53,8 +64,33 @@ pub fn calculate_diff(base: Results, change: Results) -> DiffResults {
5364

5465
query_data.sort_by(|l, r| r.self_time.duration.cmp(&l.self_time.duration));
5566

67+
let base_data = build_artifact_lookup(&base.artifact_sizes);
68+
let change_data = build_artifact_lookup(&change.artifact_sizes);
69+
let all_labels = base
70+
.artifact_sizes
71+
.iter()
72+
.chain(&change.artifact_sizes)
73+
.map(|a| a.label.as_str())
74+
.collect::<HashSet<_>>();
75+
let mut artifact_sizes: Vec<_> = all_labels
76+
.iter()
77+
.map(|l| {
78+
let b = base_data.get(l).map(|i| &base.artifact_sizes[*i]);
79+
let c = change_data.get(l).map(|i| &change.artifact_sizes[*i]);
80+
81+
match (b, c) {
82+
(Some(b), Some(c)) => c.clone() - b.clone(),
83+
(Some(_b), None) => todo!(),
84+
(None, Some(_c)) => todo!(),
85+
(None, None) => unreachable!(),
86+
}
87+
})
88+
.collect();
89+
artifact_sizes.sort_by(|l, r| r.size_change.cmp(&l.size_change));
90+
5691
DiffResults {
5792
query_data,
93+
artifact_sizes,
5894
total_time: sd(change.total_time) - sd(base.total_time),
5995
}
6096
}

summarize/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
148148

149149
println!("Total cpu time: {:?}", results.total_time);
150150

151+
let mut table = Table::new();
152+
153+
table.add_row(row!("Item", "Artifact Size Change",));
154+
155+
for artifact_size in results.artifact_sizes {
156+
let exclude = opt.exclude.iter().any(|e| artifact_size.label.contains(e));
157+
if exclude {
158+
continue;
159+
}
160+
161+
table.add_row(row![
162+
artifact_size.label,
163+
format!("{:.2?} bytes", artifact_size.size_change),
164+
]);
165+
}
166+
167+
table.printstd();
168+
151169
Ok(())
152170
}
153171

@@ -281,6 +299,19 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
281299
);
282300
}
283301

302+
let mut table = Table::new();
303+
304+
table.add_row(row!("Item", "Artifact Size",));
305+
306+
for artifact_size in results.artifact_sizes {
307+
table.add_row(row![
308+
artifact_size.label,
309+
format!("{:.2?} bytes", artifact_size.value),
310+
]);
311+
}
312+
313+
table.printstd();
314+
284315
Ok(())
285316
}
286317

summarize/src/query_data.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ fn percentage_change(base: Duration, change: Duration) -> f64 {
125125
#[derive(Serialize, Deserialize)]
126126
pub struct Results {
127127
pub query_data: Vec<QueryData>,
128+
pub artifact_sizes: Vec<ArtifactSize>,
128129
pub total_time: Duration,
129130
}
130131

@@ -135,3 +136,32 @@ impl Results {
135136
self.query_data.iter().find(|qd| qd.label == label).unwrap()
136137
}
137138
}
139+
140+
#[derive(Serialize, Deserialize, Debug, Clone)]
141+
pub struct ArtifactSize {
142+
pub label: String,
143+
pub value: u64,
144+
}
145+
146+
impl ArtifactSize {
147+
pub fn new(label: String, value: u64) -> Self {
148+
Self { label, value }
149+
}
150+
}
151+
152+
#[derive(Serialize, Deserialize, Debug)]
153+
pub struct ArtifactSizeDiff {
154+
pub label: String,
155+
pub size_change: i64,
156+
}
157+
158+
impl Sub for ArtifactSize {
159+
type Output = ArtifactSizeDiff;
160+
161+
fn sub(self, rhs: ArtifactSize) -> ArtifactSizeDiff {
162+
ArtifactSizeDiff {
163+
label: self.label,
164+
size_change: self.value as i64 - rhs.value as i64,
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)