mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Update rustc to revision 3dcd2157403163789aaf21a9ab3c4d30a7c6494d.
This commit is contained in:
parent
b8900782b0
commit
466faac2a5
223 changed files with 4414 additions and 4105 deletions
|
@ -27,3 +27,6 @@ git = "https://github.com/servo/string-cache"
|
|||
|
||||
[dependencies.url]
|
||||
git = "https://github.com/servo/rust-url"
|
||||
|
||||
[dependencies.time]
|
||||
git = "https://github.com/rust-lang/time"
|
||||
|
|
|
@ -10,7 +10,7 @@ use geom::size::Size2D;
|
|||
use serialize::{Encodable, Encoder};
|
||||
use std::default::Default;
|
||||
use std::i32;
|
||||
use std::num::{NumCast, Zero};
|
||||
use std::num::{Float, NumCast, Zero};
|
||||
use std::fmt;
|
||||
|
||||
// Units for use with geom::length and geom::scale_factor.
|
||||
|
|
|
@ -28,9 +28,9 @@ impl MemoryProfilerChan {
|
|||
|
||||
pub enum MemoryProfilerMsg {
|
||||
/// Message used to force print the memory profiling metrics.
|
||||
PrintMsg,
|
||||
Print,
|
||||
/// Tells the memory profiler to shut down.
|
||||
ExitMsg,
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub struct MemoryProfiler {
|
||||
|
@ -47,7 +47,7 @@ impl MemoryProfiler {
|
|||
spawn_named("Memory profiler timer", proc() {
|
||||
loop {
|
||||
sleep(period);
|
||||
if chan.send_opt(PrintMsg).is_err() {
|
||||
if chan.send_opt(MemoryProfilerMsg::Print).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl MemoryProfiler {
|
|||
spawn_named("Memory profiler", proc() {
|
||||
loop {
|
||||
match port.recv_opt() {
|
||||
Err(_) | Ok(ExitMsg) => break,
|
||||
Err(_) | Ok(MemoryProfilerMsg::Exit) => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -96,11 +96,11 @@ impl MemoryProfiler {
|
|||
|
||||
fn handle_msg(&self, msg: MemoryProfilerMsg) -> bool {
|
||||
match msg {
|
||||
PrintMsg => {
|
||||
MemoryProfilerMsg::Print => {
|
||||
self.handle_print_msg();
|
||||
true
|
||||
},
|
||||
ExitMsg => false
|
||||
MemoryProfilerMsg::Exit => false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,16 +108,16 @@ impl MemoryProfiler {
|
|||
match nbytes {
|
||||
Some(nbytes) => {
|
||||
let mebi = 1024f64 * 1024f64;
|
||||
println!("{:16s}: {:12.2f}", path, (nbytes as f64) / mebi);
|
||||
println!("{:16}: {:12.2}", path, (nbytes as f64) / mebi);
|
||||
}
|
||||
None => {
|
||||
println!("{:16s}: {:>12s}", path, "???");
|
||||
println!("{:16}: {:>12}", path, "???");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_print_msg(&self) {
|
||||
println!("{:16s}: {:12s}", "_category_", "_size (MiB)_");
|
||||
println!("{:16}: {:12}", "_category_", "_size (MiB)_");
|
||||
|
||||
// Virtual and physical memory usage, as reported by the OS.
|
||||
MemoryProfiler::print_measurement("vsize", get_vsize());
|
||||
|
|
|
@ -179,7 +179,7 @@ pub fn default_opts() -> Opts {
|
|||
dump_flow_tree: false,
|
||||
validate_display_list_geometry: false,
|
||||
profile_tasks: false,
|
||||
render_api: OpenGL,
|
||||
render_api: RenderApi::OpenGL,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,8 +298,8 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
|
|||
};
|
||||
|
||||
let render_api = match opt_match.opt_str("r").unwrap_or("gl".to_string()).as_slice() {
|
||||
"mesa" => Mesa,
|
||||
"gl" => OpenGL,
|
||||
"mesa" => RenderApi::Mesa,
|
||||
"gl" => RenderApi::OpenGL,
|
||||
_ => {
|
||||
args_fail("Unknown render api specified");
|
||||
return false;
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::cmp::{max, min};
|
|||
use std::iter;
|
||||
use std::fmt;
|
||||
use std::num;
|
||||
use std::num::{Bounded, Zero};
|
||||
use std::num::{Int, Bounded, Zero};
|
||||
|
||||
/// An index type to be used by a `Range`
|
||||
pub trait RangeIndex: Copy
|
||||
|
@ -52,6 +52,30 @@ macro_rules! int_range_index {
|
|||
}
|
||||
|
||||
impl RangeIndex for $Self {}
|
||||
impl ::std::num::Int for $Self {
|
||||
fn zero() -> $Self { $Self(0) }
|
||||
fn one() -> $Self { $Self(1) }
|
||||
fn min_value() -> $Self { $Self(::std::num::Int::min_value()) }
|
||||
fn max_value() -> $Self { $Self(::std::num::Int::max_value()) }
|
||||
fn count_ones(self) -> uint { self.get().count_ones() }
|
||||
fn leading_zeros(self) -> uint { self.get().leading_zeros() }
|
||||
fn trailing_zeros(self) -> uint { self.get().trailing_zeros() }
|
||||
fn rotate_left(self, n: uint) -> $Self { $Self(self.get().rotate_left(n)) }
|
||||
fn rotate_right(self, n: uint) -> $Self { $Self(self.get().rotate_right(n)) }
|
||||
fn swap_bytes(self) -> $Self { $Self(self.get().swap_bytes()) }
|
||||
fn checked_add(self, other: $Self) -> Option<$Self> {
|
||||
self.get().checked_add(other.get()).map($Self)
|
||||
}
|
||||
fn checked_sub(self, other: $Self) -> Option<$Self> {
|
||||
self.get().checked_sub(other.get()).map($Self)
|
||||
}
|
||||
fn checked_mul(self, other: $Self) -> Option<$Self> {
|
||||
self.get().checked_mul(other.get()).map($Self)
|
||||
}
|
||||
fn checked_div(self, other: $Self) -> Option<$Self> {
|
||||
self.get().checked_div(other.get()).map($Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntRangeIndex<$T> for $Self {
|
||||
#[inline]
|
||||
|
@ -108,6 +132,60 @@ macro_rules! int_range_index {
|
|||
Some(self.get() as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::num::NumCast for $Self {
|
||||
fn from<T: ToPrimitive>(n: T) -> Option<$Self> {
|
||||
n.to_int().map($Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<$Self, $Self> for $Self {
|
||||
fn div(&self, other: &$Self) -> $Self {
|
||||
$Self(self.get() / other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem<$Self, $Self> for $Self {
|
||||
fn rem(&self, other: &$Self) -> $Self {
|
||||
$Self(self.get() % other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl Not<$Self> for $Self {
|
||||
fn not(&self) -> $Self {
|
||||
$Self(!self.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd<$Self, $Self> for $Self {
|
||||
fn bitand(&self, other: &$Self) -> $Self {
|
||||
$Self(self.get() & other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<$Self, $Self> for $Self {
|
||||
fn bitor(&self, other: &$Self) -> $Self {
|
||||
$Self(self.get() | other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl BitXor<$Self, $Self> for $Self {
|
||||
fn bitxor(&self, other: &$Self) -> $Self {
|
||||
$Self(self.get() ^ other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl Shl<uint, $Self> for $Self {
|
||||
fn shl(&self, n: &uint) -> $Self {
|
||||
$Self(self.get() << *n)
|
||||
}
|
||||
}
|
||||
|
||||
impl Shr<uint, $Self> for $Self {
|
||||
fn shr(&self, n: &uint) -> $Self {
|
||||
$Self(self.get() >> *n)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -282,7 +360,7 @@ impl<I: RangeIndex> Range<I> {
|
|||
}
|
||||
|
||||
/// Methods for `Range`s with indices based on integer values
|
||||
impl<T: Int, I: IntRangeIndex<T>> Range<I> {
|
||||
impl<T: Int+Bounded, I: IntRangeIndex<T>> Range<I> {
|
||||
/// Returns an iterater that increments over `[begin, end)`.
|
||||
#[inline]
|
||||
pub fn each_index(&self) -> EachIndex<T, I> {
|
||||
|
|
|
@ -6,11 +6,11 @@ use opts;
|
|||
use std::any::Any;
|
||||
#[cfg(not(test))]
|
||||
use std::io::File;
|
||||
use std::mem;
|
||||
use std::raw;
|
||||
//use std::mem;
|
||||
//use std::raw;
|
||||
use std::rt::Runtime;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::rtio;
|
||||
//use std::rt::rtio;
|
||||
use std::rt::task::{Task, TaskOpts, BlockedTask};
|
||||
use std_time;
|
||||
use sync::Mutex;
|
||||
|
@ -28,7 +28,6 @@ pub enum Event {
|
|||
#[deriving(Encodable)]
|
||||
pub struct Message {
|
||||
timestamp: u64,
|
||||
thread_id: uint,
|
||||
event: Event,
|
||||
}
|
||||
|
||||
|
@ -110,7 +109,7 @@ fn install() {
|
|||
inner: Some(rt),
|
||||
messages: vec!(),
|
||||
};
|
||||
new_rt.log(Spawn);
|
||||
new_rt.log(Event::Spawn);
|
||||
task.put_runtime(new_rt);
|
||||
}
|
||||
|
||||
|
@ -119,7 +118,7 @@ fn install() {
|
|||
fn uninstall() -> InstrumentedRuntime {
|
||||
let mut task = Local::borrow(None::<Task>);
|
||||
let mut rt = task.maybe_take_runtime::<InstrumentedRuntime>().unwrap();
|
||||
rt.log(Death);
|
||||
rt.log(Event::Death);
|
||||
task.put_runtime(rt.inner.take().unwrap());
|
||||
*rt
|
||||
}
|
||||
|
@ -142,22 +141,13 @@ impl InstrumentedRuntime {
|
|||
|
||||
/// Logs a message into this runtime
|
||||
fn log(&mut self, event: Event) {
|
||||
let id = self.thread_id();
|
||||
self.messages.push(Message {
|
||||
timestamp: std_time::precise_time_ns(),
|
||||
event: event,
|
||||
thread_id: id,
|
||||
});
|
||||
}
|
||||
|
||||
fn task_id(&self) -> uint { self as *const _ as uint }
|
||||
|
||||
fn thread_id(&mut self) -> uint {
|
||||
self.inner.as_mut().unwrap().local_io().map(|mut i| {
|
||||
let i: raw::TraitObject = unsafe { mem::transmute(i.get()) };
|
||||
i.data as uint
|
||||
}).unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Runtime for InstrumentedRuntime {
|
||||
|
@ -177,9 +167,9 @@ impl Runtime for InstrumentedRuntime {
|
|||
|
||||
fn deschedule(mut self: Box<InstrumentedRuntime>, times: uint, cur_task: Box<Task>,
|
||||
f: |BlockedTask| -> Result<(), BlockedTask>) {
|
||||
self.log(Unschedule);
|
||||
self.log(Event::Unschedule);
|
||||
self.inner.take().unwrap().deschedule(times, cur_task, f);
|
||||
self.put(Some(Schedule));
|
||||
self.put(Some(Event::Schedule));
|
||||
}
|
||||
|
||||
fn reawaken(mut self: Box<InstrumentedRuntime>, to_wake: Box<Task>) {
|
||||
|
@ -201,9 +191,6 @@ impl Runtime for InstrumentedRuntime {
|
|||
self.put(None)
|
||||
}
|
||||
|
||||
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
|
||||
self.inner.as_mut().unwrap().local_io()
|
||||
}
|
||||
fn stack_bounds(&self) -> (uint, uint) { self.inner.as_ref().unwrap().stack_bounds() }
|
||||
fn can_block(&self) -> bool { self.inner.as_ref().unwrap().can_block() }
|
||||
fn wrap(self: Box<InstrumentedRuntime>) -> Box<Any+'static> { self as Box<Any> }
|
||||
|
|
|
@ -420,8 +420,8 @@ macro_rules! def_small_vector(
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Extendable<T> for $name<T> {
|
||||
fn extend<I: Iterator<T>>(&mut self, mut iter: I) {
|
||||
impl<T> $name<T> {
|
||||
pub fn extend<I: Iterator<T>>(&mut self, mut iter: I) {
|
||||
let (lower_size_bound, _) = iter.size_hint();
|
||||
|
||||
let target_len = self.len() + lower_size_bound;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
use geometry::Au;
|
||||
|
||||
use cssparser::{mod, RGBA, RGBAColor};
|
||||
use cssparser::{mod, RGBA, Color};
|
||||
use std::ascii::AsciiExt;
|
||||
use std::from_str::FromStr;
|
||||
use std::iter::Filter;
|
||||
use std::str::{CharEq, CharSplits};
|
||||
use std::num::Int;
|
||||
use std::str::{CharEq, CharSplits, FromStr};
|
||||
use unicode::char::to_lowercase;
|
||||
|
||||
pub type DOMString = String;
|
||||
|
@ -105,13 +105,13 @@ fn do_parse_integer<T: Iterator<char>>(input: T) -> Option<i64> {
|
|||
d as i64 - '0' as i64
|
||||
}).fold(Some(0i64), |accumulator, d| {
|
||||
accumulator.and_then(|accumulator| {
|
||||
accumulator.checked_mul(&10)
|
||||
accumulator.checked_mul(10)
|
||||
}).and_then(|accumulator| {
|
||||
accumulator.checked_add(&d)
|
||||
accumulator.checked_add(d)
|
||||
})
|
||||
});
|
||||
|
||||
return value.and_then(|value| value.checked_mul(&sign));
|
||||
return value.and_then(|value| value.checked_mul(sign));
|
||||
}
|
||||
|
||||
/// Parse an integer according to
|
||||
|
@ -131,23 +131,23 @@ pub fn parse_unsigned_integer<T: Iterator<char>>(input: T) -> Option<u32> {
|
|||
}
|
||||
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
AutoLpa,
|
||||
PercentageLpa(f64),
|
||||
LengthLpa(Au),
|
||||
Auto,
|
||||
Percentage(f64),
|
||||
Length(Au),
|
||||
}
|
||||
|
||||
/// Parses a length per HTML5 § 2.4.4.4. If unparseable, `AutoLpa` is returned.
|
||||
/// Parses a length per HTML5 § 2.4.4.4. If unparseable, `Auto` is returned.
|
||||
pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
||||
value = value.trim_left_chars(Whitespace);
|
||||
if value.len() == 0 {
|
||||
return AutoLpa
|
||||
return LengthOrPercentageOrAuto::Auto
|
||||
}
|
||||
if value.starts_with("+") {
|
||||
value = value.slice_from(1)
|
||||
}
|
||||
value = value.trim_left_chars('0');
|
||||
if value.len() == 0 {
|
||||
return AutoLpa
|
||||
return LengthOrPercentageOrAuto::Auto
|
||||
}
|
||||
|
||||
let mut end_index = value.len();
|
||||
|
@ -175,14 +175,14 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
|
|||
if found_percent {
|
||||
let result: Option<f64> = FromStr::from_str(value);
|
||||
match result {
|
||||
Some(number) => return PercentageLpa((number as f64) / 100.0),
|
||||
None => return AutoLpa,
|
||||
Some(number) => return LengthOrPercentageOrAuto::Percentage((number as f64) / 100.0),
|
||||
None => return LengthOrPercentageOrAuto::Auto,
|
||||
}
|
||||
}
|
||||
|
||||
match FromStr::from_str(value) {
|
||||
Some(number) => LengthLpa(Au::from_px(number)),
|
||||
None => AutoLpa,
|
||||
Some(number) => LengthOrPercentageOrAuto::Length(Au::from_px(number)),
|
||||
None => LengthOrPercentageOrAuto::Auto,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
|
|||
|
||||
// Step 5.
|
||||
match cssparser::parse_color_keyword(input) {
|
||||
Ok(RGBAColor(rgba)) => return Ok(rgba),
|
||||
Ok(Color::RGBA(rgba)) => return Ok(rgba),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,13 @@ pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
|
|||
};
|
||||
|
||||
let watched_name = name.to_string();
|
||||
let watcher_name = format!("{:s}Watcher", watched_name);
|
||||
let watcher_name = format!("{}Watcher", watched_name);
|
||||
TaskBuilder::new().named(watcher_name).spawn(proc() {
|
||||
rtinstrument::instrument(proc() {
|
||||
match future_result.unwrap() {
|
||||
Ok(()) => (),
|
||||
Err(..) => {
|
||||
debug!("{:s} failed, notifying constellation", name);
|
||||
debug!("{} failed, notifying constellation", name);
|
||||
dest.send(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::comm::{Sender, channel, Receiver};
|
|||
use std::f64;
|
||||
use std::io::timer::sleep;
|
||||
use std::iter::AdditiveIterator;
|
||||
use std::num::FloatMath;
|
||||
use std::time::duration::Duration;
|
||||
use std_time::precise_time_ns;
|
||||
use task::{spawn_named};
|
||||
|
@ -60,11 +61,11 @@ impl Formatable for Option<TimerMetadata> {
|
|||
#[deriving(Clone)]
|
||||
pub enum TimeProfilerMsg {
|
||||
/// Normal message used for reporting time
|
||||
TimeMsg((TimeProfilerCategory, Option<TimerMetadata>), f64),
|
||||
Time((TimeProfilerCategory, Option<TimerMetadata>), f64),
|
||||
/// Message used to force print the profiling metrics
|
||||
PrintMsg,
|
||||
Print,
|
||||
/// Tells the profiler to shut down.
|
||||
ExitMsg,
|
||||
Exit,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
|
@ -92,38 +93,38 @@ impl Formatable for TimeProfilerCategory {
|
|||
// and should be printed to indicate this
|
||||
fn format(&self) -> String {
|
||||
let padding = match *self {
|
||||
LayoutStyleRecalcCategory |
|
||||
LayoutRestyleDamagePropagation |
|
||||
LayoutNonIncrementalReset |
|
||||
LayoutMainCategory |
|
||||
LayoutDispListBuildCategory |
|
||||
LayoutShapingCategory |
|
||||
LayoutDamagePropagateCategory |
|
||||
PaintingPerTileCategory |
|
||||
PaintingPrepBuffCategory => "+ ",
|
||||
LayoutParallelWarmupCategory |
|
||||
LayoutSelectorMatchCategory |
|
||||
LayoutTreeBuilderCategory => "| + ",
|
||||
TimeProfilerCategory::LayoutStyleRecalcCategory |
|
||||
TimeProfilerCategory::LayoutRestyleDamagePropagation |
|
||||
TimeProfilerCategory::LayoutNonIncrementalReset |
|
||||
TimeProfilerCategory::LayoutMainCategory |
|
||||
TimeProfilerCategory::LayoutDispListBuildCategory |
|
||||
TimeProfilerCategory::LayoutShapingCategory |
|
||||
TimeProfilerCategory::LayoutDamagePropagateCategory |
|
||||
TimeProfilerCategory::PaintingPerTileCategory |
|
||||
TimeProfilerCategory::PaintingPrepBuffCategory => "+ ",
|
||||
TimeProfilerCategory::LayoutParallelWarmupCategory |
|
||||
TimeProfilerCategory::LayoutSelectorMatchCategory |
|
||||
TimeProfilerCategory::LayoutTreeBuilderCategory => "| + ",
|
||||
_ => ""
|
||||
};
|
||||
let name = match *self {
|
||||
CompositingCategory => "Compositing",
|
||||
LayoutPerformCategory => "Layout",
|
||||
LayoutStyleRecalcCategory => "Style Recalc",
|
||||
LayoutRestyleDamagePropagation => "Restyle Damage Propagation",
|
||||
LayoutNonIncrementalReset => "Non-incremental reset (temporary)",
|
||||
LayoutSelectorMatchCategory => "Selector Matching",
|
||||
LayoutTreeBuilderCategory => "Tree Building",
|
||||
LayoutDamagePropagateCategory => "Damage Propagation",
|
||||
LayoutMainCategory => "Primary Layout Pass",
|
||||
LayoutParallelWarmupCategory => "Parallel Warmup",
|
||||
LayoutShapingCategory => "Shaping",
|
||||
LayoutDispListBuildCategory => "Display List Construction",
|
||||
PaintingPerTileCategory => "Painting Per Tile",
|
||||
PaintingPrepBuffCategory => "Buffer Prep",
|
||||
PaintingCategory => "Painting",
|
||||
TimeProfilerCategory::CompositingCategory => "Compositing",
|
||||
TimeProfilerCategory::LayoutPerformCategory => "Layout",
|
||||
TimeProfilerCategory::LayoutStyleRecalcCategory => "Style Recalc",
|
||||
TimeProfilerCategory::LayoutRestyleDamagePropagation => "Restyle Damage Propagation",
|
||||
TimeProfilerCategory::LayoutNonIncrementalReset => "Non-incremental reset (temporary)",
|
||||
TimeProfilerCategory::LayoutSelectorMatchCategory => "Selector Matching",
|
||||
TimeProfilerCategory::LayoutTreeBuilderCategory => "Tree Building",
|
||||
TimeProfilerCategory::LayoutDamagePropagateCategory => "Damage Propagation",
|
||||
TimeProfilerCategory::LayoutMainCategory => "Primary Layout Pass",
|
||||
TimeProfilerCategory::LayoutParallelWarmupCategory => "Parallel Warmup",
|
||||
TimeProfilerCategory::LayoutShapingCategory => "Shaping",
|
||||
TimeProfilerCategory::LayoutDispListBuildCategory => "Display List Construction",
|
||||
TimeProfilerCategory::PaintingPerTileCategory => "Painting Per Tile",
|
||||
TimeProfilerCategory::PaintingPrepBuffCategory => "Buffer Prep",
|
||||
TimeProfilerCategory::PaintingCategory => "Painting",
|
||||
};
|
||||
format!("{:s}{}", padding, name)
|
||||
format!("{}{}", padding, name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +147,7 @@ impl TimeProfiler {
|
|||
spawn_named("Time profiler timer", proc() {
|
||||
loop {
|
||||
sleep(period);
|
||||
if chan.send_opt(PrintMsg).is_err() {
|
||||
if chan.send_opt(TimeProfilerMsg::Print).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +163,7 @@ impl TimeProfiler {
|
|||
spawn_named("Time profiler", proc() {
|
||||
loop {
|
||||
match port.recv_opt() {
|
||||
Err(_) | Ok(ExitMsg) => break,
|
||||
Err(_) | Ok(TimeProfilerMsg::Exit) => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -206,20 +207,20 @@ impl TimeProfiler {
|
|||
|
||||
fn handle_msg(&mut self, msg: TimeProfilerMsg) -> bool {
|
||||
match msg.clone() {
|
||||
TimeMsg(k, t) => self.find_or_insert(k, t),
|
||||
PrintMsg => match self.last_msg {
|
||||
TimeProfilerMsg::Time(k, t) => self.find_or_insert(k, t),
|
||||
TimeProfilerMsg::Print => match self.last_msg {
|
||||
// only print if more data has arrived since the last printout
|
||||
Some(TimeMsg(..)) => self.print_buckets(),
|
||||
Some(TimeProfilerMsg::Time(..)) => self.print_buckets(),
|
||||
_ => ()
|
||||
},
|
||||
ExitMsg => return false,
|
||||
TimeProfilerMsg::Exit => return false,
|
||||
};
|
||||
self.last_msg = Some(msg);
|
||||
true
|
||||
}
|
||||
|
||||
fn print_buckets(&mut self) {
|
||||
println!("{:35s} {:14} {:9} {:30} {:15s} {:15s} {:-15s} {:-15s} {:-15s}",
|
||||
println!("{:35} {:14} {:9} {:30} {:15} {:15} {:-15} {:-15} {:-15}",
|
||||
"_category_", "_incremental?_", "_iframe?_",
|
||||
" _url_", " _mean (ms)_", " _median (ms)_",
|
||||
" _min (ms)_", " _max (ms)_", " _events_");
|
||||
|
@ -238,7 +239,7 @@ impl TimeProfiler {
|
|||
data.as_slice()[data_len / 2],
|
||||
data.iter().fold(f64::INFINITY, |a, &b| a.min(b)),
|
||||
data.iter().fold(-f64::INFINITY, |a, &b| a.max(b)));
|
||||
println!("{:-35s}{} {:15.4f} {:15.4f} {:15.4f} {:15.4f} {:15u}",
|
||||
println!("{:-35}{} {:15.4} {:15.4} {:15.4} {:15.4} {:15}",
|
||||
category.format(), meta.format(), mean, median, min, max, data_len);
|
||||
}
|
||||
}
|
||||
|
@ -248,14 +249,14 @@ impl TimeProfiler {
|
|||
|
||||
#[deriving(Eq, PartialEq)]
|
||||
pub enum TimerMetadataFrameType {
|
||||
TimeRootWindow,
|
||||
TimeIFrame,
|
||||
RootWindow,
|
||||
IFrame,
|
||||
}
|
||||
|
||||
#[deriving(Eq, PartialEq)]
|
||||
pub enum TimerMetadataReflowType {
|
||||
TimeIncremental,
|
||||
TimeFirstReflow,
|
||||
Incremental,
|
||||
FirstReflow,
|
||||
}
|
||||
|
||||
pub fn profile<T>(category: TimeProfilerCategory,
|
||||
|
@ -270,10 +271,10 @@ pub fn profile<T>(category: TimeProfilerCategory,
|
|||
let meta = meta.map(|(url, iframe, reflow_type)|
|
||||
TimerMetadata {
|
||||
url: url.serialize(),
|
||||
iframe: iframe == TimeIFrame,
|
||||
incremental: reflow_type == TimeIncremental,
|
||||
iframe: iframe == TimerMetadataFrameType::IFrame,
|
||||
incremental: reflow_type == TimerMetadataReflowType::Incremental,
|
||||
});
|
||||
time_profiler_chan.send(TimeMsg((category, meta), ms));
|
||||
time_profiler_chan.send(TimeProfilerMsg::Time((category, meta), ms));
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ pub fn time<T>(msg: &str, callback: || -> T) -> T{
|
|||
let end_time = precise_time_ns();
|
||||
let ms = (end_time - start_time) as f64 / 1000000f64;
|
||||
if ms >= 5f64 {
|
||||
debug!("{:s} took {} ms", msg, ms);
|
||||
debug!("{} took {} ms", msg, ms);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -33,17 +33,17 @@ pub struct WorkUnit<QueueData, WorkData> {
|
|||
/// Messages from the supervisor to the worker.
|
||||
enum WorkerMsg<QueueData, WorkData> {
|
||||
/// Tells the worker to start work.
|
||||
StartMsg(Worker<WorkUnit<QueueData, WorkData>>, *mut AtomicUint, *const QueueData),
|
||||
/// Tells the worker to stop. It can be restarted again with a `StartMsg`.
|
||||
StopMsg,
|
||||
Start(Worker<WorkUnit<QueueData, WorkData>>, *mut AtomicUint, *const QueueData),
|
||||
/// Tells the worker to stop. It can be restarted again with a `WorkerMsg::Start`.
|
||||
Stop,
|
||||
/// Tells the worker thread to terminate.
|
||||
ExitMsg,
|
||||
Exit,
|
||||
}
|
||||
|
||||
/// Messages to the supervisor.
|
||||
enum SupervisorMsg<QueueData, WorkData> {
|
||||
FinishedMsg,
|
||||
ReturnDequeMsg(uint, Worker<WorkUnit<QueueData, WorkData>>),
|
||||
Finished,
|
||||
ReturnDeque(uint, Worker<WorkUnit<QueueData, WorkData>>),
|
||||
}
|
||||
|
||||
/// Information that the supervisor thread keeps about the worker threads.
|
||||
|
@ -81,9 +81,9 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
|||
loop {
|
||||
// Wait for a start message.
|
||||
let (mut deque, ref_count, queue_data) = match self.port.recv() {
|
||||
StartMsg(deque, ref_count, queue_data) => (deque, ref_count, queue_data),
|
||||
StopMsg => panic!("unexpected stop message"),
|
||||
ExitMsg => return,
|
||||
WorkerMsg::Start(deque, ref_count, queue_data) => (deque, ref_count, queue_data),
|
||||
WorkerMsg::Stop => panic!("unexpected stop message"),
|
||||
WorkerMsg::Exit => return,
|
||||
};
|
||||
|
||||
let mut back_off_sleep = 0 as u32;
|
||||
|
@ -125,11 +125,11 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
|||
|
||||
if i == SPIN_COUNT {
|
||||
match self.port.try_recv() {
|
||||
Ok(StopMsg) => {
|
||||
Ok(WorkerMsg::Stop) => {
|
||||
should_continue = false;
|
||||
break
|
||||
}
|
||||
Ok(ExitMsg) => return,
|
||||
Ok(WorkerMsg::Exit) => return,
|
||||
Ok(_) => panic!("unexpected message"),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -158,13 +158,13 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
|||
// the last work unit in the queue, then send a message on the channel.
|
||||
unsafe {
|
||||
if (*ref_count).fetch_sub(1, SeqCst) == 1 {
|
||||
self.chan.send(FinishedMsg)
|
||||
self.chan.send(SupervisorMsg::Finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Give the deque back to the supervisor.
|
||||
self.chan.send(ReturnDequeMsg(self.index, deque))
|
||||
self.chan.send(SupervisorMsg::ReturnDeque(self.index, deque))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> {
|
|||
// Tell the workers to start.
|
||||
let mut work_count = AtomicUint::new(self.work_count);
|
||||
for worker in self.workers.iter_mut() {
|
||||
worker.chan.send(StartMsg(worker.deque.take().unwrap(), &mut work_count, &self.data))
|
||||
worker.chan.send(WorkerMsg::Start(worker.deque.take().unwrap(), &mut work_count, &self.data))
|
||||
}
|
||||
|
||||
// Wait for the work to finish.
|
||||
|
@ -292,21 +292,21 @@ impl<QueueData: Send, WorkData: Send> WorkQueue<QueueData, WorkData> {
|
|||
|
||||
// Tell everyone to stop.
|
||||
for worker in self.workers.iter() {
|
||||
worker.chan.send(StopMsg)
|
||||
worker.chan.send(WorkerMsg::Stop)
|
||||
}
|
||||
|
||||
// Get our deques back.
|
||||
for _ in range(0, self.workers.len()) {
|
||||
match self.port.recv() {
|
||||
ReturnDequeMsg(index, deque) => self.workers[index].deque = Some(deque),
|
||||
FinishedMsg => panic!("unexpected finished message!"),
|
||||
SupervisorMsg::ReturnDeque(index, deque) => self.workers[index].deque = Some(deque),
|
||||
SupervisorMsg::Finished => panic!("unexpected finished message!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shutdown(&mut self) {
|
||||
for worker in self.workers.iter() {
|
||||
worker.chan.send(ExitMsg)
|
||||
worker.chan.send(WorkerMsg::Exit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue