-
Notifications
You must be signed in to change notification settings - Fork 299
Register thread to WR's profiler and the external profiler. #2014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors-servo
merged 2 commits into
servo:master
from
JerryShih:register-thread-to-profiler
Nov 10, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1787,33 +1787,57 @@ impl Renderer { | |
let debug_flags = options.debug_flags; | ||
let payload_tx_for_backend = payload_tx.clone(); | ||
let recorder = options.recorder; | ||
let worker_config = ThreadPoolConfig::new() | ||
.thread_name(|idx| format!("WebRender:Worker#{}", idx)) | ||
.start_handler(|idx| { | ||
register_thread_with_profiler(format!("WebRender:Worker#{}", idx)); | ||
}); | ||
let thread_listener = Arc::new(options.thread_listener); | ||
let thread_listener_for_rayon_start = thread_listener.clone(); | ||
let thread_listener_for_rayon_end = thread_listener.clone(); | ||
let workers = options | ||
.workers | ||
.take() | ||
.unwrap_or_else(|| Arc::new(ThreadPool::new(worker_config).unwrap())); | ||
.unwrap_or_else(|| { | ||
let worker_config = ThreadPoolConfig::new() | ||
.thread_name(|idx|{ format!("WRWorker#{}", idx) }) | ||
.start_handler(move |idx| { | ||
register_thread_with_profiler(format!("WRWorker#{}", idx)); | ||
if let Some(ref thread_listener) = *thread_listener_for_rayon_start { | ||
thread_listener.thread_started(&format!("WRWorker#{}", idx)); | ||
} | ||
}) | ||
.exit_handler(move |idx| { | ||
if let Some(ref thread_listener) = *thread_listener_for_rayon_end { | ||
thread_listener.thread_stopped(&format!("WRWorker#{}", idx)); | ||
} | ||
}); | ||
Arc::new(ThreadPool::new(worker_config).unwrap()) | ||
}); | ||
let enable_render_on_scroll = options.enable_render_on_scroll; | ||
|
||
let blob_image_renderer = options.blob_image_renderer.take(); | ||
try!{ thread::Builder::new().name("RenderBackend".to_string()).spawn(move || { | ||
let mut backend = RenderBackend::new(api_rx, | ||
payload_rx, | ||
payload_tx_for_backend, | ||
result_tx, | ||
device_pixel_ratio, | ||
texture_cache, | ||
workers, | ||
backend_notifier, | ||
config, | ||
recorder, | ||
blob_image_renderer, | ||
enable_render_on_scroll); | ||
backend.run(backend_profile_counters); | ||
})}; | ||
let thread_listener_for_render_backend = thread_listener.clone(); | ||
let thread_name = format!("WRRenderBackend#{}", options.renderer_id.unwrap_or(0)); | ||
try!{ | ||
thread::Builder::new().name(thread_name.clone()).spawn(move || { | ||
register_thread_with_profiler(thread_name.clone()); | ||
if let Some(ref thread_listener) = *thread_listener_for_render_backend { | ||
thread_listener.thread_started(&thread_name); | ||
} | ||
let mut backend = RenderBackend::new(api_rx, | ||
payload_rx, | ||
payload_tx_for_backend, | ||
result_tx, | ||
device_pixel_ratio, | ||
texture_cache, | ||
workers, | ||
backend_notifier, | ||
config, | ||
recorder, | ||
blob_image_renderer, | ||
enable_render_on_scroll); | ||
backend.run(backend_profile_counters); | ||
if let Some(ref thread_listener) = *thread_listener_for_render_backend { | ||
thread_listener.thread_stopped(&thread_name); | ||
} | ||
}) | ||
}; | ||
|
||
let gpu_cache_texture = CacheTexture::new(&mut device); | ||
|
||
|
@@ -3826,6 +3850,11 @@ pub trait OutputImageHandler { | |
fn unlock(&mut self, pipeline_id: PipelineId); | ||
} | ||
|
||
pub trait ThreadListener { | ||
fn thread_started(&self, thread_name: &str); | ||
fn thread_stopped(&self, thread_name: &str); | ||
} | ||
|
||
pub struct RendererOptions { | ||
pub device_pixel_ratio: f32, | ||
pub resource_override_path: Option<PathBuf>, | ||
|
@@ -3845,8 +3874,10 @@ pub struct RendererOptions { | |
pub workers: Option<Arc<ThreadPool>>, | ||
pub blob_image_renderer: Option<Box<BlobImageRenderer>>, | ||
pub recorder: Option<Box<ApiRecordingReceiver>>, | ||
pub thread_listener: Option<Box<ThreadListener + Send + Sync>>, | ||
pub enable_render_on_scroll: bool, | ||
pub debug_flags: DebugFlags, | ||
pub renderer_id: Option<u64>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might have multiple renderer in the same process. Use this renderer_id for identification. |
||
} | ||
|
||
impl Default for RendererOptions { | ||
|
@@ -3871,7 +3902,9 @@ impl Default for RendererOptions { | |
workers: None, | ||
blob_image_renderer: None, | ||
recorder: None, | ||
thread_listener: None, | ||
enable_render_on_scroll: true, | ||
renderer_id: None, | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The worker_config is only used when we don't have the thread pool. So, move the config into the worker's unwrap_or_else() block.