Skip to content

Commit

Permalink
Add a "total pixels drawn" line to the debug overlay, and express sam…
Browse files Browse the repository at this point in the history
…ple counts

as percentages to make them clearer
  • Loading branch information
pcwalton committed Aug 10, 2018
1 parent 86c95d8 commit a03ab4b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions webrender/src/profiler.rs
Expand Up @@ -98,19 +98,19 @@ impl ProfileCounter for IntProfileCounter {
}

#[cfg(feature = "debug_renderer")]
pub struct FloatProfileCounter {
pub struct PercentageProfileCounter {
description: &'static str,
value: f32,
}

#[cfg(feature = "debug_renderer")]
impl ProfileCounter for FloatProfileCounter {
impl ProfileCounter for PercentageProfileCounter {
fn description(&self) -> &'static str {
self.description
}

fn value(&self) -> String {
format!("{:.2}", self.value)
format!("{:.2}%", self.value * 100.0)
}
}

Expand Down Expand Up @@ -1119,21 +1119,27 @@ impl Profiler {
);

if !gpu_samplers.is_empty() {
let mut samplers = Vec::<FloatProfileCounter>::new();
let mut samplers = Vec::<PercentageProfileCounter>::new();
// Gathering unique GPU samplers. This has O(N^2) complexity,
// but we only have a few samplers per target.
let mut total = 0.0;
for sampler in gpu_samplers {
let value = sampler.count as f32 * screen_fraction;
total += value;
match samplers.iter().position(|s| {
s.description as *const _ == sampler.tag.label as *const _
}) {
Some(pos) => samplers[pos].value += value,
None => samplers.push(FloatProfileCounter {
None => samplers.push(PercentageProfileCounter {
description: sampler.tag.label,
value,
}),
}
}
samplers.push(PercentageProfileCounter {
description: "Total",
value: total,
});
let samplers: Vec<&ProfileCounter> = samplers.iter().map(|sampler| {
sampler as &ProfileCounter
}).collect();
Expand Down

0 comments on commit a03ab4b

Please sign in to comment.