diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index fcc129e2cccc..c14652b1662c 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -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" diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 727760e57ed5..3c9bbc6b8fa5 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -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; diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 69e5ef4f17b2..acafbbc8f9b7 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -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; diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 7ad95f89b90d..a9271bc0cfd5 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -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; diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index 46f8351ba21e..e0c5c1fad1c0 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -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. /// diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index 7b8d49348c3a..09a7eae774a4 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -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; diff --git a/components/compositing/pipeline.rs b/components/compositing/pipeline.rs index 3c96524b18b0..06d85a2ca2a9 100644 --- a/components/compositing/pipeline.rs +++ b/components/compositing/pipeline.rs @@ -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; diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index c78bda489d15..aaefa6c900ce 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -20,8 +20,8 @@ path = "../util" [dependencies.msg] path = "../msg" -[dependencies.profile] -path = "../profile" +[dependencies.profile_traits] +path = "../profile_traits" [dependencies.style] path = "../style" diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 3e59c8305a6e..d44d52b54107 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -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; diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index a97487db92de..ba07f89bfa4f 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -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; diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 62a0e16ee652..27ca46a7f49a 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -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" diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 6166b95f73b4..dbcf03df1b03 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -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; diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 844689f0534e..876d8f7c425d 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -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; diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index 6699e44d4877..5d61e11a3d46 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -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}; diff --git a/components/layout_traits/Cargo.toml b/components/layout_traits/Cargo.toml index 02df09b7f2b8..17d706eeca36 100644 --- a/components/layout_traits/Cargo.toml +++ b/components/layout_traits/Cargo.toml @@ -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" diff --git a/components/layout_traits/lib.rs b/components/layout_traits/lib.rs index 406730f65d7e..f37cfa194bb5 100644 --- a/components/layout_traits/lib.rs +++ b/components/layout_traits/lib.rs @@ -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; diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 2f33836598c7..0548c6f00a95 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -7,9 +7,6 @@ authors = ["The Servo Project Developers"] name = "net" path = "lib.rs" -[dependencies.profile] -path = "../profile" - [dependencies.net_traits] path = "../net_traits" diff --git a/components/net/lib.rs b/components/net/lib.rs index cdc6217b706c..70f4a14db599 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -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; diff --git a/components/net_traits/Cargo.toml b/components/net_traits/Cargo.toml index f75b04eff499..bd336eb2a9c7 100644 --- a/components/net_traits/Cargo.toml +++ b/components/net_traits/Cargo.toml @@ -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" diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 55cb27a0519c..879643af2664 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -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; diff --git a/components/profile/Cargo.toml b/components/profile/Cargo.toml index de9fb13a5975..dfb3a187e30e 100644 --- a/components/profile/Cargo.toml +++ b/components/profile/Cargo.toml @@ -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" diff --git a/components/profile/lib.rs b/components/profile/lib.rs index 55a59065a4e5..3d6e91e5dcca 100644 --- a/components/profile/lib.rs +++ b/components/profile/lib.rs @@ -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; diff --git a/components/profile/mem.rs b/components/profile/mem.rs index 522ebe896b4e..bc8b84ac1bb6 100644 --- a/components/profile/mem.rs +++ b/components/profile/mem.rs @@ -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); - -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, - - /// The size, in bytes. - pub size: usize, -} - -/// A channel through which memory reports can be sent. -#[derive(Clone)] -pub struct ReportsChan(pub Sender>); - -impl ReportsChan { - pub fn send(&self, report: Vec) { - 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), - - /// 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, @@ -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}; diff --git a/components/profile/time.rs b/components/profile/time.rs index 8b85f4d8e7c0..284853a54803 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -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); - -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 { } } -#[derive(Clone)] -pub enum ProfilerMsg { - /// Normal message used for reporting time - Time((ProfilerCategory, Option), 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(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(msg: &str, callback: F) -> T where F: Fn() -> T { diff --git a/components/profile_traits/Cargo.toml b/components/profile_traits/Cargo.toml new file mode 100644 index 000000000000..eb9da970c20d --- /dev/null +++ b/components/profile_traits/Cargo.toml @@ -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" + diff --git a/components/profile_traits/lib.rs b/components/profile_traits/lib.rs new file mode 100644 index 000000000000..25dbb0b4c5b0 --- /dev/null +++ b/components/profile_traits/lib.rs @@ -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; diff --git a/components/profile_traits/mem.rs b/components/profile_traits/mem.rs new file mode 100644 index 000000000000..f31e6f733587 --- /dev/null +++ b/components/profile_traits/mem.rs @@ -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); + +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, + + /// The size, in bytes. + pub size: usize, +} + +/// A channel through which memory reports can be sent. +#[derive(Clone)] +pub struct ReportsChan(pub Sender>); + +impl ReportsChan { + pub fn send(&self, report: Vec) { + 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), + + /// 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, +} diff --git a/components/profile_traits/time.rs b/components/profile_traits/time.rs new file mode 100644 index 000000000000..5cd794072f9c --- /dev/null +++ b/components/profile_traits/time.rs @@ -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); + +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), 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(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; +} diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 50607cabefed..634c3e46d09d 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -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" diff --git a/components/script/layout_interface.rs b/components/script/layout_interface.rs index 4859c075058f..05046c3e564f 100644 --- a/components/script/layout_interface.rs +++ b/components/script/layout_interface.rs @@ -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}; diff --git a/components/script/lib.rs b/components/script/lib.rs index 5c2e522f5d4b..879216a2e279 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -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; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 5fdb4195f718..3adac4b1aa8a 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -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)", diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 24ab504b3033..2a57db1d9ee0 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -67,6 +67,9 @@ path = "../msg" [dependencies.profile] path = "../profile" +[dependencies.profile_traits] +path = "../profile_traits" + [dependencies.util] path = "../util" diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 22ec02646ef1..b7a45efa1de3 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -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) }); diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index ab2eb625afa5..cecc03294f78 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -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)", diff --git a/tests/unit/net/Cargo.toml b/tests/unit/net/Cargo.toml index 390d6f8ba018..5c265bfec6b6 100644 --- a/tests/unit/net/Cargo.toml +++ b/tests/unit/net/Cargo.toml @@ -14,9 +14,6 @@ path = "../../../components/net" [dependencies.net_traits] path = "../../../components/net_traits" -[dependencies.profile] -path = "../../../components/profile" - [dependencies.util] path = "../../../components/util" diff --git a/tests/unit/net/lib.rs b/tests/unit/net/lib.rs index f44c6fd54cde..959133da74f6 100644 --- a/tests/unit/net/lib.rs +++ b/tests/unit/net/lib.rs @@ -6,7 +6,6 @@ extern crate net; extern crate net_traits; -extern crate profile; extern crate url; extern crate util;