diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-09-21 08:52:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-21 08:52:01 -0400 |
commit | 2671a1c064bf33d68fa96ff7f6f34123434fa052 (patch) | |
tree | 92837004545b43f3e142cb0574988a04a7b6938e | |
parent | f313847b6b7f9b121145a2df878e357e26c19948 (diff) | |
parent | 3e8f7fcefdfb1b61b547db1dea7273b44e36203c (diff) | |
download | servo-2671a1c064bf33d68fa96ff7f6f34123434fa052.tar.gz servo-2671a1c064bf33d68fa96ff7f6f34123434fa052.zip |
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 -->
-rw-r--r-- | components/profile/time.rs | 1 | ||||
-rw-r--r-- | components/profile_traits/ipc.rs | 30 | ||||
-rw-r--r-- | components/profile_traits/time.rs | 1 | ||||
-rw-r--r-- | tests/unit/profile/time.rs | 23 |
4 files changed, 55 insertions, 0 deletions
diff --git a/components/profile/time.rs b/components/profile/time.rs index fd09ca8cd8e..780a6e9da2f 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -151,6 +151,7 @@ impl Formattable for ProfilerCategory { ProfilerCategory::TimeToFirstContentfulPaint => "Time To First Contentful Paint", ProfilerCategory::TimeToInteractive => "Time to Interactive", ProfilerCategory::IpcReceiver => "Blocked at IPC Receive", + ProfilerCategory::IpcBytesReceiver => "Blocked at IPC Bytes Receive", ProfilerCategory::ApplicationHeartbeat => "Application Heartbeat", }; format!("{}{}", padding, name) diff --git a/components/profile_traits/ipc.rs b/components/profile_traits/ipc.rs index cd4553ea8bc..7436ef5d5f1 100644 --- a/components/profile_traits/ipc.rs +++ b/components/profile_traits/ipc.rs @@ -53,3 +53,33 @@ where }; Ok((ipc_sender, profiled_ipc_receiver)) } + +pub struct IpcBytesReceiver +{ + ipc_bytes_receiver: ipc::IpcBytesReceiver, + time_profile_chan: ProfilerChan, +} + +impl IpcBytesReceiver +{ + pub fn recv(&self) -> Result<Vec<u8>, bincode::Error> { + time::profile( + ProfilerCategory::IpcBytesReceiver, + None, + self.time_profile_chan.clone(), + move || self.ipc_bytes_receiver.recv(), + ) + } +} + +pub fn bytes_channel( + time_profile_chan: ProfilerChan, +) -> Result<(ipc::IpcBytesSender, IpcBytesReceiver), Error> +{ + let (ipc_bytes_sender, ipc_bytes_receiver) = ipc::bytes_channel()?; + let profiled_ipc_bytes_receiver = IpcBytesReceiver { + ipc_bytes_receiver, + time_profile_chan, + }; + Ok((ipc_bytes_sender, profiled_ipc_bytes_receiver)) +} diff --git a/components/profile_traits/time.rs b/components/profile_traits/time.rs index f905348a882..9f3c41740ff 100644 --- a/components/profile_traits/time.rs +++ b/components/profile_traits/time.rs @@ -110,6 +110,7 @@ pub enum ProfilerCategory { TimeToFirstContentfulPaint = 0x81, TimeToInteractive = 0x82, IpcReceiver = 0x83, + IpcBytesReceiver = 0x84, ApplicationHeartbeat = 0x90, } diff --git a/tests/unit/profile/time.rs b/tests/unit/profile/time.rs index 19d3a19ee5d..0cd41086065 100644 --- a/tests/unit/profile/time.rs +++ b/tests/unit/profile/time.rs @@ -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] |