diff --git a/webrender/src/profiler.rs b/webrender/src/profiler.rs index e28d70ccde..da3f6902f9 100644 --- a/webrender/src/profiler.rs +++ b/webrender/src/profiler.rs @@ -82,6 +82,10 @@ pub trait ProfilerHooks : Send + Sync { /// be a C string (null terminated). fn end_marker(&self, label: &CStr); + /// Called to mark an event happening. The label must + /// be a C string (null terminated). + fn event_marker(&self, label: &CStr); + /// Called with a duration to indicate a text marker that just ended. Text /// markers allow different types of entries to be recorded on the same row /// in the timeline, by adding labels to the entry. @@ -123,6 +127,15 @@ pub fn add_text_marker(label: &CStr, text: &str, duration: Duration) { } } +/// Records a marker of the given duration that just ended. +pub fn add_event_marker(label: &CStr) { + unsafe { + if let Some(ref hooks) = PROFILER_HOOKS { + hooks.event_marker(label); + } + } +} + /// Returns true if the current thread is being profiled. pub fn thread_is_being_profiled() -> bool { unsafe { diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index dc017c0d1c..1f40e5218f 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -78,7 +78,7 @@ use crate::picture::{RecordedDirtyRegion, tile_cache_sizes, ResolvedSurfaceTextu use crate::prim_store::DeferredResolve; use crate::profiler::{BackendProfileCounters, FrameProfileCounters, TimeProfileCounter, GpuProfileTag, RendererProfileCounters, RendererProfileTimers}; -use crate::profiler::{Profiler, ChangeIndicator, ProfileStyle}; +use crate::profiler::{Profiler, ChangeIndicator, ProfileStyle, add_event_marker}; use crate::device::query::{GpuProfiler, GpuDebugMethod}; use rayon::{ThreadPool, ThreadPoolBuilder}; use crate::record::ApiRecordingReceiver; @@ -96,6 +96,7 @@ use crate::render_target::{RenderTarget, TextureCacheRenderTarget, RenderTargetL use crate::render_target::{RenderTargetKind, BlitJob, BlitJobSource}; use crate::render_task_graph::RenderPassKind; use crate::util::drain_filter; +use crate::c_str; use std; use std::cmp; @@ -3581,6 +3582,12 @@ impl Renderer { upload_time.profile(|| { for update_list in pending_texture_updates.drain(..) { for allocation in update_list.allocations { + match allocation.kind { + TextureCacheAllocationKind::Alloc(_) => add_event_marker(c_str!("TextureCacheAlloc")), + TextureCacheAllocationKind::Realloc(_) => add_event_marker(c_str!("TextureCacheRealloc")), + TextureCacheAllocationKind::Reset(_) => add_event_marker(c_str!("TextureCacheReset")), + TextureCacheAllocationKind::Free => add_event_marker(c_str!("TextureCacheFree")), + }; let old = match allocation.kind { TextureCacheAllocationKind::Alloc(ref info) | TextureCacheAllocationKind::Realloc(ref info) | diff --git a/webrender/src/util.rs b/webrender/src/util.rs index 97fa01258b..cefbfc1080 100644 --- a/webrender/src/util.rs +++ b/webrender/src/util.rs @@ -1178,3 +1178,13 @@ pub fn round_up_to_multiple(val: usize, mul: NonZeroUsize) -> usize { } } + +#[macro_export] +macro_rules! c_str { + ($lit:expr) => { + unsafe { + std::ffi::CStr::from_ptr(concat!($lit, "\0").as_ptr() + as *const std::os::raw::c_char) + } + } +}