mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01: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
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue