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

45
Cargo.lock generated
View file

@ -1377,49 +1377,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "energy-monitor"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe872d0664f1cc60db36349af245d892ee67d3c8f78055df0ebc43271fd4e05c"
[[package]]
name = "energymon"
version = "0.3.0"
source = "git+https://github.com/energymon/energymon-rust.git#89daf8f37858eab96ad8eec7cc81accb17b2411e"
dependencies = [
"energy-monitor",
"energymon-default-sys",
"libc",
]
[[package]]
name = "energymon-builder"
version = "0.3.0"
source = "git+https://github.com/energymon/energymon-sys.git#f8d77ea2906b25f9c0fd358aa9d300a46dc3e97c"
dependencies = [
"cmake",
"pkg-config",
]
[[package]]
name = "energymon-default-sys"
version = "0.3.0"
source = "git+https://github.com/energymon/energymon-sys.git#f8d77ea2906b25f9c0fd358aa9d300a46dc3e97c"
dependencies = [
"energymon-builder",
"energymon-sys",
"libc",
]
[[package]]
name = "energymon-sys"
version = "0.3.0"
source = "git+https://github.com/energymon/energymon-sys.git#f8d77ea2906b25f9c0fd358aa9d300a46dc3e97c"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "enum-iterator" name = "enum-iterator"
version = "0.3.1" version = "0.3.1"
@ -4241,8 +4198,6 @@ name = "profile_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"energy-monitor",
"energymon",
"ipc-channel", "ipc-channel",
"log", "log",
"serde", "serde",

View file

@ -1456,8 +1456,6 @@ impl LayoutThread {
&self.time_profiler_chan, &self.time_profiler_chan,
0, 0,
text_shaping_time as u64, text_shaping_time as u64,
0,
0,
); );
// Retrieve the (possibly rebuilt) root flow. // Retrieve the (possibly rebuilt) root flow.

View file

@ -81,8 +81,6 @@ fn set_metric<U: ProgressiveWebMetric>(
&pwm.get_time_profiler_chan(), &pwm.get_time_profiler_chan(),
time, time,
time, time,
0,
0,
); );
// Print the metric to console if the print-pwm option was given. // Print the metric to console if the print-pwm option was given.

View file

