diff --git a/components/profile_traits/energy.rs b/components/profile_traits/energy.rs index 1e34645b180a..bbd427ca834f 100644 --- a/components/profile_traits/energy.rs +++ b/components/profile_traits/energy.rs @@ -2,7 +2,6 @@ * 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/. */ - #[cfg(feature = "energy-profiling")] pub fn read_energy_uj() -> u64 { energymon::read_energy_uj() @@ -33,7 +32,6 @@ mod energymon { use std::mem; use std::sync::{Once, ONCE_INIT}; - static mut EM: Option<*mut EnergyMon> = None; fn init() { @@ -60,9 +58,7 @@ mod energymon { pub fn get_min_interval_ms() -> u32 { init(); - unsafe { - EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32) - } + unsafe { EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32) } } } diff --git a/components/profile_traits/ipc.rs b/components/profile_traits/ipc.rs index fe64d54ef07e..cd4553ea8bce 100644 --- a/components/profile_traits/ipc.rs +++ b/components/profile_traits/ipc.rs @@ -10,12 +10,18 @@ use time; use time::ProfilerCategory; use time::ProfilerChan; -pub struct IpcReceiver where T: for<'de> Deserialize<'de> + Serialize { +pub struct IpcReceiver +where + T: for<'de> Deserialize<'de> + Serialize, +{ ipc_receiver: ipc::IpcReceiver, time_profile_chan: ProfilerChan, } -impl IpcReceiver where T: for<'de> Deserialize<'de> + Serialize { +impl IpcReceiver +where + T: for<'de> Deserialize<'de> + Serialize, +{ pub fn recv(&self) -> Result { time::profile( ProfilerCategory::IpcReceiver, @@ -34,8 +40,12 @@ impl IpcReceiver where T: for<'de> Deserialize<'de> + Serialize { } } -pub fn channel(time_profile_chan: ProfilerChan) -> Result<(ipc::IpcSender, IpcReceiver), Error> - where T: for<'de> Deserialize<'de> + Serialize, { +pub fn channel( + time_profile_chan: ProfilerChan, +) -> Result<(ipc::IpcSender, IpcReceiver), Error> +where + T: for<'de> Deserialize<'de> + Serialize, +{ let (ipc_sender, ipc_receiver) = ipc::channel()?; let profiled_ipc_receiver = IpcReceiver { ipc_receiver, diff --git a/components/profile_traits/lib.rs b/components/profile_traits/lib.rs index 029e59a3241d..e70d0b7ac401 100644 --- a/components/profile_traits/lib.rs +++ b/components/profile_traits/lib.rs @@ -12,7 +12,8 @@ extern crate bincode; extern crate ipc_channel; #[macro_use] extern crate log; -#[macro_use] extern crate serde; +#[macro_use] +extern crate serde; extern crate servo_config; extern crate signpost; diff --git a/components/profile_traits/mem.rs b/components/profile_traits/mem.rs index b0df9ac7db71..8e4d756884b2 100644 --- a/components/profile_traits/mem.rs +++ b/components/profile_traits/mem.rs @@ -21,15 +21,24 @@ pub trait OpaqueSender { impl OpaqueSender for Sender { fn send(&self, message: T) { 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 OpaqueSender for IpcSender where T: serde::Serialize { +impl OpaqueSender for IpcSender +where + T: serde::Serialize, +{ fn send(&self, message: T) { 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. - pub fn run_with_memory_reporting(&self, f: F, - reporter_name: String, - channel_for_reporter: C, - msg: M) - where F: FnOnce(), - M: Fn(ReportsChan) -> T + Send + 'static, - T: Send + 'static, - C: OpaqueSender + Send + 'static + pub fn run_with_memory_reporting( + &self, + f: F, + reporter_name: String, + channel_for_reporter: C, + msg: M, + ) where + F: FnOnce(), + M: Fn(ReportsChan) -> T + Send + 'static, + T: Send + 'static, + C: OpaqueSender + Send + 'static, { // Register the memory reporter. let (reporter_sender, reporter_receiver) = ipc::channel().unwrap(); - ROUTER.add_route(reporter_receiver.to_opaque(), Box::new(move |message| { - // Just injects an appropriate event into the paint thread's queue. - let request: ReporterRequest = message.to().unwrap(); - channel_for_reporter.send(msg(request.reports_channel)); - })); - self.send(ProfilerMsg::RegisterReporter(reporter_name.clone(), - Reporter(reporter_sender))); + ROUTER.add_route( + reporter_receiver.to_opaque(), + Box::new(move |message| { + // Just injects an appropriate event into the paint thread's queue. + let request: ReporterRequest = message.to().unwrap(); + channel_for_reporter.send(msg(request.reports_channel)); + }), + ); + self.send(ProfilerMsg::RegisterReporter( + reporter_name.clone(), + Reporter(reporter_sender), + )); f(); @@ -154,9 +171,10 @@ pub struct Reporter(pub IpcSender); impl Reporter { /// Collect one or more memory reports. Returns true on success, and false on failure. pub fn collect_reports(&self, reports_chan: ReportsChan) { - self.0.send(ReporterRequest { - reports_channel: reports_chan, - }).unwrap() + self.0 + .send(ReporterRequest { + reports_channel: reports_chan, + }).unwrap() } } @@ -188,4 +206,3 @@ pub enum ProfilerMsg { /// Tells the memory profiler to shut down. Exit, } - diff --git a/components/profile_traits/time.rs b/components/profile_traits/time.rs index 2c297003b9ec..f905348a882d 100644 --- a/components/profile_traits/time.rs +++ b/components/profile_traits/time.rs @@ -37,9 +37,16 @@ pub enum ProfilerData { #[derive(Clone, Deserialize, Serialize)] pub enum ProfilerMsg { /// Normal message used for reporting time - Time((ProfilerCategory, Option), (u64, u64), (u64, u64)), + Time( + (ProfilerCategory, Option), + (u64, u64), + (u64, u64), + ), /// Message used to get time spend entries for a particular ProfilerBuckets (in nanoseconds) - Get((ProfilerCategory, Option), IpcSender), + Get( + (ProfilerCategory, Option), + IpcSender, + ), /// Message used to force print the profiling metrics Print, /// Tells the profiler to shut down. @@ -118,12 +125,14 @@ pub enum TimerMetadataReflowType { FirstReflow, } -pub fn profile(category: ProfilerCategory, - meta: Option, - profiler_chan: ProfilerChan, - callback: F) - -> T - where F: FnOnce() -> T, +pub fn profile( + category: ProfilerCategory, + meta: Option, + profiler_chan: ProfilerChan, + callback: F, +) -> T +where + F: FnOnce() -> T, { if opts::get().signpost { signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]); @@ -139,24 +148,30 @@ pub fn profile(category: ProfilerCategory, signpost::end(category as u32, &[0, 0, 0, (category as usize) >> 4]); } - send_profile_data(category, - meta, - &profiler_chan, - start_time, - end_time, - start_energy, - end_energy); + send_profile_data( + category, + meta, + &profiler_chan, + start_time, + end_time, + start_energy, + end_energy, + ); val } -pub fn send_profile_data(category: ProfilerCategory, - meta: Option, - profiler_chan: &ProfilerChan, - start_time: u64, - end_time: u64, - start_energy: u64, - end_energy: u64) { - profiler_chan.send(ProfilerMsg::Time((category, meta), - (start_time, end_time), - (start_energy, end_energy))); +pub fn send_profile_data( + category: ProfilerCategory, + meta: Option, + profiler_chan: &ProfilerChan, + start_time: u64, + end_time: u64, + start_energy: u64, + end_energy: u64, +) { + profiler_chan.send(ProfilerMsg::Time( + (category, meta), + (start_time, end_time), + (start_energy, end_energy), + )); }