Skip to content

Commit 964e1a1

Browse files
display % total time
1 parent ad18c02 commit 964e1a1

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

site/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub mod self_profile {
263263
pub struct QueryData {
264264
pub label: String,
265265
pub self_time: Duration,
266+
pub percent_total_time: f32,
266267
pub number_of_cache_misses: usize,
267268
pub number_of_cache_hits: usize,
268269
pub invocation_count: usize,

site/src/server.rs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -633,45 +633,51 @@ fn get_self_profile_data(
633633
.as_ref()
634634
.ok_or(format!("No self profile results for this commit"))?
635635
.clone();
636+
let totals = self_profile::QueryData {
637+
label: String::from("Totals"),
638+
self_time: profile.query_data.iter().map(|qd| qd.self_time).sum(),
639+
// TODO: check against wall-time from perf stats
640+
percent_total_time: 100.0,
641+
number_of_cache_misses: profile
642+
.query_data
643+
.iter()
644+
.map(|qd| qd.number_of_cache_misses)
645+
.sum(),
646+
number_of_cache_hits: profile
647+
.query_data
648+
.iter()
649+
.map(|qd| qd.number_of_cache_hits)
650+
.sum(),
651+
invocation_count: profile
652+
.query_data
653+
.iter()
654+
.map(|qd| qd.invocation_count)
655+
.sum(),
656+
blocked_time: profile.query_data.iter().map(|qd| qd.blocked_time).sum(),
657+
incremental_load_time: profile
658+
.query_data
659+
.iter()
660+
.map(|qd| qd.incremental_load_time)
661+
.sum(),
662+
};
636663
let mut profile = self_profile::SelfProfile {
637-
totals: self_profile::QueryData {
638-
label: String::from("Totals"),
639-
self_time: profile.query_data.iter().map(|qd| qd.self_time).sum(),
640-
number_of_cache_misses: profile
641-
.query_data
642-
.iter()
643-
.map(|qd| qd.number_of_cache_misses)
644-
.sum(),
645-
number_of_cache_hits: profile
646-
.query_data
647-
.iter()
648-
.map(|qd| qd.number_of_cache_hits)
649-
.sum(),
650-
invocation_count: profile
651-
.query_data
652-
.iter()
653-
.map(|qd| qd.invocation_count)
654-
.sum(),
655-
blocked_time: profile.query_data.iter().map(|qd| qd.blocked_time).sum(),
656-
incremental_load_time: profile
657-
.query_data
658-
.iter()
659-
.map(|qd| qd.incremental_load_time)
660-
.sum(),
661-
},
662664
query_data: profile
663665
.query_data
664666
.into_iter()
665667
.map(|qd| self_profile::QueryData {
666668
label: qd.label,
667669
self_time: qd.self_time,
670+
percent_total_time: ((qd.self_time.as_nanos() as f64
671+
/ totals.self_time.as_nanos() as f64)
672+
* 100.0) as f32,
668673
number_of_cache_misses: qd.number_of_cache_misses,
669674
number_of_cache_hits: qd.number_of_cache_hits,
670675
invocation_count: qd.invocation_count,
671676
blocked_time: qd.blocked_time,
672677
incremental_load_time: qd.incremental_load_time,
673678
})
674679
.collect(),
680+
totals,
675681
};
676682

677683
if let Some(sort_idx) = sort_idx {
@@ -693,6 +699,11 @@ fn get_self_profile_data(
693699
((qd.number_of_cache_hits as f64 / qd.invocation_count as f64) * 10_000.0)
694700
as u64
695701
}),
702+
10 => profile.query_data.sort_by(|a, b| {
703+
a.percent_total_time
704+
.partial_cmp(&b.percent_total_time)
705+
.unwrap()
706+
}),
696707
_ => break,
697708
}
698709

site/static/detailed-query.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h3 id="title"></h3>
4747
<tr id="table-header">
4848
<th data-sort-idx="1" data-default-sort-dir="1">Query/Function</th>
4949
<th data-sort-idx="2" data-default-sort-dir="-1">Time</th>
50+
<th data-sort-idx="10" data-default-sort-dir="-1">% Total Time</th>
5051
<th class="delta">Δ</th>
5152
<th data-sort-idx="5" data-default-sort-dir="-1">Invocations</th>
5253
<th class="delta">Δ</th>
@@ -143,7 +144,7 @@ <h3 id="title"></h3>
143144
let cur = to_object(element);
144145
let prev = null;
145146
if (data.base_profile) {
146-
for (let prev_el of data.base_profile[0]) {
147+
for (let prev_el of [data.base_profile[0], ...data.base_profile[1]]) {
147148
if (to_object(prev_el).label == cur.label) {
148149
prev = to_object(prev_el);
149150
break;
@@ -158,12 +159,14 @@ <h3 id="title"></h3>
158159
td.classList.add("delta");
159160
}
160161
row.appendChild(td);
162+
return td;
161163
}
162164
if (idx == 0) {
163165
row.style.fontStyle = "italic";
164166
}
165167
td(row, cur.label);
166168
td(row, to_seconds(cur.self_time).toFixed(3));
169+
td(row, cur.percent_total_time.toFixed(2));
167170
if (prev) {
168171
td(row, fmt_delta(to_seconds(prev.self_time), to_seconds(cur.self_time)), true);
169172
} else {
@@ -199,9 +202,11 @@ <h3 id="title"></h3>
199202

200203
function to_object(element) {
201204
if (!element.length) {
205+
console.log("element:", element);
202206
element = [
203207
element.label,
204208
[ element.self_time.secs, element.self_time.nanos ],
209+
element.percent_total_time,
205210
element.number_of_cache_misses,
206211
element.number_of_cache_hits,
207212
element.invocation_count,
@@ -210,13 +215,14 @@ <h3 id="title"></h3>
210215
];
211216
}
212217
let [
213-
label, self_time, cache_misses,
218+
label, self_time, percent_total_time, cache_misses,
214219
_cache_hits, invocation_count, _blocked_time,
215220
incremental_load_time
216221
] = element;
217222
return {
218223
label,
219224
self_time,
225+
percent_total_time,
220226
cache_misses,
221227
invocation_count,
222228
incremental_load_time,

0 commit comments

Comments
 (0)