Bug 1331856 - Add style performance statistics to Servo. r=emilio

MozReview-Commit-ID: ECHZgYNA8nb
This commit is contained in:
Bobby Holley 2017-01-18 19:03:19 -08:00
parent 3a8167350b
commit 5370224877
5 changed files with 95 additions and 29 deletions

View file

@ -16,16 +16,8 @@ use selector_parser::RestyleDamage;
use servo_config::opts;
use std::borrow::BorrowMut;
use std::mem;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use stylist::Stylist;
/// Style sharing candidate cache hits. These are only used when
/// `-Z style-sharing-stats` is given.
pub static STYLE_SHARING_CACHE_HITS: AtomicUsize = ATOMIC_USIZE_INIT;
/// Style sharing candidate cache misses.
pub static STYLE_SHARING_CACHE_MISSES: AtomicUsize = ATOMIC_USIZE_INIT;
/// A per-traversal-level chunk of data. This is sent down by the traversal, and
/// currently only holds the dom depth for the bloom filter.
///
@ -386,6 +378,7 @@ pub fn recalc_style_at<E, D>(traversal: &D,
D: DomTraversal<E>
{
context.thread_local.begin_element(element, &data);
context.thread_local.statistics.elements_traversed += 1;
debug_assert!(data.get_restyle().map_or(true, |r| r.snapshot.is_none()),
"Snapshots should be expanded by the caller");
@ -446,6 +439,7 @@ fn compute_style<E, D>(_traversal: &D,
where E: TElement,
D: DomTraversal<E>,
{
context.thread_local.statistics.elements_styled += 1;
let shared_context = context.shared;
// Ensure the bloom filter is up to date.
let dom_depth = context.thread_local.bloom_filter
@ -472,11 +466,8 @@ fn compute_style<E, D>(_traversal: &D,
StyleSharingResult::CannotShare => {
let match_results;
let shareable_element = {
if opts::get().style_sharing_stats {
STYLE_SHARING_CACHE_MISSES.fetch_add(1, Ordering::Relaxed);
}
// Perform the CSS selector matching.
context.thread_local.statistics.elements_matched += 1;
let filter = context.thread_local.bloom_filter.filter();
match_results = element.match_element(context, Some(filter));
if match_results.primary_is_shareable() {
@ -505,9 +496,7 @@ fn compute_style<E, D>(_traversal: &D,
}
}
StyleSharingResult::StyleWasShared(index) => {
if opts::get().style_sharing_stats {
STYLE_SHARING_CACHE_HITS.fetch_add(1, Ordering::Relaxed);
}
context.thread_local.statistics.styles_shared += 1;
context.thread_local.style_sharing_candidate_cache.touch(index);
}
}