mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add a profile_traits
crate to reduce compile times.
A rebuild after touching components/profile/mem.rs now takes 48 seconds (and only rebuilds `profile` and `servo`) which is much lower than it used to be. In comparison, a rebuild after touching components/profile_traits/mem.rs takes 294 seconds and rebuilds many more crates. This change also removes some unnecessary crate dependencies in `net` and `net_traits`.
This commit is contained in:
parent
826b722202
commit
092507d23c
37 changed files with 269 additions and 225 deletions
|
@ -22,8 +22,8 @@ path = "../msg"
|
|||
[dependencies.net]
|
||||
path = "../net"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
|
|
@ -32,8 +32,8 @@ use msg::constellation_msg::{ConstellationChan, NavigationDirection};
|
|||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
|
||||
use msg::constellation_msg::{PipelineId, WindowSizeData};
|
||||
use png;
|
||||
use profile::mem;
|
||||
use profile::time::{self, ProfilerCategory, profile};
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||
use script_traits::{ConstellationControlMsg, ScriptControlChan};
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
|
|
|
@ -21,8 +21,8 @@ use msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
|
|||
use msg::compositor_msg::{PaintListener, PaintState, ScriptListener, ScrollPolicy};
|
||||
use msg::constellation_msg::{ConstellationChan, PipelineId};
|
||||
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use std::fmt::{Error, Formatter, Debug};
|
||||
use std::rc::Rc;
|
||||
|
|
|
@ -23,8 +23,8 @@ use msg::constellation_msg::{self, ConstellationChan, Failure};
|
|||
use net_traits::{self, ResourceTask};
|
||||
use net_traits::image_cache_task::ImageCacheTask;
|
||||
use net_traits::storage_task::{StorageTask, StorageTaskMsg};
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use script_traits::{CompositorEvent, ConstellationControlMsg};
|
||||
use script_traits::{ScriptControlChan, ScriptTaskFactory};
|
||||
use std::borrow::ToOwned;
|
||||
|
|
|
@ -9,8 +9,8 @@ use geom::scale_factor::ScaleFactor;
|
|||
use geom::size::TypedSize2D;
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
|
||||
/// Starts the compositor, which listens for messages on the specified port.
|
||||
///
|
||||
|
|
|
@ -22,7 +22,7 @@ extern crate png;
|
|||
extern crate script_traits;
|
||||
extern crate msg;
|
||||
extern crate net;
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
extern crate net_traits;
|
||||
#[macro_use]
|
||||
extern crate util;
|
||||
|
|
|
@ -16,8 +16,8 @@ use gfx::font_cache_task::FontCacheTask;
|
|||
use layers::geometry::DevicePixel;
|
||||
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
|
||||
use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType, MozBrowserEvent};
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use net_traits::ResourceTask;
|
||||
use net_traits::image_cache_task::ImageCacheTask;
|
||||
use net_traits::storage_task::StorageTask;
|
||||
|
|
|
@ -20,8 +20,8 @@ path = "../util"
|
|||
[dependencies.msg]
|
||||
path = "../msg"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.style]
|
||||
path = "../style"
|
||||
|
|
|
@ -26,7 +26,7 @@ extern crate layers;
|
|||
extern crate libc;
|
||||
extern crate stb_image;
|
||||
extern crate png;
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate unicode;
|
||||
|
|
|
@ -25,7 +25,7 @@ use msg::compositor_msg::{LayerMetadata, PaintListener, ScrollPolicy};
|
|||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
|
||||
use msg::constellation_msg::PipelineExitType;
|
||||
use profile::time::{self, profile};
|
||||
use profile_traits::time::{self, profile};
|
||||
use skia::SkiaGrGLNativeContextRef;
|
||||
use std::borrow::ToOwned;
|
||||
use std::mem;
|
||||
|
|
|
@ -37,8 +37,8 @@ path = "../plugins"
|
|||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
|
|
@ -42,9 +42,9 @@ use log;
|
|||
use msg::compositor_msg::ScrollPolicy;
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
|
||||
use profile::mem::{self, Report, ReportsChan};
|
||||
use profile::time::{self, ProfilerMetadata, profile};
|
||||
use profile::time::{TimerMetadataFrameType, TimerMetadataReflowType};
|
||||
use profile_traits::mem::{self, Report, ReportsChan};
|
||||
use profile_traits::time::{self, ProfilerMetadata, profile};
|
||||
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
|
||||
use net_traits::{load_bytes_iter, ResourceTask};
|
||||
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheResult, ImageCacheChan};
|
||||
use script::dom::bindings::js::LayoutJS;
|
||||
|
|
|
@ -32,7 +32,7 @@ extern crate bitflags;
|
|||
extern crate "plugins" as servo_plugins;
|
||||
extern crate net_traits;
|
||||
#[macro_use]
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
|
||||
#[macro_use]
|
||||
extern crate util;
|
||||
|
|
|
@ -20,7 +20,7 @@ use wrapper::{layout_node_to_unsafe_layout_node, layout_node_from_unsafe_layout_
|
|||
use wrapper::{PostorderNodeMutTraversal, UnsafeLayoutNode};
|
||||
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};
|
||||
|
||||
use profile::time::{self, ProfilerMetadata, profile};
|
||||
use profile_traits::time::{self, ProfilerMetadata, profile};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::sync::atomic::{AtomicIsize, Ordering};
|
||||
|
|
|
@ -19,8 +19,8 @@ path = "../msg"
|
|||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
extern crate gfx;
|
||||
extern crate script_traits;
|
||||
extern crate msg;
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
extern crate net_traits;
|
||||
extern crate url;
|
||||
extern crate util;
|
||||
|
@ -18,8 +18,8 @@ extern crate util;
|
|||
use gfx::font_cache_task::FontCacheTask;
|
||||
use gfx::paint_task::PaintChan;
|
||||
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, PipelineExitType};
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use net_traits::ResourceTask;
|
||||
use net_traits::image_cache_task::ImageCacheTask;
|
||||
use url::Url;
|
||||
|
|
|
@ -7,9 +7,6 @@ authors = ["The Servo Project Developers"]
|
|||
name = "net"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
|
||||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ extern crate png;
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate openssl;
|
||||
extern crate profile;
|
||||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate util;
|
||||
extern crate time;
|
||||
|
|
|
@ -13,9 +13,6 @@ git = "https://github.com/servo/rust-geom"
|
|||
[dependencies.png]
|
||||
git = "https://github.com/servo/rust-png"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ extern crate hyper;
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate png;
|
||||
extern crate profile;
|
||||
extern crate stb_image;
|
||||
extern crate url;
|
||||
extern crate util;
|
||||
|
|
|
@ -7,6 +7,9 @@ authors = ["The Servo Project Developers"]
|
|||
name = "profile"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.task_info]
|
||||
path = "../../support/rust-task_info"
|
||||
|
||||
|
@ -17,4 +20,3 @@ path = "../util"
|
|||
libc = "*"
|
||||
regex = "0.1.14"
|
||||
time = "0.1.12"
|
||||
url = "0.2.16"
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
|
||||
extern crate collections;
|
||||
extern crate libc;
|
||||
#[macro_use]
|
||||
extern crate profile_traits;
|
||||
#[cfg(target_os="linux")]
|
||||
extern crate regex;
|
||||
#[cfg(target_os="macos")]
|
||||
extern crate task_info;
|
||||
extern crate "time" as std_time;
|
||||
extern crate util;
|
||||
extern crate url;
|
||||
|
||||
pub mod mem;
|
||||
pub mod time;
|
||||
|
|
|
@ -4,83 +4,16 @@
|
|||
|
||||
//! Memory profiling functions.
|
||||
|
||||
use profile_traits::mem::{ProfilerChan, ProfilerMsg, Reporter, ReportsChan};
|
||||
use self::system_reporter::SystemReporter;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::old_io::timer::sleep;
|
||||
use std::sync::mpsc::{Sender, channel, Receiver};
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use std::time::duration::Duration;
|
||||
use util::task::spawn_named;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProfilerChan(pub Sender<ProfilerMsg>);
|
||||
|
||||
impl ProfilerChan {
|
||||
pub fn send(&self, msg: ProfilerMsg) {
|
||||
let ProfilerChan(ref c) = *self;
|
||||
c.send(msg).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// An easy way to build a path for a report.
|
||||
#[macro_export]
|
||||
macro_rules! path {
|
||||
($($x:expr),*) => {{
|
||||
use std::borrow::ToOwned;
|
||||
vec![$( $x.to_owned() ),*]
|
||||
}}
|
||||
}
|
||||
|
||||
/// A single memory-related measurement.
|
||||
pub struct Report {
|
||||
/// The identifying path for this report.
|
||||
pub path: Vec<String>,
|
||||
|
||||
/// The size, in bytes.
|
||||
pub size: usize,
|
||||
}
|
||||
|
||||
/// A channel through which memory reports can be sent.
|
||||
#[derive(Clone)]
|
||||
pub struct ReportsChan(pub Sender<Vec<Report>>);
|
||||
|
||||
impl ReportsChan {
|
||||
pub fn send(&self, report: Vec<Report>) {
|
||||
let ReportsChan(ref c) = *self;
|
||||
c.send(report).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory reporter is capable of measuring some data structure of interest. Because it needs
|
||||
/// to be passed to and registered with the Profiler, it's typically a "small" (i.e. easily
|
||||
/// cloneable) value that provides access to a "large" data structure, e.g. a channel that can
|
||||
/// inject a request for measurements into the event queue associated with the "large" data
|
||||
/// structure.
|
||||
pub trait Reporter {
|
||||
/// Collect one or more memory reports. Returns true on success, and false on failure.
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) -> bool;
|
||||
}
|
||||
|
||||
/// Messages that can be sent to the memory profiler thread.
|
||||
pub enum ProfilerMsg {
|
||||
/// Register a Reporter with the memory profiler. The String is only used to identify the
|
||||
/// reporter so it can be unregistered later. The String must be distinct from that used by any
|
||||
/// other registered reporter otherwise a panic will occur.
|
||||
RegisterReporter(String, Box<Reporter + Send>),
|
||||
|
||||
/// Unregister a Reporter with the memory profiler. The String must match the name given when
|
||||
/// the reporter was registered. If the String does not match the name of a registered reporter
|
||||
/// a panic will occur.
|
||||
UnregisterReporter(String),
|
||||
|
||||
/// Triggers printing of the memory profiling metrics.
|
||||
Print,
|
||||
|
||||
/// Tells the memory profiler to shut down.
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub struct Profiler {
|
||||
/// The port through which messages are received.
|
||||
pub port: Receiver<ProfilerMsg>,
|
||||
|
@ -363,11 +296,11 @@ impl ReportsForest {
|
|||
|
||||
mod system_reporter {
|
||||
use libc::{c_char, c_int, c_void, size_t};
|
||||
use profile_traits::mem::{Report, Reporter, ReportsChan};
|
||||
use std::borrow::ToOwned;
|
||||
use std::ffi::CString;
|
||||
use std::mem::size_of;
|
||||
use std::ptr::null_mut;
|
||||
use super::{Report, Reporter, ReportsChan};
|
||||
#[cfg(target_os="macos")]
|
||||
use task_info::task_basic_info::{virtual_size, resident_size};
|
||||
|
||||
|
|
|
@ -5,36 +5,18 @@
|
|||
//! Timing functions.
|
||||
|
||||
use collections::BTreeMap;
|
||||
use profile_traits::time::{ProfilerCategory, ProfilerChan, ProfilerMsg, TimerMetadata};
|
||||
use std::borrow::ToOwned;
|
||||
use std::cmp::Ordering;
|
||||
use std::f64;
|
||||
use std::old_io::timer::sleep;
|
||||
use std::iter::AdditiveIterator;
|
||||
use std::num::Float;
|
||||
use std::sync::mpsc::{Sender, channel, Receiver};
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use std::time::duration::Duration;
|
||||
use std_time::precise_time_ns;
|
||||
use url::Url;
|
||||
use util::task::spawn_named;
|
||||
|
||||
// front-end representation of the profiler used to communicate with the profiler
|
||||
#[derive(Clone)]
|
||||
pub struct ProfilerChan(pub Sender<ProfilerMsg>);
|
||||
|
||||
impl ProfilerChan {
|
||||
pub fn send(&self, msg: ProfilerMsg) {
|
||||
let ProfilerChan(ref c) = *self;
|
||||
c.send(msg).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, PartialOrd, Eq, Ord)]
|
||||
pub struct TimerMetadata {
|
||||
url: String,
|
||||
iframe: bool,
|
||||
incremental: bool,
|
||||
}
|
||||
|
||||
pub trait Formattable {
|
||||
fn format(&self) -> String;
|
||||
}
|
||||
|
@ -60,38 +42,6 @@ impl Formattable for Option<TimerMetadata> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ProfilerMsg {
|
||||
/// Normal message used for reporting time
|
||||
Time((ProfilerCategory, Option<TimerMetadata>), f64),
|
||||
/// Message used to force print the profiling metrics
|
||||
Print,
|
||||
/// Tells the profiler to shut down.
|
||||
Exit,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(PartialEq, Clone, PartialOrd, Eq, Ord)]
|
||||
pub enum ProfilerCategory {
|
||||
Compositing,
|
||||
LayoutPerform,
|
||||
LayoutStyleRecalc,
|
||||
LayoutRestyleDamagePropagation,
|
||||
LayoutNonIncrementalReset,
|
||||
LayoutSelectorMatch,
|
||||
LayoutTreeBuilder,
|
||||
LayoutDamagePropagate,
|
||||
LayoutGeneratedContent,
|
||||
LayoutMain,
|
||||
LayoutParallelWarmup,
|
||||
LayoutShaping,
|
||||
LayoutDispListBuild,
|
||||
PaintingPerTile,
|
||||
PaintingPrepBuff,
|
||||
Painting,
|
||||
ImageDecoding,
|
||||
}
|
||||
|
||||
impl Formattable for ProfilerCategory {
|
||||
// some categories are subcategories of LayoutPerformCategory
|
||||
// and should be printed to indicate this
|
||||
|
@ -254,41 +204,6 @@ impl Profiler {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum TimerMetadataFrameType {
|
||||
RootWindow,
|
||||
IFrame,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum TimerMetadataReflowType {
|
||||
Incremental,
|
||||
FirstReflow,
|
||||
}
|
||||
|
||||
pub type ProfilerMetadata<'a> = Option<(&'a Url, TimerMetadataFrameType, TimerMetadataReflowType)>;
|
||||
|
||||
pub fn profile<T, F>(category: ProfilerCategory,
|
||||
meta: ProfilerMetadata,
|
||||
profiler_chan: ProfilerChan,
|
||||
callback: F)
|
||||
-> T
|
||||
where F: FnOnce() -> T
|
||||
{
|
||||
let start_time = precise_time_ns();
|
||||
let val = callback();
|
||||
let end_time = precise_time_ns();
|
||||
let ms = (end_time - start_time) as f64 / 1000000f64;
|
||||
let meta = meta.map(|(url, iframe, reflow_type)|
|
||||
TimerMetadata {
|
||||
url: url.serialize(),
|
||||
iframe: iframe == TimerMetadataFrameType::IFrame,
|
||||
incremental: reflow_type == TimerMetadataReflowType::Incremental,
|
||||
});
|
||||
profiler_chan.send(ProfilerMsg::Time((category, meta), ms));
|
||||
return val;
|
||||
}
|
||||
|
||||
pub fn time<T, F>(msg: &str, callback: F) -> T
|
||||
where F: Fn() -> T
|
||||
{
|
||||
|
|
13
components/profile_traits/Cargo.toml
Normal file
13
components/profile_traits/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "profile_traits"
|
||||
version = "0.0.1"
|
||||
authors = ["The Servo Project Developers"]
|
||||
|
||||
[lib]
|
||||
name = "profile_traits"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
time = "0.1.12"
|
||||
url = "0.2.16"
|
||||
|
6
components/profile_traits/lib.rs
Normal file
6
components/profile_traits/lib.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
pub mod mem;
|
||||
pub mod time;
|
72
components/profile_traits/mem.rs
Normal file
72
components/profile_traits/mem.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProfilerChan(pub Sender<ProfilerMsg>);
|
||||
|
||||
impl ProfilerChan {
|
||||
pub fn send(&self, msg: ProfilerMsg) {
|
||||
let ProfilerChan(ref c) = *self;
|
||||
c.send(msg).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A single memory-related measurement.
|
||||
pub struct Report {
|
||||
/// The identifying path for this report.
|
||||
pub path: Vec<String>,
|
||||
|
||||
/// The size, in bytes.
|
||||
pub size: usize,
|
||||
}
|
||||
|
||||
/// A channel through which memory reports can be sent.
|
||||
#[derive(Clone)]
|
||||
pub struct ReportsChan(pub Sender<Vec<Report>>);
|
||||
|
||||
impl ReportsChan {
|
||||
pub fn send(&self, report: Vec<Report>) {
|
||||
let ReportsChan(ref c) = *self;
|
||||
c.send(report).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory reporter is capable of measuring some data structure of interest. Because it needs to
|
||||
/// be passed to and registered with the Profiler, it's typically a "small" (i.e. easily cloneable)
|
||||
/// value that provides access to a "large" data structure, e.g. a channel that can inject a
|
||||
/// request for measurements into the event queue associated with the "large" data structure.
|
||||
pub trait Reporter {
|
||||
/// Collect one or more memory reports. Returns true on success, and false on failure.
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) -> bool;
|
||||
}
|
||||
|
||||
/// An easy way to build a path for a report.
|
||||
#[macro_export]
|
||||
macro_rules! path {
|
||||
($($x:expr),*) => {{
|
||||
use std::borrow::ToOwned;
|
||||
vec![$( $x.to_owned() ),*]
|
||||
}}
|
||||
}
|
||||
|
||||
/// Messages that can be sent to the memory profiler thread.
|
||||
pub enum ProfilerMsg {
|
||||
/// Register a Reporter with the memory profiler. The String is only used to identify the
|
||||
/// reporter so it can be unregistered later. The String must be distinct from that used by any
|
||||
/// other registered reporter otherwise a panic will occur.
|
||||
RegisterReporter(String, Box<Reporter + Send>),
|
||||
|
||||
/// Unregister a Reporter with the memory profiler. The String must match the name given when
|
||||
/// the reporter was registered. If the String does not match the name of a registered reporter
|
||||
/// a panic will occur.
|
||||
UnregisterReporter(String),
|
||||
|
||||
/// Triggers printing of the memory profiling metrics.
|
||||
Print,
|
||||
|
||||
/// Tells the memory profiler to shut down.
|
||||
Exit,
|
||||
}
|
95
components/profile_traits/time.rs
Normal file
95
components/profile_traits/time.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate "time" as std_time;
|
||||
extern crate url;
|
||||
|
||||
use self::std_time::precise_time_ns;
|
||||
use self::url::Url;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
#[derive(PartialEq, Clone, PartialOrd, Eq, Ord)]
|
||||
pub struct TimerMetadata {
|
||||
pub url: String,
|
||||
pub iframe: bool,
|
||||
pub incremental: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProfilerChan(pub Sender<ProfilerMsg>);
|
||||
|
||||
impl ProfilerChan {
|
||||
pub fn send(&self, msg: ProfilerMsg) {
|
||||
let ProfilerChan(ref c) = *self;
|
||||
c.send(msg).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ProfilerMsg {
|
||||
/// Normal message used for reporting time
|
||||
Time((ProfilerCategory, Option<TimerMetadata>), f64),
|
||||
/// Message used to force print the profiling metrics
|
||||
Print,
|
||||
/// Tells the profiler to shut down.
|
||||
Exit,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(PartialEq, Clone, PartialOrd, Eq, Ord)]
|
||||
pub enum ProfilerCategory {
|
||||
Compositing,
|
||||
LayoutPerform,
|
||||
LayoutStyleRecalc,
|
||||
LayoutRestyleDamagePropagation,
|
||||
LayoutNonIncrementalReset,
|
||||
LayoutSelectorMatch,
|
||||
LayoutTreeBuilder,
|
||||
LayoutDamagePropagate,
|
||||
LayoutGeneratedContent,
|
||||
LayoutMain,
|
||||
LayoutParallelWarmup,
|
||||
LayoutShaping,
|
||||
LayoutDispListBuild,
|
||||
PaintingPerTile,
|
||||
PaintingPrepBuff,
|
||||
Painting,
|
||||
ImageDecoding,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum TimerMetadataFrameType {
|
||||
RootWindow,
|
||||
IFrame,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum TimerMetadataReflowType {
|
||||
Incremental,
|
||||
FirstReflow,
|
||||
}
|
||||
|
||||
pub type ProfilerMetadata<'a> =
|
||||
Option<(&'a Url, TimerMetadataFrameType, TimerMetadataReflowType)>;
|
||||
|
||||
pub fn profile<T, F>(category: ProfilerCategory,
|
||||
meta: ProfilerMetadata,
|
||||
profiler_chan: ProfilerChan,
|
||||
callback: F)
|
||||
-> T
|
||||
where F: FnOnce() -> T
|
||||
{
|
||||
let start_time = precise_time_ns();
|
||||
let val = callback();
|
||||
let end_time = precise_time_ns();
|
||||
let ms = (end_time - start_time) as f64 / 1000000f64;
|
||||
let meta = meta.map(|(url, iframe, reflow_type)|
|
||||
TimerMetadata {
|
||||
url: url.serialize(),
|
||||
iframe: iframe == TimerMetadataFrameType::IFrame,
|
||||
incremental: reflow_type == TimerMetadataReflowType::Incremental,
|
||||
});
|
||||
profiler_chan.send(ProfilerMsg::Time((category, meta), ms));
|
||||
return val;
|
||||
}
|
|
@ -24,8 +24,8 @@ path = "../msg"
|
|||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.script_traits]
|
||||
path = "../script_traits"
|
||||
|
|
|
@ -12,7 +12,7 @@ use geom::point::Point2D;
|
|||
use geom::rect::Rect;
|
||||
use libc::uintptr_t;
|
||||
use msg::constellation_msg::{PipelineExitType, WindowSizeData};
|
||||
use profile::mem::{Reporter, ReportsChan};
|
||||
use profile_traits::mem::{Reporter, ReportsChan};
|
||||
use script_traits::{ScriptControlChan, OpaqueScriptLayoutChannel, UntrustedNodeAddress};
|
||||
use std::any::Any;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
|
|
|
@ -43,7 +43,7 @@ extern crate png;
|
|||
extern crate "rustc-serialize" as rustc_serialize;
|
||||
extern crate time;
|
||||
extern crate canvas;
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
extern crate selectors;
|
||||
extern crate util;
|
||||
|
|
24
components/servo/Cargo.lock
generated
24
components/servo/Cargo.lock
generated
|
@ -17,6 +17,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script 0.0.1",
|
||||
"script_tests 0.0.1",
|
||||
"style_tests 0.0.1",
|
||||
|
@ -121,7 +122,7 @@ dependencies = [
|
|||
"net 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -348,7 +349,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script_traits 0.0.1",
|
||||
"skia 0.0.20130412 (git+https://github.com/servo/skia?branch=upstream-2014-06-16)",
|
||||
|
@ -561,7 +562,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
|
@ -580,7 +581,7 @@ dependencies = [
|
|||
"gfx 0.0.1",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
@ -674,7 +675,6 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"openssl 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex_macros 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -691,7 +691,6 @@ dependencies = [
|
|||
"hyper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"net 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile 0.0.1",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
@ -703,7 +702,6 @@ dependencies = [
|
|||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||
"hyper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
@ -809,13 +807,21 @@ name = "profile"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"profile_traits 0.0.1",
|
||||
"regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"task_info 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "profile_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.1.4"
|
||||
|
@ -862,7 +868,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script_traits 0.0.1",
|
||||
"selectors 0.1.0 (git+https://github.com/servo/rust-selectors)",
|
||||
|
|
|
@ -67,6 +67,9 @@ path = "../msg"
|
|||
[dependencies.profile]
|
||||
path = "../profile"
|
||||
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ extern crate net;
|
|||
extern crate net_traits;
|
||||
extern crate msg;
|
||||
extern crate profile;
|
||||
extern crate profile_traits;
|
||||
#[macro_use]
|
||||
extern crate util;
|
||||
extern crate script;
|
||||
|
@ -52,8 +53,10 @@ use net::resource_task::new_resource_task;
|
|||
use net_traits::storage_task::StorageTask;
|
||||
|
||||
use gfx::font_cache_task::FontCacheTask;
|
||||
use profile::mem;
|
||||
use profile::time;
|
||||
use profile::mem as profile_mem;
|
||||
use profile::time as profile_time;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use util::opts;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
@ -92,8 +95,8 @@ impl Browser {
|
|||
// to deliver the message.
|
||||
let (compositor_proxy, compositor_receiver) =
|
||||
WindowMethods::create_compositor_channel(&window);
|
||||
let time_profiler_chan = time::Profiler::create(opts.time_profiler_period);
|
||||
let mem_profiler_chan = mem::Profiler::create(opts.mem_profiler_period);
|
||||
let time_profiler_chan = profile_time::Profiler::create(opts.time_profiler_period);
|
||||
let mem_profiler_chan = profile_mem::Profiler::create(opts.mem_profiler_period);
|
||||
let devtools_chan = opts.devtools_port.map(|port| {
|
||||
devtools::start_server(port)
|
||||
});
|
||||
|
|
23
ports/cef/Cargo.lock
generated
23
ports/cef/Cargo.lock
generated
|
@ -119,7 +119,7 @@ dependencies = [
|
|||
"net 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -346,7 +346,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script_traits 0.0.1",
|
||||
"skia 0.0.20130412 (git+https://github.com/servo/skia?branch=upstream-2014-06-16)",
|
||||
|
@ -552,7 +552,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
|
@ -571,7 +571,7 @@ dependencies = [
|
|||
"gfx 0.0.1",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
@ -665,7 +665,6 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"openssl 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex_macros 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -681,7 +680,6 @@ dependencies = [
|
|||
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
|
||||
"hyper 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
@ -787,13 +785,21 @@ name = "profile"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"profile_traits 0.0.1",
|
||||
"regex 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"task_info 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "profile_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.1.4"
|
||||
|
@ -840,7 +846,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"rustc-serialize 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script_traits 0.0.1",
|
||||
"selectors 0.1.0 (git+https://github.com/servo/rust-selectors)",
|
||||
|
@ -896,6 +902,7 @@ dependencies = [
|
|||
"net_traits 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"script 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -14,9 +14,6 @@ path = "../../../components/net"
|
|||
[dependencies.net_traits]
|
||||
path = "../../../components/net_traits"
|
||||
|
||||
[dependencies.profile]
|
||||
path = "../../../components/profile"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../../../components/util"
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
extern crate net;
|
||||
extern crate net_traits;
|
||||
extern crate profile;
|
||||
extern crate url;
|
||||
extern crate util;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue