aboutsummaryrefslogtreecommitdiffstats
path: root/components/profile/heartbeats.rs
diff options
context:
space:
mode:
authorConnor Imes <connor.k.imes@gmail.com>2017-02-07 14:20:43 -0600
committerConnor Imes <connor.k.imes@gmail.com>2017-02-20 17:20:03 -0600
commite602162a3d8af7aa8fff4fde63a1570838aab368 (patch)
tree6d45847a0f69c1b3a0b30564a50b6a63cf70b423 /components/profile/heartbeats.rs
parentd10ad4465f3c77c05ce40885904b71dcde6fd762 (diff)
downloadservo-e602162a3d8af7aa8fff4fde63a1570838aab368.tar.gz
servo-e602162a3d8af7aa8fff4fde63a1570838aab368.zip
Create heartbeats dynamically as needed - avoids the need for hardcoding and maintaining heartbeats for profiler categories.
Use consistent variable names. Use Box::into_raw and Box::from_raw instead of std::mem::transmute.
Diffstat (limited to 'components/profile/heartbeats.rs')
-rw-r--r--components/profile/heartbeats.rs74
1 files changed, 14 insertions, 60 deletions
diff --git a/components/profile/heartbeats.rs b/components/profile/heartbeats.rs
index 761a1cf4d54..0919ccb84e7 100644
--- a/components/profile/heartbeats.rs
+++ b/components/profile/heartbeats.rs
@@ -11,7 +11,6 @@ use std::collections::HashMap;
use std::env::var_os;
use std::error::Error;
use std::fs::File;
-use std::mem;
use std::path::Path;
@@ -19,71 +18,23 @@ static mut HBS: Option<*mut HashMap<ProfilerCategory, Heartbeat>> = None;
/// Initialize heartbeats
pub fn init() {
- let mut hbs: HashMap<ProfilerCategory, Heartbeat> = HashMap::new();
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::Compositing);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutPerform);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutStyleRecalc);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutTextShaping);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutRestyleDamagePropagation);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutNonIncrementalReset);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutSelectorMatch);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutTreeBuilder);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutDamagePropagate);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutGeneratedContent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutDisplayListSorting);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutFloatPlacementSpeculation);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutMain);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutStoreOverflow);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutParallelWarmup);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::LayoutDispListBuild);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::NetHTTPRequestResponse);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::PaintingPerTile);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::PaintingPrepBuff);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::Painting);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ImageDecoding);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ImageSaving);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptAttachLayout);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptConstellationMsg);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptDevtoolsMsg);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptDocumentEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptDomEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptEvaluate);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptFileRead);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptImageCacheMsg);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptInputEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptNetworkEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptParseHTML);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptPlannedNavigation);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptResize);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptSetScrollState);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptSetViewport);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptTimerEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptStylesheetLoad);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptUpdateReplacedElement);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptWebSocketEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptWorkerEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptServiceWorkerEvent);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptParseXML);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptEnterFullscreen);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptExitFullscreen);
- maybe_create_heartbeat(&mut hbs, ProfilerCategory::ScriptWebVREvent);
+ let mut hbs: Box<HashMap<ProfilerCategory, Heartbeat>> = Box::new(HashMap::new());
maybe_create_heartbeat(&mut hbs, ProfilerCategory::ApplicationHeartbeat);
unsafe {
- HBS = Some(mem::transmute(Box::new(hbs)));
+ HBS = Some(Box::into_raw(hbs));
}
}
/// Log regmaining buffer data and cleanup heartbeats
pub fn cleanup() {
unsafe {
- if let Some(hbs) = HBS {
- let mut h: Box<HashMap<ProfilerCategory, Heartbeat>> = mem::transmute(hbs);
- for (_, mut v) in h.iter_mut() {
+ if let Some(hbs_ptr) = HBS {
+ let mut hbs: Box<HashMap<ProfilerCategory, Heartbeat>> = Box::from_raw(hbs_ptr);
+ for (_, mut v) in hbs.iter_mut() {
// log any remaining heartbeat records before dropping
log_heartbeat_records(v);
}
- h.clear();
+ hbs.clear();
}
HBS = None;
}
@@ -92,7 +43,7 @@ pub fn cleanup() {
/// Check if a heartbeat exists for the given category
pub fn is_heartbeat_enabled(category: &ProfilerCategory) -> bool {
unsafe {
- HBS.map_or(false, |m| (*m).contains_key(category))
+ HBS.map_or(false, |hbs_ptr| (*hbs_ptr).contains_key(category) || is_create_heartbeat(category))
}
}
@@ -103,8 +54,11 @@ pub fn maybe_heartbeat(category: &ProfilerCategory,
start_energy: u64,
end_energy: u64) {
unsafe {
- if let Some(map) = HBS {
- if let Some(mut h) = (*map).get_mut(category) {
+ if let Some(hbs_ptr) = HBS {
+ if !(*hbs_ptr).contains_key(category) {
+ maybe_create_heartbeat(&mut (*hbs_ptr), category.clone());
+ }
+ if let Some(mut h) = (*hbs_ptr).get_mut(category) {
(*h).heartbeat(0, 1, start_time, end_time, start_energy, end_energy);
}
}
@@ -179,8 +133,8 @@ fn log_heartbeat_records(hb: &mut Heartbeat) {
/// When this is called from native C, the heartbeat is safely locked
extern fn heartbeat_window_callback(hb: *const HeartbeatContext) {
unsafe {
- if let Some(map) = HBS {
- for (_, v) in (*map).iter_mut() {
+ if let Some(hbs_ptr) = HBS {
+ for (_, v) in (*hbs_ptr).iter_mut() {
if &v.hb as *const HeartbeatContext == hb {
log_heartbeat_records(v);
}