@ -62,31 +62,3 @@ Time is measured in nanoseconds and energy is measured in microjoules.
`Work`, `Time`, and `Energy` also have `Global` and `Window` values which are the summed over the entire runtime and sliding window period, respectively. `Work`, `Time`, and `Energy` also have `Global` and `Window` values which are the summed over the entire runtime and sliding window period, respectively.
`Perf` (performance) and `Pwr` (power) have `Global`, `Window`, and `Instant` values as described above. `Perf` (performance) and `Pwr` (power) have `Global`, `Window`, and `Instant` values as described above.
# Energy Profiling
Energy monitoring is hardware and platform-specific, so it is only enabled with the `energy-profiling` feature.
To use energy profiling, you must have a compatible `energymon-default` implementation installed to your system as `energymon-default-static` when building Servo.
Otherwise a default dummy implementation is used.
The library is linked through a chain of dependencies:
* servo::profile_traits
* energymon - Rust abstractions
* energymon-default-sys - Rust bindings to `energymon-default.h`
* energymon-default-static: A statically linked C library installed to the system that implements `energymon.h` and `energymon-default.h`
For instructions on building existing native libraries, visit the [energymon project source](https://github.com/energymon/energymon).
You may also write your own implementation of `energymon.h` and `energymon-default.h` and install it as `energymon-default-static` where pkg-config can find it.
Once you install the proper library, you will need to rebuild the `energymon-default-sys` crate.
The most straightforward way to do this is to do a clean build of Servo.
To build Servo with the `energy-profiling` feature enabled, pass `--features "energy-profiling"` to the `mach` command, e.g.:
```sh
./mach build -r --features "energy-profiling"
```
When running Servo, you will want to enable the desired Heartbeats to record the results.

View file

@ -7,14 +7,12 @@
use crate::heartbeats; use crate::heartbeats;
use crate::trace_dump::TraceDump; use crate::trace_dump::TraceDump;
use ipc_channel::ipc::{self, IpcReceiver}; use ipc_channel::ipc::{self, IpcReceiver};
use profile_traits::energy::{energy_interval_ms, read_energy_uj};
use profile_traits::time::{ use profile_traits::time::{
ProfilerCategory, ProfilerChan, ProfilerData, ProfilerMsg, TimerMetadata, ProfilerCategory, ProfilerChan, ProfilerData, ProfilerMsg, TimerMetadata,
}; };
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType}; use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use servo_config::opts::OutputOptions; use servo_config::opts::OutputOptions;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
use std::fs::File; use std::fs::File;
use std::io::{self, Write}; use std::io::{self, Write};
@ -253,22 +251,15 @@ impl Profiler {
}; };
if run_ap_thread() { if run_ap_thread() {
let profiler_chan = profiler_chan.clone(); let profiler_chan = profiler_chan.clone();
// min of 1 heartbeat/sec, max of 20 should provide accurate enough power/energy readings // min of 1 heartbeat/sec, max of 20 should provide accurate enough readings
// waking up more frequently allows the thread to end faster on exit // waking up more frequently allows the thread to end faster on exit
const SLEEP_MS: u32 = 10; const SLEEP_MS: u32 = 10;
const MIN_ENERGY_INTERVAL_MS: u32 = 50; let interval_ms = 200;
const MAX_ENERGY_INTERVAL_MS: u32 = 1000;
let interval_ms = enforce_range(
MIN_ENERGY_INTERVAL_MS,
MAX_ENERGY_INTERVAL_MS,
energy_interval_ms(),
);
let loop_count: u32 = (interval_ms as f32 / SLEEP_MS as f32).ceil() as u32; let loop_count: u32 = (interval_ms as f32 / SLEEP_MS as f32).ceil() as u32;
thread::Builder::new() thread::Builder::new()
.name("Application heartbeat profiler".to_owned()) .name("Application heartbeat profiler".to_owned())
.spawn(move || { .spawn(move || {
let mut start_time = precise_time_ns(); let mut start_time = precise_time_ns();
let mut start_energy = read_energy_uj();
loop { loop {
for _ in 0..loop_count { for _ in 0..loop_count {
if run_ap_thread() { if run_ap_thread() {
@ -278,7 +269,6 @@ impl Profiler {
} }
} }
let end_time = precise_time_ns(); let end_time = precise_time_ns();
let end_energy = read_energy_uj();
// send using the inner channel // send using the inner channel
// (using ProfilerChan.send() forces an unwrap // (using ProfilerChan.send() forces an unwrap
// and sometimes panics for this background profiler) // and sometimes panics for this background profiler)
@ -286,12 +276,10 @@ impl Profiler {
if let Err(_) = c.send(ProfilerMsg::Time( if let Err(_) = c.send(ProfilerMsg::Time(
(ProfilerCategory::ApplicationHeartbeat, None), (ProfilerCategory::ApplicationHeartbeat, None),
(start_time, end_time), (start_time, end_time),
(start_energy, end_energy),
)) { )) {
return; return;
} }
start_time = end_time; start_time = end_time;
start_energy = end_energy;
} }
}) })
.expect("Thread spawning failed"); .expect("Thread spawning failed");
@ -331,10 +319,10 @@ impl Profiler {
fn handle_msg(&mut self, msg: ProfilerMsg) -> bool { fn handle_msg(&mut self, msg: ProfilerMsg) -> bool {
match msg.clone() { match msg.clone() {
ProfilerMsg::Time(k, t, e) => { ProfilerMsg::Time(k, t) => {
heartbeats::maybe_heartbeat(&k.0, t.0, t.1, e.0, e.1, self.profile_heartbeats); heartbeats::maybe_heartbeat(&k.0, t.0, t.1, 0, 0, self.profile_heartbeats);
if let Some(ref mut trace) = self.trace { if let Some(ref mut trace) = self.trace {
trace.write_one(&k, t, e); trace.write_one(&k, t);
} }
let ms = (t.1 - t.0) as f64 / 1000000f64; let ms = (t.1 - t.0) as f64 / 1000000f64;
self.find_or_insert(k, ms); self.find_or_insert(k, ms);
@ -475,20 +463,6 @@ impl Profiler {
} }
} }
fn enforce_range<T>(min: T, max: T, value: T) -> T
where
T: Ord,
{
assert!(min <= max);
match value.cmp(&max) {
Ordering::Equal | Ordering::Greater => max,
Ordering::Less => match value.cmp(&min) {
Ordering::Equal | Ordering::Less => min,
Ordering::Greater => value,
},
}
}
pub fn duration_from_seconds(secs: f64) -> Duration { pub fn duration_from_seconds(secs: f64) -> Duration {
pub const NANOS_PER_SEC: u32 = 1_000_000_000; pub const NANOS_PER_SEC: u32 = 1_000_000_000;

View file

@ -25,12 +25,6 @@ struct TraceEntry {
#[serde(rename = "endTime")] #[serde(rename = "endTime")]
end_time: u64, end_time: u64,
#[serde(rename = "startEnergy")]
start_energy: u64,
#[serde(rename = "endEnergy")]
end_energy: u64,
} }
impl TraceDump { impl TraceDump {
@ -50,15 +44,12 @@ impl TraceDump {
&mut self, &mut self,
category: &(ProfilerCategory, Option<TimerMetadata>), category: &(ProfilerCategory, Option<TimerMetadata>),
time: (u64, u64), time: (u64, u64),
energy: (u64, u64),
) { ) {
let entry = TraceEntry { let entry = TraceEntry {
category: category.0, category: category.0,
metadata: category.1.clone(), metadata: category.1.clone(),
start_time: time.0, start_time: time.0,
end_time: time.1, end_time: time.1,
start_energy: energy.0,
end_energy: energy.1,
}; };
serde_json::to_writer(&mut self.file, &entry).unwrap(); serde_json::to_writer(&mut self.file, &entry).unwrap();
writeln!(&mut self.file, ",").unwrap(); writeln!(&mut self.file, ",").unwrap();

View file

@ -10,13 +10,8 @@ publish = false
name = "profile_traits" name = "profile_traits"
path = "lib.rs" path = "lib.rs"
[features]
energy-profiling = ["energy-monitor", "energymon"]
[dependencies] [dependencies]
crossbeam-channel = "0.4" 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" ipc-channel = "0.14"
log = "0.4" log = "0.4"
serde = "1.0" 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] #[macro_use]
extern crate serde; extern crate serde;
#[allow(unsafe_code)]
pub mod energy;
pub mod ipc; pub mod ipc;
pub mod mem; pub mod mem;
pub mod time; pub mod time;

View file

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

View file

@ -14,7 +14,6 @@ crate-type = ["rlib"]
[features] [features]
debugmozjs = ["script/debugmozjs"] debugmozjs = ["script/debugmozjs"]
egl = ["mozangle/egl"] egl = ["mozangle/egl"]
energy-profiling = ["profile_traits/energy-profiling"]
googlevr = ["webxr/googlevr"] googlevr = ["webxr/googlevr"]
jitspew = ["script/jitspew"] jitspew = ["script/jitspew"]
js_backtrace = ["script/js_backtrace"] js_backtrace = ["script/js_backtrace"]

View file

@ -35,7 +35,6 @@ gl_generator = "0.14"
debugmozjs = ["libservo/debugmozjs"] debugmozjs = ["libservo/debugmozjs"]
default = ["webdriver", "max_log_level"] default = ["webdriver", "max_log_level"]
egl = ["libservo/egl"] egl = ["libservo/egl"]
energy-profiling = ["libservo/energy-profiling"]
googlevr = ["libservo/googlevr"] googlevr = ["libservo/googlevr"]
jitspew = ["libservo/jitspew"] jitspew = ["libservo/jitspew"]
js_backtrace = ["libservo/js_backtrace"] js_backtrace = ["libservo/js_backtrace"]

View file

@ -31,7 +31,6 @@ cbindgen = "0.14"
debugmozjs = ["simpleservo/debugmozjs"] debugmozjs = ["simpleservo/debugmozjs"]
default = ["webdriver", "max_log_level"] default = ["webdriver", "max_log_level"]
egl = ["simpleservo/egl"] egl = ["simpleservo/egl"]
energy-profiling = ["simpleservo/energy-profiling"]
googlevr = ["simpleservo/googlevr"] googlevr = ["simpleservo/googlevr"]
jitspew = ["simpleservo/jitspew"] jitspew = ["simpleservo/jitspew"]
js_backtrace = ["simpleservo/js_backtrace"] js_backtrace = ["simpleservo/js_backtrace"]

View file

@ -30,7 +30,6 @@ cc = "1.0"
debugmozjs = ["simpleservo/debugmozjs"] debugmozjs = ["simpleservo/debugmozjs"]
default = ["webdriver", "max_log_level"] default = ["webdriver", "max_log_level"]
egl = ["simpleservo/egl"] egl = ["simpleservo/egl"]
energy-profiling = ["simpleservo/energy-profiling"]
googlevr = ["simpleservo/googlevr"] googlevr = ["simpleservo/googlevr"]
js_backtrace = ["simpleservo/js_backtrace"] js_backtrace = ["simpleservo/js_backtrace"]
layout-2013 = ["simpleservo/layout-2013"] layout-2013 = ["simpleservo/layout-2013"]

View file

@ -30,7 +30,6 @@ ProductName = "Servo"
debugmozjs = ["libservo/debugmozjs"] debugmozjs = ["libservo/debugmozjs"]
default = ["webdriver", "max_log_level"] default = ["webdriver", "max_log_level"]
egl = ["libservo/egl"] egl = ["libservo/egl"]
energy-profiling = ["libservo/energy-profiling"]
jitspew = ["libservo/jitspew"] jitspew = ["libservo/jitspew"]
js_backtrace = ["libservo/js_backtrace"] js_backtrace = ["libservo/js_backtrace"]
layout-2013 = ["libservo/layout-2013"] layout-2013 = ["libservo/layout-2013"]