Skip to content

Commit

Permalink
register stylo threads with the gecko profiler
Browse files Browse the repository at this point in the history
Now that we require rayon 0.7, we can register start and stop handlers
that take care of dealing with the Gecko profiler for rayon threads in
the style thread pool.
  • Loading branch information
froydnj committed May 9, 2017
1 parent 121662a commit 74ce5bd
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions components/style/gecko/global_style_data.rs
Expand Up @@ -5,11 +5,13 @@
//! Global style data

use context::StyleSystemOptions;
use gecko_bindings::bindings::{Gecko_RegisterProfilerThread, Gecko_UnregisterProfilerThread};
use num_cpus;
use rayon;
use shared_lock::SharedRwLock;
use std::cmp;
use std::env;
use std::ffi::CString;

/// Global style data
pub struct GlobalStyleData {
Expand All @@ -26,6 +28,25 @@ pub struct GlobalStyleData {
pub options: StyleSystemOptions,
}

fn thread_name(index: usize) -> String {
format!("StyleThread#{}", index)
}

fn thread_startup(index: usize) {
let name = thread_name(index);
let name = CString::new(name).unwrap();
unsafe {
// Gecko_RegisterProfilerThread copies the passed name here.
Gecko_RegisterProfilerThread(name.as_ptr());
}
}

fn thread_shutdown(_: usize) {
unsafe {
Gecko_UnregisterProfilerThread();
}
}

lazy_static! {
/// Global style data
pub static ref GLOBAL_STYLE_DATA: GlobalStyleData = {
Expand All @@ -39,8 +60,11 @@ lazy_static! {
let pool = if num_threads <= 1 {
None
} else {
let configuration =
rayon::Configuration::new().num_threads(num_threads);
let configuration = rayon::Configuration::new()
.num_threads(num_threads)
.thread_name(thread_name)
.start_handler(thread_startup)
.exit_handler(thread_shutdown);
let pool = rayon::ThreadPool::new(configuration).ok();
pool
};
Expand Down

0 comments on commit 74ce5bd

Please sign in to comment.