<!-- Please describe your changes on the following line: --> Implements feature #19223 --- <!-- 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 #19223 (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. --> WIP. @jdm - this is the new profiler : "Blocked at IPC Receive" Should I dig through all the calls to `ipc::channel` and replace them with this profiled `IpcReceiver`?  Source-Repo: https://github.com/servo/servo Source-Revision: f467bdce1ba95e950b01f59ba284873137bca5d5
46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use bincode;
|
|
use ipc_channel::ipc;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::io::Error;
|
|
use time;
|
|
use time::ProfilerCategory;
|
|
use time::ProfilerChan;
|
|
|
|
pub struct IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
|
|
ipc_receiver: ipc::IpcReceiver<T>,
|
|
time_profile_chan: ProfilerChan,
|
|
}
|
|
|
|
impl<T> IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
|
|
pub fn recv(&self) -> Result<T, bincode::Error> {
|
|
time::profile(
|
|
ProfilerCategory::IpcReceiver,
|
|
None,
|
|
self.time_profile_chan.clone(),
|
|
move || self.ipc_receiver.recv(),
|
|
)
|
|
}
|
|
|
|
pub fn try_recv(&self) -> Result<T, bincode::Error> {
|
|
self.ipc_receiver.try_recv()
|
|
}
|
|
|
|
pub fn to_opaque(self) -> ipc::OpaqueIpcReceiver {
|
|
self.ipc_receiver.to_opaque()
|
|
}
|
|
}
|
|
|
|
pub fn channel<T>(time_profile_chan: ProfilerChan) -> Result<(ipc::IpcSender<T>, IpcReceiver<T>), Error>
|
|
where T: for<'de> Deserialize<'de> + Serialize, {
|
|
let (ipc_sender, ipc_receiver) = ipc::channel()?;
|
|
let profiled_ipc_receiver = IpcReceiver {
|
|
ipc_receiver,
|
|
time_profile_chan,
|
|
};
|
|
Ok((ipc_sender, profiled_ipc_receiver))
|
|
}
|