Skip to content
Permalink
Browse files

bound sampler buffer

  • Loading branch information...
gterzian committed Mar 31, 2019
1 parent fcd6beb commit 0780298b80fac803e9f57f8f839bbe4b3c36c388
@@ -12,7 +12,7 @@ use msg::constellation_msg::{
};
use msg::constellation_msg::{HangAlert, HangAnnotation, HangMonitorAlert, SamplerControlMsg};
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::{HashMap, VecDeque};
use std::thread;
use std::time::{Duration, Instant};

@@ -153,10 +153,11 @@ pub struct BackgroundHangMonitorWorker {
port: Receiver<(MonitoredComponentId, MonitoredComponentMsg)>,
control_port: Receiver<SamplerControlMsg>,
sampling_duration: Option<Duration>,
sampling_max_duration: Option<Duration>,
last_sample: Instant,
creation: Instant,
sampling_baseline: Instant,
samples: Vec<Sample>,
samples: VecDeque<Sample>,
}

impl BackgroundHangMonitorWorker {
@@ -173,10 +174,11 @@ impl BackgroundHangMonitorWorker {
port,
control_port,
sampling_duration: None,
sampling_max_duration: None,
last_sample: Instant::now(),
sampling_baseline: Instant::now(),
creation: Instant::now(),
samples: vec![],
samples: Default::default(),
}
}

@@ -239,9 +241,10 @@ impl BackgroundHangMonitorWorker {
},
recv(self.control_port) -> event => {
match event {
Ok(SamplerControlMsg::Enable(rate)) => {
Ok(SamplerControlMsg::Enable(rate, max_duration)) => {
println!("Enabling profiler.");
self.sampling_duration = Some(rate);
self.sampling_max_duration = Some(max_duration);
self.sampling_baseline = Instant::now();
None
}
@@ -381,9 +384,15 @@ impl BackgroundHangMonitorWorker {
for (component_id, monitored) in self.monitored_components.iter_mut() {
let instant = Instant::now();
if let Ok(stack) = monitored.sampler.suspend_and_sample_thread() {
// TODO: support a bounded buffer that discards older samples.
if self.sampling_baseline.elapsed() >
self.sampling_max_duration
.expect("Max duration has been set")
{
// Buffer is full, start discarding older samples.
self.samples.pop_front();
}
self.samples
.push(Sample(component_id.clone(), instant, stack));
.push_back(Sample(component_id.clone(), instant, stack));
}
}
}
@@ -30,11 +30,15 @@ fn test_sampler() {
);

const RATE: u64 = 10;
const MAX_DURATION: u64 = 10;
sampler_sender
.send(SamplerControlMsg::Enable(Duration::from_millis(RATE)))
.send(SamplerControlMsg::Enable(
Duration::from_millis(RATE),
Duration::from_secs(MAX_DURATION),
))
.unwrap();

thread::sleep(Duration::from_millis(30));
thread::sleep(Duration::from_millis(100));

sampler_sender.send(SamplerControlMsg::Disable).unwrap();

@@ -95,8 +95,8 @@ pub enum WindowEvent {
ToggleWebRenderDebug(WebRenderDebugOption),
/// Capture current WebRender
CaptureWebRender,
/// Toggle sampling profiler with the given sampling rate
ToggleSamplingProfiler(Duration),
/// Toggle sampling profiler with the given sampling rate and max duration.
ToggleSamplingProfiler(Duration, Duration),
}

impl Debug for WindowEvent {
@@ -1216,9 +1216,9 @@ where
self.forward_event(destination_pipeline_id, event);
},
FromCompositorMsg::SetCursor(cursor) => self.handle_set_cursor_msg(cursor),
FromCompositorMsg::EnableProfiler(rate) => {
FromCompositorMsg::EnableProfiler(rate, max_duration) => {
for chan in &self.sampling_profiler_control {
if let Err(e) = chan.send(SamplerControlMsg::Enable(rate)) {
if let Err(e) = chan.send(SamplerControlMsg::Enable(rate, max_duration)) {
warn!("error communicating with sampling profiler: {}", e);
}
}
@@ -494,6 +494,7 @@ pub trait BackgroundHangMonitor {
/// Messages to control the sampling profiler.
#[derive(Deserialize, Serialize)]
pub enum SamplerControlMsg {
Enable(Duration),
/// Enable the sampler, with a given sampling rate and max total sampling duration.
Enable(Duration, Duration),
Disable,
}
@@ -778,8 +778,8 @@ pub enum ConstellationMsg {
ForwardEvent(PipelineId, CompositorEvent),
/// Requesting a change to the onscreen cursor.
SetCursor(Cursor),
/// Enable the sampling profiler.
EnableProfiler(Duration),
/// Enable the sampling profiler, with a given sampling rate and max total sampling duration.
EnableProfiler(Duration, Duration),
/// Disable the sampling profiler.
DisableProfiler,
}
@@ -408,10 +408,10 @@ where
}
},

WindowEvent::ToggleSamplingProfiler(rate) => {
WindowEvent::ToggleSamplingProfiler(rate, max_duration) => {
self.profiler_enabled = !self.profiler_enabled;
let msg = if self.profiler_enabled {
ConstellationMsg::EnableProfiler(rate)
ConstellationMsg::EnableProfiler(rate, max_duration)
} else {
ConstellationMsg::DisableProfiler
};
@@ -121,8 +121,12 @@ impl Browser {
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10);
let duration = env::var("SAMPLING_DURATION")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10);
self.event_queue.push(WindowEvent::ToggleSamplingProfiler(
Duration::from_millis(rate)));
Duration::from_millis(rate), Duration::from_secs(duration)));
})
.shortcut(Modifiers::CONTROL, Key::F9, || {
self.event_queue.push(WindowEvent::CaptureWebRender)

0 comments on commit 0780298

Please sign in to comment.
You can’t perform that action at this time.