mirror of
https://github.com/servo/servo.git
synced 2025-08-15 10:25:32 +01:00
Implements profiler for blocked recv
This commit is contained in:
parent
563f0ec824
commit
7d4e2b11e9
27 changed files with 176 additions and 58 deletions
|
@ -13,6 +13,7 @@ path = "lib.rs"
|
|||
energy-profiling = ["energymon", "energy-monitor"]
|
||||
|
||||
[dependencies]
|
||||
bincode = "1"
|
||||
energy-monitor = {version = "0.2.0", optional = true}
|
||||
energymon = {git = "https://github.com/energymon/energymon-rust.git", optional = true}
|
||||
ipc-channel = "0.10"
|
||||
|
|
45
components/profile_traits/ipc.rs
Normal file
45
components/profile_traits/ipc.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* 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))
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#![deny(unsafe_code)]
|
||||
|
||||
extern crate bincode;
|
||||
extern crate ipc_channel;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -17,5 +18,6 @@ extern crate signpost;
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub mod energy;
|
||||
pub mod ipc;
|
||||
pub mod mem;
|
||||
pub mod time;
|
||||
|
|
|
@ -28,10 +28,18 @@ impl ProfilerChan {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub enum ProfilerData {
|
||||
NoRecords,
|
||||
Record(Vec<f64>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub enum ProfilerMsg {
|
||||
/// Normal message used for reporting time
|
||||
Time((ProfilerCategory, Option<TimerMetadata>), (u64, u64), (u64, u64)),
|
||||
/// Message used to get time spend entries for a particular ProfilerBuckets (in nanoseconds)
|
||||
Get((ProfilerCategory, Option<TimerMetadata>), IpcSender<ProfilerData>),
|
||||
/// Message used to force print the profiling metrics
|
||||
Print,
|
||||
/// Tells the profiler to shut down.
|
||||
|
@ -94,6 +102,7 @@ pub enum ProfilerCategory {
|
|||
TimeToFirstPaint = 0x80,
|
||||
TimeToFirstContentfulPaint = 0x81,
|
||||
TimeToInteractive = 0x82,
|
||||
IpcReceiver = 0x83,
|
||||
ApplicationHeartbeat = 0x90,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue