Removed util.

This commit is contained in:
Alan Jeffrey 2016-12-14 10:37:58 -06:00
parent 01b6ad55bd
commit 9be4fd56ce
133 changed files with 396 additions and 352 deletions

View file

@ -12,13 +12,13 @@ path = "lib.rs"
[dependencies]
profile_traits = {path = "../profile_traits"}
plugins = {path = "../plugins"}
util = {path = "../util", features = ["servo"]}
ipc-channel = "0.5"
heartbeats-simple = "0.3"
log = "0.3.5"
serde = "0.8"
serde_derive = "0.8"
serde_json = "0.8"
servo_config = {path = "../config", features = ["servo"]}
time = "0.1.12"
[target.'cfg(target_os = "macos")'.dependencies]

View file

@ -6,13 +6,13 @@
use heartbeats_simple::HeartbeatPow as Heartbeat;
use heartbeats_simple::HeartbeatPowContext as HeartbeatContext;
use profile_traits::time::ProfilerCategory;
use servo_config::opts;
use std::collections::HashMap;
use std::env::var_os;
use std::error::Error;
use std::fs::File;
use std::mem;
use std::path::Path;
use util::opts;
static mut HBS: Option<*mut HashMap<ProfilerCategory, Heartbeat>> = None;

View file

@ -27,10 +27,10 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate servo_config;
#[cfg(target_os = "macos")]
extern crate task_info;
extern crate time as std_time;
extern crate util;
#[allow(unsafe_code)]
mod heartbeats;

View file

@ -13,7 +13,6 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use std::thread;
use time::duration_from_seconds;
use util::thread::spawn_named;
pub struct Profiler {
/// The port through which messages are received.
@ -33,22 +32,22 @@ impl Profiler {
// Create the timer thread if a period was provided.
if let Some(period) = period {
let chan = chan.clone();
spawn_named("Memory profiler timer".to_owned(), move || {
thread::Builder::new().name("Memory profiler timer".to_owned()).spawn(move || {
loop {
thread::sleep(duration_from_seconds(period));
if chan.send(ProfilerMsg::Print).is_err() {
break;
}
}
});
}).expect("Thread spawning failed");
}
// Always spawn the memory profiler. If there is no timer thread it won't receive regular
// `Print` events, but it will still receive the other events.
spawn_named("Memory profiler".to_owned(), move || {
thread::Builder::new().name("Memory profiler".to_owned()).spawn(move || {
let mut mem_profiler = Profiler::new(port);
mem_profiler.start();
});
}).expect("Thread spawning failed");
let mem_profiler_chan = ProfilerChan(chan);

View file

@ -9,6 +9,7 @@ use ipc_channel::ipc::{self, IpcReceiver};
use profile_traits::energy::{energy_interval_ms, read_energy_uj};
use profile_traits::time::{ProfilerCategory, ProfilerChan, ProfilerMsg, TimerMetadata};
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use servo_config::opts::OutputOptions;
use std::{f64, thread, u32, u64};
use std::borrow::ToOwned;
use std::cmp::Ordering;
@ -22,8 +23,6 @@ use std::path::Path;
use std::time::Duration;
use std_time::precise_time_ns;
use trace_dump::TraceDump;
use util::opts::OutputOptions;
use util::thread::spawn_named;
pub trait Formattable {
fn format(&self, output: &Option<OutputOptions>) -> String;
@ -176,28 +175,28 @@ impl Profiler {
Some(ref option) => {
// Spawn the time profiler thread
let outputoption = option.clone();
spawn_named("Time profiler".to_owned(), move || {
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
let trace = file_path.as_ref()
.map(path::Path::new)
.map(fs::File::create)
.map(|res| TraceDump::new(res.unwrap()));
let mut profiler = Profiler::new(port, trace, Some(outputoption));
profiler.start();
});
}).expect("Thread spawning failed");
// decide if we need to spawn the timer thread
match option {
&OutputOptions::FileName(_) => { /* no timer thread needed */ },
&OutputOptions::Stdout(period) => {
// Spawn a timer thread
let chan = chan.clone();
spawn_named("Time profiler timer".to_owned(), move || {
thread::Builder::new().name("Time profiler timer".to_owned()).spawn(move || {
loop {
thread::sleep(duration_from_seconds(period));
if chan.send(ProfilerMsg::Print).is_err() {
break;
}
}
});
}).expect("Thread spawning failed");
},
}
},
@ -205,17 +204,17 @@ impl Profiler {
// this is when the -p option hasn't been specified
if file_path.is_some() {
// Spawn the time profiler
spawn_named("Time profiler".to_owned(), move || {
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
let trace = file_path.as_ref()
.map(path::Path::new)
.map(fs::File::create)
.map(|res| TraceDump::new(res.unwrap()));
let mut profiler = Profiler::new(port, trace, None);
profiler.start();
});
}).expect("Thread spawning failed");
} else {
// No-op to handle messages when the time profiler is not printing:
spawn_named("Time profiler".to_owned(), move || {
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
loop {
match port.recv() {
Err(_) => break,
@ -226,7 +225,7 @@ impl Profiler {
_ => {}
}
}
});
}).expect("Thread spawning failed");
}
}
}
@ -247,7 +246,7 @@ impl Profiler {
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;
spawn_named("Application heartbeat profiler".to_owned(), move || {
thread::Builder::new().name("Application heartbeat profiler".to_owned()).spawn(move || {
let mut start_time = precise_time_ns();
let mut start_energy = read_energy_uj();
loop {
@ -272,7 +271,7 @@ impl Profiler {
start_time = end_time;
start_energy = end_energy;
}
});
}).expect("Thread spawning failed");
}
profiler_chan