profiler refactor to print every period if new data has arrived

This commit is contained in:
Tim Kuehn 2013-06-14 15:41:08 -07:00
parent 850fa97c4b
commit 496069dad4
3 changed files with 31 additions and 33 deletions

View file

@ -19,7 +19,7 @@ use script::script_task;
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient}; use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask; use servo_net::resource_task::ResourceTask;
use servo_net::resource_task; use servo_net::resource_task;
use servo_util::time::{ProfilerChan, ForcePrintMsg}; use servo_util::time::{ProfilerChan};
pub struct Engine { pub struct Engine {
request_port: Port<Msg>, request_port: Port<Msg>,
@ -34,7 +34,7 @@ pub struct Engine {
impl Drop for Engine { impl Drop for Engine {
fn finalize(&self) { fn finalize(&self) {
self.profiler_chan.send(ForcePrintMsg); //self.profiler_chan.send(ForcePrintMsg);
} }
} }

View file

@ -40,7 +40,8 @@ use script::engine_interface::{ExitMsg, LoadUrlMsg};
use gfx::opts; use gfx::opts;
use servo_net::image_cache_task::ImageCacheTask; use servo_net::image_cache_task::ImageCacheTask;
use servo_net::resource_task::ResourceTask; use servo_net::resource_task::ResourceTask;
use servo_util::time::{Profiler, ProfilerChan}; use servo_util::time::{Profiler, ProfilerChan, PrintMsg};
use std::uv_global_loop;
pub use gfx::opts::Opts; pub use gfx::opts::Opts;
pub use gfx::text; pub use gfx::text;
@ -92,7 +93,18 @@ fn run(opts: &Opts) {
// Create the profiler channel. // Create the profiler channel.
let (profiler_port, profiler_chan) = comm::stream(); let (profiler_port, profiler_chan) = comm::stream();
let profiler_chan = ProfilerChan::new(profiler_chan); let profiler_chan = ProfilerChan::new(profiler_chan);
Profiler::create_profiler(profiler_port, opts.profiler_period); Profiler::create_profiler(profiler_port);
do opts.profiler_period.map |period| {
let profiler_chan = profiler_chan.clone();
let period = *period;
do spawn {
loop {
std::timer::sleep(&uv_global_loop::get(),
(period * 1000f64) as uint);
profiler_chan.send(PrintMsg);
}
}
};
// Create the compositor. // Create the compositor.
let (compositor_port, compositor_chan) = comm::stream(); let (compositor_port, compositor_chan) = comm::stream();

View file

@ -50,16 +50,14 @@ pub enum ProfilerMsg {
// Normal message used for reporting time // Normal message used for reporting time
TimeMsg(ProfilerCategory, f64), TimeMsg(ProfilerCategory, f64),
// Message used to force print the profiling metrics // Message used to force print the profiling metrics
ForcePrintMsg, PrintMsg,
} }
// back end of the profiler that handles data aggregation and performance metrics // back end of the profiler that handles data aggregation and performance metrics
pub struct Profiler { pub struct Profiler {
port: Port<ProfilerMsg>, port: Port<ProfilerMsg>,
buckets: ~[(ProfilerCategory, ~[f64])], buckets: ~[(ProfilerCategory, ~[f64])],
verbose: bool, last_msg: Option<ProfilerMsg>,
period: f64,
last_print: f64,
} }
impl ProfilerCategory { impl ProfilerCategory {
@ -112,25 +110,19 @@ impl ProfilerCategory {
} }
impl Profiler { impl Profiler {
pub fn create_profiler(port: Port<ProfilerMsg>, period: Option<f64>) { pub fn create_profiler(port: Port<ProfilerMsg>) {
let port = Cell(port); let port = Cell(port);
do spawn { do spawn {
let mut profiler = Profiler::new(port.take(), period); let mut profiler = Profiler::new(port.take());
profiler.start(); profiler.start();
} }
} }
pub fn new(port: Port<ProfilerMsg>, period: Option<f64>) -> Profiler { pub fn new(port: Port<ProfilerMsg>) -> Profiler {
let (verbose, period) = match period {
Some(period) => (true, period),
None => (false, 0f64)
};
Profiler { Profiler {
port: port, port: port,
buckets: ProfilerCategory::empty_buckets(), buckets: ProfilerCategory::empty_buckets(),
verbose: verbose, last_msg: None,
period: period,
last_print: 0f64,
} }
} }
@ -143,25 +135,19 @@ impl Profiler {
priv fn handle_msg(&mut self, msg: ProfilerMsg) { priv fn handle_msg(&mut self, msg: ProfilerMsg) {
match msg { match msg {
TimeMsg(category, t) => { TimeMsg(category, t) => match self.buckets[category as uint] {
// FIXME(#3874): this should be a let (cat, ref mut bucket) = ..., // FIXME(#3874): this should be a let (cat, ref mut bucket) = ...,
// not a match // not a match
match self.buckets[category as uint] { (_, ref mut data) => {
(_, ref mut data) => { data.push(t);
data.push(t);
}
} }
},
if self.verbose { PrintMsg => match self.last_msg {
let cur_time = precise_time_ns() as f64 / 1000000000f64; Some(TimeMsg(*)) => self.print_buckets(),
if cur_time - self.last_print > self.period { _ => {}
self.last_print = cur_time; },
self.print_buckets();
}
}
}
ForcePrintMsg => self.print_buckets(),
}; };
self.last_msg = Some(msg);
} }
priv fn print_buckets(&mut self) { priv fn print_buckets(&mut self) {