style: Remove the old profiler label frames code in the servo codebase and replace it with the new API

Differential Revision: https://phabricator.services.mozilla.com/D120795
This commit is contained in:
Nazım Can Altınova 2023-05-22 13:08:55 +02:00 committed by Oriol Brufau
parent 9e33a154fd
commit 5a9fae3fb5
6 changed files with 5 additions and 109 deletions

View file

@ -140,7 +140,7 @@ where
// ensures that we process all the elements at a given depth before // ensures that we process all the elements at a given depth before
// proceeding to the next depth, which is important for style sharing. // proceeding to the next depth, which is important for style sharing.
rayon::scope_fifo(|scope| { rayon::scope_fifo(|scope| {
profiler_label!(Style); gecko_profiler_label!(Layout, StyleComputation);
parallel::traverse_nodes( parallel::traverse_nodes(
drain, drain,
DispatchMode::TailCall, DispatchMode::TailCall,

View file

@ -13,8 +13,6 @@ pub mod conversions;
pub mod data; pub mod data;
pub mod media_features; pub mod media_features;
pub mod media_queries; pub mod media_queries;
#[cfg(feature = "gecko_profiler")]
pub mod profiler;
pub mod pseudo_element; pub mod pseudo_element;
pub mod restyle_damage; pub mod restyle_damage;
pub mod selector_parser; pub mod selector_parser;

View file

@ -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<structs::AutoProfilerLabel>,
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
}

View file

@ -33,6 +33,8 @@ extern crate cssparser;
extern crate debug_unreachable; extern crate debug_unreachable;
#[macro_use] #[macro_use]
extern crate derive_more; extern crate derive_more;
#[macro_use]
extern crate gecko_profiler;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
#[macro_use] #[macro_use]
pub mod gecko_string_cache; pub mod gecko_string_cache;

View file

@ -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")] #[cfg(feature = "servo")]
macro_rules! local_name { macro_rules! local_name {
($s:tt) => { ($s:tt) => {

View file

@ -274,7 +274,7 @@ pub fn traverse_nodes<'a, 'scope, E, D, I>(
top_down_dom(&work, root, traversal_data, scope, pool, traversal, tls); top_down_dom(&work, root, traversal_data, scope, pool, traversal, tls);
} else { } else {
scope.spawn_fifo(move |scope| { scope.spawn_fifo(move |scope| {
profiler_label!(Style); gecko_profiler_label!(Layout, StyleComputation);
let work = work; let work = work;
top_down_dom(&work, root, traversal_data, scope, pool, traversal, tls); 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<E::ConcreteNode> = chunk.collect(); let nodes: WorkUnit<E::ConcreteNode> = chunk.collect();
let traversal_data_copy = traversal_data.clone(); let traversal_data_copy = traversal_data.clone();
scope.spawn_fifo(move |scope| { scope.spawn_fifo(move |scope| {
profiler_label!(Style); gecko_profiler_label!(Layout, StyleComputation);
let n = nodes; let n = nodes;
top_down_dom(&*n, root, traversal_data_copy, scope, pool, traversal, tls) top_down_dom(&*n, root, traversal_data_copy, scope, pool, traversal, tls)
}); });