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)]
pub struct RenderChan<T> {
chan: SharedChan<Msg<T>>,
}
pub struct RenderChan<T>{chan:SharedChan<Msg<T>>}
impl<T> RenderChan<T> {
pub fn new(chan: Chan<Msg<T>>) -> RenderChan<T> {
RenderChan {
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg<T>) {
self.chan.send(msg);
RenderChan{chan:SharedChan::new(chan)}
}
pub fn send(&self, msg: Msg<T>) { self.chan.send(msg) }
}
struct RenderTask<C,T> {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,27 +3,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Timing functions.
use extra::time::precise_time_ns;
use std::cell::Cell;
use std::comm::{Port, SharedChan};
use extra::sort::tim_sort;
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;
// front-end representation of the profiler used to communicate with the profiler
#[deriving(Clone)]
pub struct ProfilerChan {
chan: SharedChan<ProfilerMsg>,
}
pub struct ProfilerChan(SharedChan<ProfilerMsg>);
impl ProfilerChan {
pub fn new(chan: Chan<ProfilerMsg>) -> ProfilerChan {
ProfilerChan {
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: ProfilerMsg) {
self.chan.send(msg);
ProfilerChan(SharedChan::new(chan))
}
}
@ -101,13 +95,33 @@ pub struct Profiler {
}
impl Profiler {
pub fn create(port: Port<ProfilerMsg>) {
let port = Cell::new(port);
pub fn create(port: Port<ProfilerMsg>, chan: ProfilerChan, period: Option<float>) {
match period {
Some(period) => {
let period = (period * 1000f) as u64;
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();
}
}
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 {
Profiler {