mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
format components/profile_traits
This commit is contained in:
parent
6cb39fad47
commit
ce9231c471
5 changed files with 96 additions and 57 deletions
|
@ -2,7 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "energy-profiling")]
|
#[cfg(feature = "energy-profiling")]
|
||||||
pub fn read_energy_uj() -> u64 {
|
pub fn read_energy_uj() -> u64 {
|
||||||
energymon::read_energy_uj()
|
energymon::read_energy_uj()
|
||||||
|
@ -33,7 +32,6 @@ mod energymon {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::{Once, ONCE_INIT};
|
use std::sync::{Once, ONCE_INIT};
|
||||||
|
|
||||||
|
|
||||||
static mut EM: Option<*mut EnergyMon> = None;
|
static mut EM: Option<*mut EnergyMon> = None;
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
|
@ -60,9 +58,7 @@ mod energymon {
|
||||||
|
|
||||||
pub fn get_min_interval_ms() -> u32 {
|
pub fn get_min_interval_ms() -> u32 {
|
||||||
init();
|
init();
|
||||||
unsafe {
|
unsafe { EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32) }
|
||||||
EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,18 @@ use time;
|
||||||
use time::ProfilerCategory;
|
use time::ProfilerCategory;
|
||||||
use time::ProfilerChan;
|
use time::ProfilerChan;
|
||||||
|
|
||||||
pub struct IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
|
pub struct IpcReceiver<T>
|
||||||
|
where
|
||||||
|
T: for<'de> Deserialize<'de> + Serialize,
|
||||||
|
{
|
||||||
ipc_receiver: ipc::IpcReceiver<T>,
|
ipc_receiver: ipc::IpcReceiver<T>,
|
||||||
time_profile_chan: ProfilerChan,
|
time_profile_chan: ProfilerChan,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
|
impl<T> IpcReceiver<T>
|
||||||
|
where
|
||||||
|
T: for<'de> Deserialize<'de> + Serialize,
|
||||||
|
{
|
||||||
pub fn recv(&self) -> Result<T, bincode::Error> {
|
pub fn recv(&self) -> Result<T, bincode::Error> {
|
||||||
time::profile(
|
time::profile(
|
||||||
ProfilerCategory::IpcReceiver,
|
ProfilerCategory::IpcReceiver,
|
||||||
|
@ -34,8 +40,12 @@ impl<T> IpcReceiver<T> where T: for<'de> Deserialize<'de> + Serialize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channel<T>(time_profile_chan: ProfilerChan) -> Result<(ipc::IpcSender<T>, IpcReceiver<T>), Error>
|
pub fn channel<T>(
|
||||||
where T: for<'de> Deserialize<'de> + Serialize, {
|
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 (ipc_sender, ipc_receiver) = ipc::channel()?;
|
||||||
let profiled_ipc_receiver = IpcReceiver {
|
let profiled_ipc_receiver = IpcReceiver {
|
||||||
ipc_receiver,
|
ipc_receiver,
|
||||||
|
|
|
@ -12,7 +12,8 @@ extern crate bincode;
|
||||||
extern crate ipc_channel;
|
extern crate ipc_channel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use]
|
||||||
|
extern crate serde;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate signpost;
|
extern crate signpost;
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,24 @@ pub trait OpaqueSender<T> {
|
||||||
impl<T> OpaqueSender<T> for Sender<T> {
|
impl<T> OpaqueSender<T> for Sender<T> {
|
||||||
fn send(&self, message: T) {
|
fn send(&self, message: T) {
|
||||||
if let Err(e) = Sender::send(self, message) {
|
if let Err(e) = Sender::send(self, message) {
|
||||||
warn!("Error communicating with the target thread from the profiler: {}", e);
|
warn!(
|
||||||
|
"Error communicating with the target thread from the profiler: {}",
|
||||||
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> OpaqueSender<T> for IpcSender<T> where T: serde::Serialize {
|
impl<T> OpaqueSender<T> for IpcSender<T>
|
||||||
|
where
|
||||||
|
T: serde::Serialize,
|
||||||
|
{
|
||||||
fn send(&self, message: T) {
|
fn send(&self, message: T) {
|
||||||
if let Err(e) = IpcSender::send(self, message) {
|
if let Err(e) = IpcSender::send(self, message) {
|
||||||
warn!("Error communicating with the target thread from the profiler: {}", e);
|
warn!(
|
||||||
|
"Error communicating with the target thread from the profiler: {}",
|
||||||
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,24 +59,32 @@ impl ProfilerChan {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs `f()` with memory profiling.
|
/// Runs `f()` with memory profiling.
|
||||||
pub fn run_with_memory_reporting<F, M, T, C>(&self, f: F,
|
pub fn run_with_memory_reporting<F, M, T, C>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
reporter_name: String,
|
reporter_name: String,
|
||||||
channel_for_reporter: C,
|
channel_for_reporter: C,
|
||||||
msg: M)
|
msg: M,
|
||||||
where F: FnOnce(),
|
) where
|
||||||
|
F: FnOnce(),
|
||||||
M: Fn(ReportsChan) -> T + Send + 'static,
|
M: Fn(ReportsChan) -> T + Send + 'static,
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
C: OpaqueSender<T> + Send + 'static
|
C: OpaqueSender<T> + Send + 'static,
|
||||||
{
|
{
|
||||||
// Register the memory reporter.
|
// Register the memory reporter.
|
||||||
let (reporter_sender, reporter_receiver) = ipc::channel().unwrap();
|
let (reporter_sender, reporter_receiver) = ipc::channel().unwrap();
|
||||||
ROUTER.add_route(reporter_receiver.to_opaque(), Box::new(move |message| {
|
ROUTER.add_route(
|
||||||
|
reporter_receiver.to_opaque(),
|
||||||
|
Box::new(move |message| {
|
||||||
// Just injects an appropriate event into the paint thread's queue.
|
// Just injects an appropriate event into the paint thread's queue.
|
||||||
let request: ReporterRequest = message.to().unwrap();
|
let request: ReporterRequest = message.to().unwrap();
|
||||||
channel_for_reporter.send(msg(request.reports_channel));
|
channel_for_reporter.send(msg(request.reports_channel));
|
||||||
}));
|
}),
|
||||||
self.send(ProfilerMsg::RegisterReporter(reporter_name.clone(),
|
);
|
||||||
Reporter(reporter_sender)));
|
self.send(ProfilerMsg::RegisterReporter(
|
||||||
|
reporter_name.clone(),
|
||||||
|
Reporter(reporter_sender),
|
||||||
|
));
|
||||||
|
|
||||||
f();
|
f();
|
||||||
|
|
||||||
|
@ -154,7 +171,8 @@ pub struct Reporter(pub IpcSender<ReporterRequest>);
|
||||||
impl Reporter {
|
impl Reporter {
|
||||||
/// Collect one or more memory reports. Returns true on success, and false on failure.
|
/// Collect one or more memory reports. Returns true on success, and false on failure.
|
||||||
pub fn collect_reports(&self, reports_chan: ReportsChan) {
|
pub fn collect_reports(&self, reports_chan: ReportsChan) {
|
||||||
self.0.send(ReporterRequest {
|
self.0
|
||||||
|
.send(ReporterRequest {
|
||||||
reports_channel: reports_chan,
|
reports_channel: reports_chan,
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -188,4 +206,3 @@ pub enum ProfilerMsg {
|
||||||
/// Tells the memory profiler to shut down.
|
/// Tells the memory profiler to shut down.
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,16 @@ pub enum ProfilerData {
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub enum ProfilerMsg {
|
pub enum ProfilerMsg {
|
||||||
/// Normal message used for reporting time
|
/// Normal message used for reporting time
|
||||||
Time((ProfilerCategory, Option<TimerMetadata>), (u64, u64), (u64, u64)),
|
Time(
|
||||||
|
(ProfilerCategory, Option<TimerMetadata>),
|
||||||
|
(u64, u64),
|
||||||
|
(u64, u64),
|
||||||
|
),
|
||||||
/// Message used to get time spend entries for a particular ProfilerBuckets (in nanoseconds)
|
/// Message used to get time spend entries for a particular ProfilerBuckets (in nanoseconds)
|
||||||
Get((ProfilerCategory, Option<TimerMetadata>), IpcSender<ProfilerData>),
|
Get(
|
||||||
|
(ProfilerCategory, Option<TimerMetadata>),
|
||||||
|
IpcSender<ProfilerData>,
|
||||||
|
),
|
||||||
/// Message used to force print the profiling metrics
|
/// Message used to force print the profiling metrics
|
||||||
Print,
|
Print,
|
||||||
/// Tells the profiler to shut down.
|
/// Tells the profiler to shut down.
|
||||||
|
@ -118,12 +125,14 @@ pub enum TimerMetadataReflowType {
|
||||||
FirstReflow,
|
FirstReflow,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn profile<T, F>(category: ProfilerCategory,
|
pub fn profile<T, F>(
|
||||||
|
category: ProfilerCategory,
|
||||||
meta: Option<TimerMetadata>,
|
meta: Option<TimerMetadata>,
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
callback: F)
|
callback: F,
|
||||||
-> T
|
) -> T
|
||||||
where F: FnOnce() -> T,
|
where
|
||||||
|
F: FnOnce() -> T,
|
||||||
{
|
{
|
||||||
if opts::get().signpost {
|
if opts::get().signpost {
|
||||||
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
||||||
|
@ -139,24 +148,30 @@ pub fn profile<T, F>(category: ProfilerCategory,
|
||||||
signpost::end(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
signpost::end(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
send_profile_data(category,
|
send_profile_data(
|
||||||
|
category,
|
||||||
meta,
|
meta,
|
||||||
&profiler_chan,
|
&profiler_chan,
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
start_energy,
|
start_energy,
|
||||||
end_energy);
|
end_energy,
|
||||||
|
);
|
||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_profile_data(category: ProfilerCategory,
|
pub fn send_profile_data(
|
||||||
|
category: ProfilerCategory,
|
||||||
meta: Option<TimerMetadata>,
|
meta: Option<TimerMetadata>,
|
||||||
profiler_chan: &ProfilerChan,
|
profiler_chan: &ProfilerChan,
|
||||||
start_time: u64,
|
start_time: u64,
|
||||||
end_time: u64,
|
end_time: u64,
|
||||||
start_energy: u64,
|
start_energy: u64,
|
||||||
end_energy: u64) {
|
end_energy: u64,
|
||||||
profiler_chan.send(ProfilerMsg::Time((category, meta),
|
) {
|
||||||
|
profiler_chan.send(ProfilerMsg::Time(
|
||||||
|
(category, meta),
|
||||||
(start_time, end_time),
|
(start_time, end_time),
|
||||||
(start_energy, end_energy)));
|
(start_energy, end_energy),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue