Implements profiler for blocked recv

This commit is contained in:
Nakul Jindal 2018-02-26 09:07:08 -08:00
parent 563f0ec824
commit 7d4e2b11e9
27 changed files with 176 additions and 58 deletions

View file

@ -16,3 +16,5 @@ profile_traits = {path = "../../../components/profile_traits"}
# Work around https://github.com/alexcrichton/jemallocator/issues/19
servo_allocator = {path = "../../../components/allocator"}
servo_config = {path = "../../../components/config"}

View file

@ -8,5 +8,6 @@ extern crate ipc_channel;
extern crate profile;
extern crate profile_traits;
extern crate servo_allocator;
extern crate servo_config;
mod time;

View file

@ -4,7 +4,11 @@
use ipc_channel::ipc;
use profile::time;
use profile_traits::time::ProfilerMsg;
use profile_traits::ipc as ProfiledIpc;
use profile_traits::time::{ProfilerCategory, ProfilerData, ProfilerMsg};
use servo_config::opts::OutputOptions;
use std::thread;
use std::time::Duration;
#[test]
fn time_profiler_smoke_test() {
@ -37,6 +41,29 @@ fn time_profiler_stats_test() {
assert_eq!(13.2599, odd_max);
}
#[test]
fn channel_profiler_test() {
let chan = time::Profiler::create(&Some(OutputOptions::Stdout(5.0)), None);
let (profiled_sender, profiled_receiver) = ProfiledIpc::channel(chan.clone()).unwrap();
thread::spawn(move || {
thread::sleep(Duration::from_secs(2));
profiled_sender.send(43).unwrap();
});
let val_profile_receiver = profiled_receiver.recv().unwrap();
assert_eq!(val_profile_receiver, 43);
let (sender, receiver) = ipc::channel().unwrap();
chan.send(ProfilerMsg::Get((ProfilerCategory::IpcReceiver, None), sender.clone()));
match receiver.recv().unwrap() {
// asserts that the time spent in the sleeping thread is more than 1500 milliseconds
ProfilerData::Record(time_data) => assert!(time_data[0] > 1.5e3),
ProfilerData::NoRecords => assert!(false),
};
}
#[cfg(debug_assertions)]
#[test]
#[should_panic]