Auto merge of #21771 - sumit0190:profile_receiver, r=jdm

Add support for IpcBytesReceiver in profile_traits::ipc - #21704

<!-- Please describe your changes on the following line: -->
Added support for IpcBytesReceiver in profile_trails::ipc. Added a new test-point that exercises bytes_channel().

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #21704 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes

<!-- 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/21771)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-21 08:52:01 -04:00 committed by GitHub
commit 2671a1c064
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 0 deletions

View file

@ -64,6 +64,29 @@ fn channel_profiler_test() {
}
#[test]
fn bytes_channel_profiler_test() {
let chan = time::Profiler::create(&Some(OutputOptions::Stdout(5.0)), None);
let (profiled_sender, profiled_receiver) = ProfiledIpc::bytes_channel(chan.clone()).unwrap();
thread::spawn(move || {
thread::sleep(Duration::from_secs(2));
profiled_sender.send(&[1, 2, 3]).unwrap();
});
let val_profile_receiver = profiled_receiver.recv().unwrap();
assert_eq!(val_profile_receiver, [1, 2, 3]);
let (sender, receiver) = ipc::channel().unwrap();
chan.send(ProfilerMsg::Get((ProfilerCategory::IpcBytesReceiver, 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]