mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
profiler refactor to print every period if new data has arrived
This commit is contained in:
parent
850fa97c4b
commit
496069dad4
3 changed files with 31 additions and 33 deletions
|
@ -19,7 +19,7 @@ use script::script_task;
|
|||
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
|
||||
use servo_net::resource_task::ResourceTask;
|
||||
use servo_net::resource_task;
|
||||
use servo_util::time::{ProfilerChan, ForcePrintMsg};
|
||||
use servo_util::time::{ProfilerChan};
|
||||
|
||||
pub struct Engine {
|
||||
request_port: Port<Msg>,
|
||||
|
@ -34,7 +34,7 @@ pub struct Engine {
|
|||
|
||||
impl Drop for Engine {
|
||||
fn finalize(&self) {
|
||||
self.profiler_chan.send(ForcePrintMsg);
|
||||
//self.profiler_chan.send(ForcePrintMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ use script::engine_interface::{ExitMsg, LoadUrlMsg};
|
|||
use gfx::opts;
|
||||
use servo_net::image_cache_task::ImageCacheTask;
|
||||
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::text;
|
||||
|
@ -92,7 +93,18 @@ fn run(opts: &Opts) {
|
|||
// Create the profiler channel.
|
||||
let (profiler_port, profiler_chan) = comm::stream();
|
||||
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.
|
||||
let (compositor_port, compositor_chan) = comm::stream();
|
||||
|
|
|
@ -50,16 +50,14 @@ pub enum ProfilerMsg {
|
|||
// Normal message used for reporting time
|
||||
TimeMsg(ProfilerCategory, f64),
|
||||
// Message used to force print the profiling metrics
|
||||
ForcePrintMsg,
|
||||
PrintMsg,
|
||||
}
|
||||
|
||||
// back end of the profiler that handles data aggregation and performance metrics
|
||||
pub struct Profiler {
|
||||
port: Port<ProfilerMsg>,
|
||||
buckets: ~[(ProfilerCategory, ~[f64])],
|
||||
verbose: bool,
|
||||
period: f64,
|
||||
last_print: f64,
|
||||
last_msg: Option<ProfilerMsg>,
|
||||
}
|
||||
|
||||
impl ProfilerCategory {
|
||||
|
@ -112,25 +110,19 @@ impl ProfilerCategory {
|
|||
}
|
||||
|
||||
impl Profiler {
|
||||
pub fn create_profiler(port: Port<ProfilerMsg>, period: Option<f64>) {
|
||||
pub fn create_profiler(port: Port<ProfilerMsg>) {
|
||||
let port = Cell(port);
|
||||
do spawn {
|
||||
let mut profiler = Profiler::new(port.take(), period);
|
||||
let mut profiler = Profiler::new(port.take());
|
||||
profiler.start();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(port: Port<ProfilerMsg>, period: Option<f64>) -> Profiler {
|
||||
let (verbose, period) = match period {
|
||||
Some(period) => (true, period),
|
||||
None => (false, 0f64)
|
||||
};
|
||||
pub fn new(port: Port<ProfilerMsg>) -> Profiler {
|
||||
Profiler {
|
||||
port: port,
|
||||
buckets: ProfilerCategory::empty_buckets(),
|
||||
verbose: verbose,
|
||||
period: period,
|
||||
last_print: 0f64,
|
||||
last_msg: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,25 +135,19 @@ impl Profiler {
|
|||
|
||||
priv fn handle_msg(&mut self, msg: ProfilerMsg) {
|
||||
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) = ...,
|
||||
// not a match
|
||||
match self.buckets[category as uint] {
|
||||
(_, ref mut data) => {
|
||||
data.push(t);
|
||||
}
|
||||
(_, ref mut data) => {
|
||||
data.push(t);
|
||||
}
|
||||
|
||||
if self.verbose {
|
||||
let cur_time = precise_time_ns() as f64 / 1000000000f64;
|
||||
if cur_time - self.last_print > self.period {
|
||||
self.last_print = cur_time;
|
||||
self.print_buckets();
|
||||
}
|
||||
}
|
||||
}
|
||||
ForcePrintMsg => self.print_buckets(),
|
||||
},
|
||||
PrintMsg => match self.last_msg {
|
||||
Some(TimeMsg(*)) => self.print_buckets(),
|
||||
_ => {}
|
||||
},
|
||||
};
|
||||
self.last_msg = Some(msg);
|
||||
}
|
||||
|
||||
priv fn print_buckets(&mut self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue