deactive profiler when not in use; use newtype structs for task chans

This commit is contained in:
Tim Kuehn 2013-09-19 21:29:23 -04:00
parent 17864cb25d
commit c804db0f93
7 changed files with 55 additions and 92 deletions

View file

@ -59,19 +59,12 @@ pub fn BufferRequest(screen_rect: Rect<uint>, page_rect: Rect<f32>) -> BufferReq
} }
#[deriving(Clone)] #[deriving(Clone)]
pub struct RenderChan<T> { pub struct RenderChan<T>{chan:SharedChan<Msg<T>>}
chan: SharedChan<Msg<T>>,
}
impl<T> RenderChan<T> { impl<T> RenderChan<T> {
pub fn new(chan: Chan<Msg<T>>) -> RenderChan<T> { pub fn new(chan: Chan<Msg<T>>) -> RenderChan<T> {
RenderChan { RenderChan{chan:SharedChan::new(chan)}
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg<T>) {
self.chan.send(msg);
} }
pub fn send(&self, msg: Msg<T>) { self.chan.send(msg) }
} }
struct RenderTask<C,T> { struct RenderTask<C,T> {

View file

@ -47,7 +47,7 @@ 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, PrintMsg}; use servo_util::time::{Profiler, ProfilerChan};
pub use gfx::opts::Opts; pub use gfx::opts::Opts;
pub use gfx::text; pub use gfx::text;
@ -56,7 +56,7 @@ use std::comm;
#[cfg(not(test))] #[cfg(not(test))]
use std::os; use std::os;
use std::rt::rtio::RtioTimer; use std::rt::rtio::RtioTimer;
use std::rt::io::timer::Timer; use std::task::spawn_with;
#[path="compositing/mod.rs"] #[path="compositing/mod.rs"]
pub mod compositing; pub mod compositing;
@ -127,38 +127,19 @@ fn start(argc: int, argv: **u8, crate_map: *u8) -> int {
fn run(opts: Opts) { fn run(opts: Opts) {
let (shutdown_port, shutdown_chan) = comm::stream(); let (shutdown_port, shutdown_chan) = comm::stream();
let (profiler_port, profiler_chan) = comm::stream(); let (profiler_port, profiler_chan) = special_stream!(ProfilerChan);
let (compositor_port, compositor_chan) = comm::stream(); let (compositor_port, compositor_chan) = special_stream!(CompositorChan);
let profiler_chan = ProfilerChan::new(profiler_chan); Profiler::create(profiler_port, profiler_chan.clone(), opts.profiler_period);
Profiler::create(profiler_port);
do opts.profiler_period.map |&period| {
let profiler_chan = profiler_chan.clone();
let period = (period * 1000f) as u64;
do spawn {
let mut tm = Timer::new().unwrap();
loop {
tm.sleep(period);
profiler_chan.send(PrintMsg);
}
}
};
let compositor_chan = CompositorChan::new(compositor_chan);
let profiler_chan_clone = profiler_chan.clone();
let opts_clone = opts.clone(); do spawn_with((profiler_chan.clone(), compositor_chan, opts.clone()))
|(profiler_chan, compositor_chan, opts)| {
do spawn {
let profiler_chan = profiler_chan_clone.clone();
let compositor_chan = compositor_chan.clone();
let opts = &opts_clone.clone();
let opts = &opts;
// Create a Servo instance. // Create a Servo instance.
let resource_task = ResourceTask(); let resource_task = ResourceTask();
let image_cache_task = ImageCacheTask(resource_task.clone()); let image_cache_task = ImageCacheTask(resource_task.clone());
let constellation_chan = Constellation::start(compositor_chan.clone(), let constellation_chan = Constellation::start(compositor_chan,
opts, opts,
resource_task, resource_task,
image_cache_task, image_cache_task,

View file

@ -12,18 +12,10 @@ use geom::size::Size2D;
use geom::rect::Rect; use geom::rect::Rect;
#[deriving(Clone)] #[deriving(Clone)]
pub struct ConstellationChan { pub struct ConstellationChan(SharedChan<Msg>);
chan: SharedChan<Msg>,
}
impl ConstellationChan { impl ConstellationChan {
pub fn new(chan: Chan<Msg>) -> ConstellationChan { pub fn new(chan: Chan<Msg>) -> ConstellationChan {
ConstellationChan { ConstellationChan(SharedChan::new(chan))
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg) {
self.chan.send(msg);
} }
} }

View file

@ -30,6 +30,7 @@ use std::int;
use std::libc; use std::libc;
use std::rt::rtio::RtioTimer; use std::rt::rtio::RtioTimer;
use std::rt::io::timer::Timer; use std::rt::io::timer::Timer;
use std::task::spawn_with;
use js::jsapi::JSVal; use js::jsapi::JSVal;
pub enum TimerControlMsg { pub enum TimerControlMsg {
@ -198,21 +199,20 @@ impl Window {
compositor: @ScriptListener, compositor: @ScriptListener,
image_cache_task: ImageCacheTask) image_cache_task: ImageCacheTask)
-> @mut Window { -> @mut Window {
let script_chan_clone = script_chan.clone();
let win = @mut Window { let win = @mut Window {
page: page, page: page,
script_chan: script_chan, script_chan: script_chan.clone(),
compositor: compositor, compositor: compositor,
wrapper: WrapperCache::new(), wrapper: WrapperCache::new(),
timer_chan: { timer_chan: {
let (timer_port, timer_chan) = comm::stream::<TimerControlMsg>(); let (timer_port, timer_chan) = comm::stream::<TimerControlMsg>();
let id = page.id.clone(); let id = page.id.clone();
do spawn { do spawn_with(script_chan) |script_chan| {
loop { loop {
match timer_port.recv() { match timer_port.recv() {
TimerMessage_Close => break, TimerMessage_Close => break,
TimerMessage_Fire(td) => script_chan_clone.chan.send(FireTimerMsg(id, td)), TimerMessage_Fire(td) => script_chan.send(FireTimerMsg(id, td)),
TimerMessage_TriggerExit => script_chan_clone.chan.send(ExitMsg), TimerMessage_TriggerExit => script_chan.send(ExitMsg),
} }
} }
} }

View file

@ -111,17 +111,9 @@ pub struct Reflow {
/// Encapsulates a channel to the layout task. /// Encapsulates a channel to the layout task.
#[deriving(Clone)] #[deriving(Clone)]
pub struct LayoutChan { pub struct LayoutChan(SharedChan<Msg>);
chan: SharedChan<Msg>,
}
impl LayoutChan { impl LayoutChan {
pub fn new(chan: Chan<Msg>) -> LayoutChan { pub fn new(chan: Chan<Msg>) -> LayoutChan {
LayoutChan { LayoutChan(SharedChan::new(chan))
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg) {
self.chan.send(msg);
} }
} }

View file

@ -83,20 +83,11 @@ pub struct NewLayoutInfo {
/// Encapsulates external communication with the script task. /// Encapsulates external communication with the script task.
#[deriving(Clone)] #[deriving(Clone)]
pub struct ScriptChan { pub struct ScriptChan(SharedChan<ScriptMsg>);
/// The channel used to send messages to the script task.
chan: SharedChan<ScriptMsg>,
}
impl ScriptChan { impl ScriptChan {
/// Creates a new script chan. /// Creates a new script chan.
pub fn new(chan: Chan<ScriptMsg>) -> ScriptChan { pub fn new(chan: Chan<ScriptMsg>) -> ScriptChan {
ScriptChan { ScriptChan(SharedChan::new(chan))
chan: SharedChan::new(chan)
}
}
pub fn send(&self, msg: ScriptMsg) {
self.chan.send(msg);
} }
} }

View file

@ -3,27 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Timing functions. // Timing functions.
use extra::time::precise_time_ns;
use std::cell::Cell;
use std::comm::{Port, SharedChan}; use std::comm::{Port, SharedChan};
use extra::sort::tim_sort;
use std::iterator::AdditiveIterator; use std::iterator::AdditiveIterator;
use std::rt::io::timer::Timer;
use std::task::spawn_with;
use extra::sort::tim_sort;
use extra::time::precise_time_ns;
use extra::treemap::TreeMap; use extra::treemap::TreeMap;
// front-end representation of the profiler used to communicate with the profiler // front-end representation of the profiler used to communicate with the profiler
#[deriving(Clone)] #[deriving(Clone)]
pub struct ProfilerChan { pub struct ProfilerChan(SharedChan<ProfilerMsg>);
chan: SharedChan<ProfilerMsg>,
}
impl ProfilerChan { impl ProfilerChan {
pub fn new(chan: Chan<ProfilerMsg>) -> ProfilerChan { pub fn new(chan: Chan<ProfilerMsg>) -> ProfilerChan {
ProfilerChan { ProfilerChan(SharedChan::new(chan))
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: ProfilerMsg) {
self.chan.send(msg);
} }
} }
@ -101,13 +95,33 @@ pub struct Profiler {
} }
impl Profiler { impl Profiler {
pub fn create(port: Port<ProfilerMsg>) { pub fn create(port: Port<ProfilerMsg>, chan: ProfilerChan, period: Option<float>) {
let port = Cell::new(port); match period {
Some(period) => {
let period = (period * 1000f) as u64;
do spawn { do spawn {
let mut profiler = Profiler::new(port.take()); let mut timer = Timer::new().unwrap();
loop {
timer.sleep(period);
if !chan.try_send(PrintMsg) {
break;
}
}
}
// Spawn the profiler
do spawn_with(port) |port| {
let mut profiler = Profiler::new(port);
profiler.start(); profiler.start();
} }
} }
None => {
// no-op to handle profiler messages when the profiler is inactive
do spawn_with(port) |port| {
while port.try_recv().is_some() {}
}
}
}
}
pub fn new(port: Port<ProfilerMsg>) -> Profiler { pub fn new(port: Port<ProfilerMsg>) -> Profiler {
Profiler { Profiler {