Skip to content
Permalink
Browse files

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

  • Loading branch information
Tim Kuehn
Tim Kuehn committed Sep 20, 2013
1 parent 17864cb commit c804db0f933b3454ba6e5c685a2ac7c8da21e45a
@@ -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> {
@@ -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_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();

let opts_clone = opts.clone();
let (profiler_port, profiler_chan) = special_stream!(ProfilerChan);
let (compositor_port, compositor_chan) = special_stream!(CompositorChan);

do spawn {
let profiler_chan = profiler_chan_clone.clone();
let compositor_chan = compositor_chan.clone();
Profiler::create(profiler_port, profiler_chan.clone(), opts.profiler_period);

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,
@@ -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))
}
}

@@ -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),
}
}
}
@@ -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))
}
}
@@ -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))
}
}

@@ -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,11 +95,31 @@ pub struct Profiler {
}

impl Profiler {
pub fn create(port: Port<ProfilerMsg>) {
let port = Cell::new(port);
do spawn {
let mut profiler = Profiler::new(port.take());
profiler.start();
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 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() {}
}
}
}
}

0 comments on commit c804db0

Please sign in to comment.
You can’t perform that action at this time.