Remove support for energy profiling

This commit is contained in:
Simon Sapin 2020-06-04 13:54:09 +02:00
parent d4f1f4641d
commit 0abe90647f
15 changed files with 8 additions and 215 deletions

View file

@ -10,13 +10,8 @@ publish = false
name = "profile_traits"
path = "lib.rs"
[features]
energy-profiling = ["energy-monitor", "energymon"]
[dependencies]
crossbeam-channel = "0.4"
energy-monitor = { version = "0.2.0", optional = true }
energymon = { git = "https://github.com/energymon/energymon-rust.git", optional = true }
ipc-channel = "0.14"
log = "0.4"
serde = "1.0"

View file

@ -1,62 +0,0 @@
/* 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 https://mozilla.org/MPL/2.0/. */
#[cfg(feature = "energy-profiling")]
pub fn read_energy_uj() -> u64 {
energymon::read_energy_uj()
}
#[cfg(not(feature = "energy-profiling"))]
pub fn read_energy_uj() -> u64 {
0
}
#[cfg(feature = "energy-profiling")]
pub fn energy_interval_ms() -> u32 {
energymon::get_min_interval_ms()
}
#[cfg(not(feature = "energy-profiling"))]
pub fn energy_interval_ms() -> u32 {
1000
}
#[cfg(feature = "energy-profiling")]
mod energymon {
extern crate energy_monitor;
extern crate energymon;
use self::energy_monitor::EnergyMonitor;
use self::energymon::EnergyMon;
use std::sync::{Once, ONCE_INIT};
static mut EM: Option<*mut EnergyMon> = None;
fn init() {
// can't use lazy_static macro for EM (no Sync trait for EnergyMon)
static ONCE: Once = ONCE_INIT;
ONCE.call_once(|| {
if let Ok(em) = EnergyMon::new() {
println!("Started energy monitoring from: {}", em.source());
unsafe {
EM = Some(Box::into_raw(Box::new(em)));
}
}
});
}
/// Read energy from the energy monitor, otherwise return 0.
pub fn read_energy_uj() -> u64 {
init();
unsafe {
// EnergyMon implementations of EnergyMonitor always return a value
EM.map_or(0, |em| (*em).read_uj().unwrap())
}
}
pub fn get_min_interval_ms() -> u32 {
init();
unsafe { EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32) }
}
}

View file

@ -13,8 +13,6 @@ extern crate log;
#[macro_use]
extern crate serde;
#[allow(unsafe_code)]
pub mod energy;
pub mod ipc;
pub mod mem;
pub mod time;

View file

@ -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 https://mozilla.org/MPL/2.0/. */
use crate::energy::read_energy_uj;
use ipc_channel::ipc::IpcSender;
use servo_config::opts;
use time::precise_time_ns;
@ -34,11 +33,7 @@ pub enum ProfilerData {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ProfilerMsg {
/// Normal message used for reporting time
Time(
(ProfilerCategory, Option<TimerMetadata>),
(u64, u64),
(u64, u64),
),
Time((ProfilerCategory, Option<TimerMetadata>), (u64, u64)),
/// Message used to get time spend entries for a particular ProfilerBuckets (in nanoseconds)
Get(
(ProfilerCategory, Option<TimerMetadata>),
@ -142,26 +137,16 @@ where
if opts::get().signpost {
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
}
let start_energy = read_energy_uj();
let start_time = precise_time_ns();
let val = callback();
let end_time = precise_time_ns();
let end_energy = read_energy_uj();
if opts::get().signpost {
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);
val
}
@ -171,12 +156,6 @@ pub fn send_profile_data(
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),
));
profiler_chan.send(ProfilerMsg::Time((category, meta), (start_time, end_time)));
}