mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1690624 - Replace the old profiler thread registration FFIs with the new API in webrender r=jrmuizel
Differential Revision: https://phabricator.services.mozilla.com/D116516
This commit is contained in:
parent
5bcc4d95af
commit
9c536ede95
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5819,6 +5819,7 @@ dependencies = [
|
||||
"euclid",
|
||||
"foreign-types",
|
||||
"fxhash",
|
||||
"gecko-profiler",
|
||||
"gleam",
|
||||
"log",
|
||||
"nsstring",
|
||||
|
@ -20,6 +20,7 @@ fxhash = "0.2.1"
|
||||
thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
|
||||
swgl = { path = "../wr/swgl" }
|
||||
wr_malloc_size_of = { path = "../wr/wr_malloc_size_of" }
|
||||
gecko-profiler = { path = "../../tools/profiler/rust-api" }
|
||||
|
||||
[dependencies.webrender]
|
||||
path = "../wr/webrender"
|
||||
|
@ -39,7 +39,6 @@ use webrender::sw_compositor::SwCompositor;
|
||||
use webrender::{
|
||||
api::units::*,
|
||||
api::*,
|
||||
host_utils::{thread_started, thread_stopped},
|
||||
render_api::*,
|
||||
set_profiler_hooks, AsyncPropertySampler, AsyncScreenshotHandle, Compositor, CompositorCapabilities,
|
||||
CompositorConfig, CompositorSurfaceTransform, DebugFlags, Device, MappableCompositor, MappedTileInfo,
|
||||
@ -886,6 +885,14 @@ extern "C" {
|
||||
struct GeckoProfilerHooks;
|
||||
|
||||
impl ProfilerHooks for GeckoProfilerHooks {
|
||||
fn register_thread(&self, thread_name: &str) {
|
||||
gecko_profiler::register_thread(thread_name);
|
||||
}
|
||||
|
||||
fn unregister_thread(&self) {
|
||||
gecko_profiler::unregister_thread();
|
||||
}
|
||||
|
||||
fn begin_marker(&self, label: &CStr) {
|
||||
unsafe {
|
||||
gecko_profiler_start_marker(label.as_ptr());
|
||||
@ -1081,10 +1088,10 @@ pub extern "C" fn wr_thread_pool_new(low_priority: bool) -> *mut WrThreadPool {
|
||||
}
|
||||
let name = format!("WRWorker{}#{}", priority_tag, idx);
|
||||
register_thread_with_profiler(name.clone());
|
||||
thread_started(&name);
|
||||
gecko_profiler::register_thread(&name);
|
||||
})
|
||||
.exit_handler(|_idx| {
|
||||
thread_stopped();
|
||||
gecko_profiler::unregister_thread();
|
||||
})
|
||||
.build();
|
||||
|
||||
|
@ -13,7 +13,7 @@ use std::thread;
|
||||
use crate::{
|
||||
api::units::*, api::ColorDepth, api::ExternalImageId, api::ImageRendering, api::YuvColorSpace, Compositor,
|
||||
CompositorCapabilities, CompositorSurfaceTransform, NativeSurfaceId, NativeSurfaceInfo, NativeTileId,
|
||||
host_utils::{thread_started, thread_stopped}, MappableCompositor, SWGLCompositeSurfaceInfo,
|
||||
profiler, MappableCompositor, SWGLCompositeSurfaceInfo,
|
||||
};
|
||||
|
||||
pub struct SwTile {
|
||||
@ -473,14 +473,14 @@ impl SwCompositeThread {
|
||||
// overhead.
|
||||
.stack_size(32 * 1024)
|
||||
.spawn(move || {
|
||||
thread_started(thread_name);
|
||||
profiler::register_thread(thread_name);
|
||||
// Process any available jobs. This will return a non-Ok
|
||||
// result when the job queue is dropped, causing the thread
|
||||
// to eventually exit.
|
||||
while let Some((job, band)) = info.take_job(true) {
|
||||
info.process_job(job, band);
|
||||
}
|
||||
thread_stopped();
|
||||
profiler::unregister_thread();
|
||||
})
|
||||
.expect("Failed creating SwComposite thread");
|
||||
result
|
||||
|
@ -1,26 +0,0 @@
|
||||
#[cfg(feature = "gecko")]
|
||||
mod utils {
|
||||
use std::ffi::CString;
|
||||
extern "C" {
|
||||
fn gecko_profiler_register_thread(name: *const ::std::os::raw::c_char);
|
||||
fn gecko_profiler_unregister_thread();
|
||||
}
|
||||
pub fn thread_started(thread_name: &str) {
|
||||
let name = CString::new(thread_name).unwrap();
|
||||
unsafe {
|
||||
// gecko_profiler_register_thread copies the passed name here.
|
||||
gecko_profiler_register_thread(name.as_ptr());
|
||||
}
|
||||
}
|
||||
pub fn thread_stopped() {
|
||||
unsafe { gecko_profiler_unregister_thread(); }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
mod utils {
|
||||
pub fn thread_started(_: &str) { }
|
||||
pub fn thread_stopped() { }
|
||||
}
|
||||
|
||||
pub use utils::*;
|
@ -130,7 +130,6 @@ mod api_resources;
|
||||
mod image_tiling;
|
||||
mod image_source;
|
||||
mod rectangle_occlusion;
|
||||
pub mod host_utils;
|
||||
|
||||
///
|
||||
pub mod intern;
|
||||
|
@ -1174,6 +1174,12 @@ impl Profiler {
|
||||
|
||||
/// Defines the interface for hooking up an external profiler to WR.
|
||||
pub trait ProfilerHooks : Send + Sync {
|
||||
/// Register a thread with the profiler.
|
||||
fn register_thread(&self, thread_name: &str);
|
||||
|
||||
/// Unregister a thread with the profiler.
|
||||
fn unregister_thread(&self);
|
||||
|
||||
/// Called at the beginning of a profile scope. The label must
|
||||
/// be a C string (null terminated).
|
||||
fn begin_marker(&self, label: &CStr);
|
||||
@ -1218,6 +1224,26 @@ pub struct ProfileScope {
|
||||
name: &'static CStr,
|
||||
}
|
||||
|
||||
|
||||
/// Register a thread with the Gecko Profiler.
|
||||
pub fn register_thread(thread_name: &str) {
|
||||
unsafe {
|
||||
if let Some(ref hooks) = PROFILER_HOOKS {
|
||||
hooks.register_thread(thread_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Unregister a thread with the Gecko Profiler.
|
||||
pub fn unregister_thread() {
|
||||
unsafe {
|
||||
if let Some(ref hooks) = PROFILER_HOOKS {
|
||||
hooks.unregister_thread();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Records a marker of the given duration that just ended.
|
||||
pub fn add_text_marker(label: &CStr, text: &str, duration: Duration) {
|
||||
unsafe {
|
||||
|
@ -97,7 +97,6 @@ use crate::render_target::{RenderTargetKind, BlitJob};
|
||||
use crate::texture_cache::{TextureCache, TextureCacheConfig};
|
||||
use crate::tile_cache::PictureCacheDebugInfo;
|
||||
use crate::util::drain_filter;
|
||||
use crate::host_utils::{thread_started, thread_stopped};
|
||||
use crate::rectangle_occlusion as occlusion;
|
||||
use upload::{upload_to_texture_cache, UploadTexturePool};
|
||||
|
||||
@ -1150,10 +1149,10 @@ impl Renderer {
|
||||
.thread_name(|idx|{ format!("WRWorker#{}", idx) })
|
||||
.start_handler(move |idx| {
|
||||
register_thread_with_profiler(format!("WRWorker#{}", idx));
|
||||
thread_started(&format!("WRWorker#{}", idx));
|
||||
profiler::register_thread(&format!("WRWorker#{}", idx));
|
||||
})
|
||||
.exit_handler(move |_idx| {
|
||||
thread_stopped();
|
||||
profiler::unregister_thread();
|
||||
})
|
||||
.build();
|
||||
Arc::new(worker.unwrap())
|
||||
@ -1177,7 +1176,7 @@ impl Renderer {
|
||||
|
||||
thread::Builder::new().name(scene_thread_name.clone()).spawn(move || {
|
||||
register_thread_with_profiler(scene_thread_name.clone());
|
||||
thread_started(&scene_thread_name);
|
||||
profiler::register_thread(&scene_thread_name);
|
||||
|
||||
let mut scene_builder = SceneBuilderThread::new(
|
||||
config,
|
||||
@ -1188,7 +1187,7 @@ impl Renderer {
|
||||
);
|
||||
scene_builder.run();
|
||||
|
||||
thread_stopped();
|
||||
profiler::unregister_thread();
|
||||
})?;
|
||||
|
||||
let low_priority_scene_tx = if options.support_low_priority_transactions {
|
||||
@ -1200,12 +1199,12 @@ impl Renderer {
|
||||
|
||||
thread::Builder::new().name(lp_scene_thread_name.clone()).spawn(move || {
|
||||
register_thread_with_profiler(lp_scene_thread_name.clone());
|
||||
thread_started(&lp_scene_thread_name);
|
||||
profiler::register_thread(&lp_scene_thread_name);
|
||||
|
||||
let mut scene_builder = lp_builder;
|
||||
scene_builder.run();
|
||||
|
||||
thread_stopped();
|
||||
profiler::unregister_thread();
|
||||
})?;
|
||||
|
||||
low_priority_scene_tx
|
||||
@ -1228,7 +1227,7 @@ impl Renderer {
|
||||
let enable_multithreading = options.enable_multithreading;
|
||||
thread::Builder::new().name(rb_thread_name.clone()).spawn(move || {
|
||||
register_thread_with_profiler(rb_thread_name.clone());
|
||||
thread_started(&rb_thread_name);
|
||||
profiler::register_thread(&rb_thread_name);
|
||||
|
||||
let texture_cache = TextureCache::new(
|
||||
max_internal_texture_size,
|
||||
@ -1264,7 +1263,7 @@ impl Renderer {
|
||||
namespace_alloc_by_client,
|
||||
);
|
||||
backend.run();
|
||||
thread_stopped();
|
||||
profiler::unregister_thread();
|
||||
})?;
|
||||
|
||||
let debug_method = if !options.enable_gpu_markers {
|
||||
|
Loading…
Reference in New Issue
Block a user