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 -->
This commit is contained in:
bors-servo 2019-03-31 10:27:13 -04:00 committed by GitHub
commit 31c02614be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 18 deletions

View file

@ -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));
}
}
}

View file

@ -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();