From 496069dad4beb0b8e395f36ee78c177af5429d6b Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Fri, 14 Jun 2013 15:41:08 -0700 Subject: [PATCH] profiler refactor to print every period if new data has arrived --- src/components/main/engine.rs | 4 ++-- src/components/main/servo.rc | 16 +++++++++++-- src/components/util/time.rs | 44 ++++++++++++----------------------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/components/main/engine.rs b/src/components/main/engine.rs index 3958231196d..8a8b30dc226 100644 --- a/src/components/main/engine.rs +++ b/src/components/main/engine.rs @@ -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, @@ -34,7 +34,7 @@ pub struct Engine { impl Drop for Engine { fn finalize(&self) { - self.profiler_chan.send(ForcePrintMsg); + //self.profiler_chan.send(ForcePrintMsg); } } diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 5196990f628..072d718b824 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -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(); diff --git a/src/components/util/time.rs b/src/components/util/time.rs index cd639105e9a..8d1cdfc7091 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -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, buckets: ~[(ProfilerCategory, ~[f64])], - verbose: bool, - period: f64, - last_print: f64, + last_msg: Option, } impl ProfilerCategory { @@ -112,25 +110,19 @@ impl ProfilerCategory { } impl Profiler { - pub fn create_profiler(port: Port, period: Option) { + pub fn create_profiler(port: Port) { 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, period: Option) -> Profiler { - let (verbose, period) = match period { - Some(period) => (true, period), - None => (false, 0f64) - }; + pub fn new(port: Port) -> 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) {