aboutsummaryrefslogtreecommitdiffstats
path: root/components/background_hang_monitor
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-03-31 10:27:13 -0400
committerGitHub <noreply@github.com>2019-03-31 10:27:13 -0400
commit31c02614beb94207237865e58587f75a98b5c9b1 (patch)
treedd84b51594d4c86b166ed1eb48bbdc4fc7ecd49b /components/background_hang_monitor
parent14304b23a95c18a5c6cd688b206f0ee3e49bcebb (diff)
parent0780298b80fac803e9f57f8f839bbe4b3c36c388 (diff)
downloadservo-31c02614beb94207237865e58587f75a98b5c9b1.tar.gz
servo-31c02614beb94207237865e58587f75a98b5c9b1.zip
Auto merge of #23139 - gterzian:bounded_profiler_with_buffer_feedback, r=jdm
Bound sampler buffer, add length feedback message, fix intermittence in test <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #23109 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23139) <!-- Reviewable:end -->
Diffstat (limited to 'components/background_hang_monitor')
-rw-r--r--components/background_hang_monitor/background_hang_monitor.rs21
-rw-r--r--components/background_hang_monitor/tests/hang_monitor_tests.rs8
2 files changed, 21 insertions, 8 deletions
diff --git a/components/background_hang_monitor/background_hang_monitor.rs b/components/background_hang_monitor/background_hang_monitor.rs
index 904e9a7ebd6..5791401fcd7 100644
--- a/components/background_hang_monitor/background_hang_monitor.rs
+++ b/components/background_hang_monitor/background_hang_monitor.rs
@@ -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};
@@ -158,10 +158,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 {
@@ -178,10 +179,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(),
}
}
@@ -244,9 +246,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
}
@@ -386,9 +389,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));
}
}
}
diff --git a/components/background_hang_monitor/tests/hang_monitor_tests.rs b/components/background_hang_monitor/tests/hang_monitor_tests.rs
index 8bc0700fa2e..bc783a49709 100644
--- a/components/background_hang_monitor/tests/hang_monitor_tests.rs
+++ b/components/background_hang_monitor/tests/hang_monitor_tests.rs
@@ -40,11 +40,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();