diff --git a/components/style/driver.rs b/components/style/driver.rs index 475d04269c5..41833c9c320 100644 --- a/components/style/driver.rs +++ b/components/style/driver.rs @@ -140,7 +140,7 @@ where // ensures that we process all the elements at a given depth before // proceeding to the next depth, which is important for style sharing. rayon::scope_fifo(|scope| { - profiler_label!(Style); + gecko_profiler_label!(Layout, StyleComputation); parallel::traverse_nodes( drain, DispatchMode::TailCall, diff --git a/components/style/gecko/mod.rs b/components/style/gecko/mod.rs index 3ff2cfcf140..7b19810fcf2 100644 --- a/components/style/gecko/mod.rs +++ b/components/style/gecko/mod.rs @@ -13,8 +13,6 @@ pub mod conversions; pub mod data; pub mod media_features; pub mod media_queries; -#[cfg(feature = "gecko_profiler")] -pub mod profiler; pub mod pseudo_element; pub mod restyle_damage; pub mod selector_parser; diff --git a/components/style/gecko/profiler.rs b/components/style/gecko/profiler.rs deleted file mode 100644 index db269b497d1..00000000000 --- a/components/style/gecko/profiler.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -//! Gecko profiler support. -//! -//! Use the `profiler_label!` macro from macros.rs. - -use crate::gecko_bindings::structs; - -/// A label describing a category of work that style threads can perform. -pub enum ProfilerLabel { - /// Style computation. - Style, - /// Style sheet parsing. - Parse, -} - -/// RAII object that constructs and destroys a C++ AutoProfilerLabel object -/// pointed to be the specified reference. -#[cfg(feature = "gecko_profiler")] -pub struct AutoProfilerLabel<'a>(&'a mut structs::AutoProfilerLabel); - -#[cfg(feature = "gecko_profiler")] -impl<'a> AutoProfilerLabel<'a> { - /// Creates a new AutoProfilerLabel with the specified label type. - /// - /// unsafe since the caller must ensure that `label` is allocated on the - /// stack. - #[inline] - pub unsafe fn new( - label: &mut std::mem::MaybeUninit, - label_type: ProfilerLabel, - ) -> AutoProfilerLabel { - let category_pair = match label_type { - ProfilerLabel::Style => structs::JS::ProfilingCategoryPair_LAYOUT_StyleComputation, - ProfilerLabel::Parse => structs::JS::ProfilingCategoryPair_LAYOUT_CSSParsing, - }; - structs::Gecko_Construct_AutoProfilerLabel(label.as_mut_ptr(), category_pair); - AutoProfilerLabel(&mut *label.as_mut_ptr()) - } -} - -#[cfg(feature = "gecko_profiler")] -impl<'a> Drop for AutoProfilerLabel<'a> { - #[inline] - fn drop(&mut self) { - unsafe { - structs::Gecko_Destroy_AutoProfilerLabel(self.0); - } - } -} - -/// Whether the Gecko profiler is currently active. -/// -/// This implementation must be kept in sync with -/// `mozilla::profiler::detail::RacyFeatures::IsActive`. -#[cfg(feature = "gecko_profiler")] -#[inline] -pub fn profiler_is_active() -> bool { - use self::structs::profiler::detail; - use std::mem; - use std::sync::atomic::{AtomicU32, Ordering}; - - let active_and_features: &AtomicU32 = - unsafe { mem::transmute(&detail::RacyFeatures_sActiveAndFeatures) }; - (active_and_features.load(Ordering::Relaxed) & detail::RacyFeatures_Active) != 0 -} - -/// Always false when the Gecko profiler is disabled. -#[cfg(not(feature = "gecko_profiler"))] -#[inline] -pub fn profiler_is_active() -> bool { - false -} diff --git a/components/style/lib.rs b/components/style/lib.rs index a9853e4c823..ddfbd5d5995 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -33,6 +33,8 @@ extern crate cssparser; extern crate debug_unreachable; #[macro_use] extern crate derive_more; +#[macro_use] +extern crate gecko_profiler; #[cfg(feature = "gecko")] #[macro_use] pub mod gecko_string_cache; diff --git a/components/style/macros.rs b/components/style/macros.rs index f5937d8b469..e27a554acf4 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -105,35 +105,6 @@ macro_rules! define_keyword_type { }; } -/// Place a Gecko profiler label on the stack. -/// -/// The `label_type` argument must be the name of a variant of `ProfilerLabel`. -#[cfg(feature = "gecko_profiler")] -#[macro_export] -macro_rules! profiler_label { - ($label_type:ident) => { - let mut _profiler_label = - ::std::mem::MaybeUninit::<$crate::gecko_bindings::structs::AutoProfilerLabel>::uninit(); - let _profiler_label = if $crate::gecko::profiler::profiler_is_active() { - unsafe { - Some($crate::gecko::profiler::AutoProfilerLabel::new( - &mut _profiler_label, - $crate::gecko::profiler::ProfilerLabel::$label_type, - )) - } - } else { - None - }; - }; -} - -/// No-op when the Gecko profiler is not available. -#[cfg(not(feature = "gecko_profiler"))] -#[macro_export] -macro_rules! profiler_label { - ($label_type:ident) => {}; -} - #[cfg(feature = "servo")] macro_rules! local_name { ($s:tt) => { diff --git a/components/style/parallel.rs b/components/style/parallel.rs index f03bf64fe61..fea031115a7 100644 --- a/components/style/parallel.rs +++ b/components/style/parallel.rs @@ -274,7 +274,7 @@ pub fn traverse_nodes<'a, 'scope, E, D, I>( top_down_dom(&work, root, traversal_data, scope, pool, traversal, tls); } else { scope.spawn_fifo(move |scope| { - profiler_label!(Style); + gecko_profiler_label!(Layout, StyleComputation); let work = work; top_down_dom(&work, root, traversal_data, scope, pool, traversal, tls); }); @@ -284,7 +284,7 @@ pub fn traverse_nodes<'a, 'scope, E, D, I>( let nodes: WorkUnit = chunk.collect(); let traversal_data_copy = traversal_data.clone(); scope.spawn_fifo(move |scope| { - profiler_label!(Style); + gecko_profiler_label!(Layout, StyleComputation); let n = nodes; top_down_dom(&*n, root, traversal_data_copy, scope, pool, traversal, tls) });