Skip to content

Commit

Permalink
Move profiler code from util into a new crate profile.
Browse files Browse the repository at this point in the history
- Most of util::memory has been moved into profile::mem, though the
  `SizeOf` trait and related things remain in util::memory. The
  `SystemMemoryReporter` code is now in a submodule
  profile::mem::system_reporter.

- util::time has been moved entirely into profile::time.
  • Loading branch information
nnethercote committed Mar 24, 2015
1 parent cad58b3 commit 52447cc
Show file tree
Hide file tree
Showing 36 changed files with 850 additions and 726 deletions.
5 changes: 4 additions & 1 deletion components/compositing/Cargo.toml
Expand Up @@ -22,6 +22,9 @@ path = "../msg"
[dependencies.net]
path = "../net"

[dependencies.profile]
path = "../profile"

[dependencies.util]
path = "../util"

Expand Down Expand Up @@ -52,4 +55,4 @@ git = "https://github.com/servo/gleam"
[dependencies]
url = "0.2.16"
time = "0.1.17"
libc = "*"
libc = "*"
19 changes: 10 additions & 9 deletions components/compositing/compositor.rs
Expand Up @@ -11,8 +11,6 @@ use scrolling::ScrollingTimerProxy;
use windowing;
use windowing::{MouseWindowEvent, WindowEvent, WindowMethods, WindowNavigateMsg};

use std::cmp;
use std::mem;
use geom::point::{Point2D, TypedPoint2D};
use geom::rect::{Rect, TypedRect};
use geom::size::{Size2D, TypedSize2D};
Expand All @@ -35,20 +33,23 @@ use msg::constellation_msg::{ConstellationChan, NavigationDirection};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
use msg::constellation_msg::{PipelineId, WindowSizeData};
use util::geometry::{PagePx, ScreenPx, ViewportPx};
use util::memory::MemoryProfilerChan;
use util::opts;
use util::time::{TimeProfilerCategory, profile, TimeProfilerChan};
use util::{memory, time};
use profile::mem;
use profile::mem::{MemoryProfilerChan};
use profile::time;
use profile::time::{TimeProfilerCategory, profile, TimeProfilerChan};
use std::cmp;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::old_path::Path;
use std::mem::replace;
use std::num::Float;
use std::rc::Rc;
use std::slice::bytes::copy_memory;
use std::sync::mpsc::Sender;
use time::{precise_time_ns, precise_time_s};
use url::Url;
use util::geometry::{PagePx, ScreenPx, ViewportPx};
use util::opts;

/// NB: Never block on the constellation, because sometimes the constellation blocks on us.
pub struct IOCompositor<Window: WindowMethods> {
Expand Down Expand Up @@ -869,7 +870,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {

fn process_pending_scroll_events(&mut self) {
let had_scroll_events = self.pending_scroll_events.len() > 0;
for scroll_event in mem::replace(&mut self.pending_scroll_events, Vec::new()).into_iter() {
for scroll_event in replace(&mut self.pending_scroll_events, Vec::new()).into_iter() {
let delta = scroll_event.delta / self.scene.scale;
let cursor = scroll_event.cursor.as_f32() / self.scene.scale;

Expand Down Expand Up @@ -1356,7 +1357,7 @@ impl<Window> CompositorEventListener for IOCompositor<Window> where Window: Wind

// Tell the profiler, memory profiler, and scrolling timer to shut down.
self.time_profiler_chan.send(time::TimeProfilerMsg::Exit);
self.memory_profiler_chan.send(memory::MemoryProfilerMsg::Exit);
self.memory_profiler_chan.send(mem::MemoryProfilerMsg::Exit);
self.scrolling_timer.shutdown();
}

Expand Down
8 changes: 4 additions & 4 deletions components/compositing/compositor_task.rs
Expand Up @@ -21,13 +21,13 @@ 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 url::Url;
use util::cursor::Cursor;
use util::memory::MemoryProfilerChan;
use util::time::TimeProfilerChan;
use profile::mem::MemoryProfilerChan;
use profile::time::TimeProfilerChan;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::fmt::{Error, Formatter, Debug};
use std::rc::Rc;
use url::Url;
use util::cursor::Cursor;

/// Sends messages to the compositor. This is a trait supplied by the port because the method used
/// to communicate with the compositor may have to kick OS event loops awake, communicate cross-
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/constellation.rs
Expand Up @@ -25,12 +25,12 @@ use msg::constellation_msg::Msg as ConstellationMsg;
use net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use net::resource_task::{self, ResourceTask};
use net::storage_task::{StorageTask, StorageTaskMsg};
use profile::mem::MemoryProfilerChan;
use profile::time::TimeProfilerChan;
use util::cursor::Cursor;
use util::geometry::PagePx;
use util::memory::MemoryProfilerChan;
use util::opts;
use util::task::spawn_named;
use util::time::TimeProfilerChan;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::old_io as io;
Expand Down
10 changes: 5 additions & 5 deletions components/compositing/headless.rs
Expand Up @@ -9,10 +9,10 @@ use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
use util::memory::MemoryProfilerChan;
use util::memory;
use util::time::TimeProfilerChan;
use util::time;
use profile::mem;
use profile::mem::MemoryProfilerChan;
use profile::time;
use profile::time::TimeProfilerChan;

/// Starts the compositor, which listens for messages on the specified port.
///
Expand Down Expand Up @@ -121,7 +121,7 @@ impl CompositorEventListener for NullCompositor {
while self.port.try_recv_compositor_msg().is_some() {}

self.time_profiler_chan.send(time::TimeProfilerMsg::Exit);
self.memory_profiler_chan.send(memory::MemoryProfilerMsg::Exit);
self.memory_profiler_chan.send(mem::MemoryProfilerMsg::Exit);
}

fn pinch_zoom_level(&self) -> f32 {
Expand Down
1 change: 1 addition & 0 deletions components/compositing/lib.rs
Expand Up @@ -23,6 +23,7 @@ extern crate png;
extern crate script_traits;
extern crate msg;
extern crate net;
extern crate profile;
#[macro_use]
extern crate util;
extern crate gleam;
Expand Down
6 changes: 3 additions & 3 deletions components/compositing/pipeline.rs
Expand Up @@ -19,11 +19,11 @@ use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType};
use net::image_cache_task::ImageCacheTask;
use net::resource_task::ResourceTask;
use net::storage_task::StorageTask;
use profile::mem::MemoryProfilerChan;
use profile::time::TimeProfilerChan;
use std::sync::mpsc::{Receiver, channel};
use url::Url;
use util::geometry::{PagePx, ViewportPx};
use util::memory::MemoryProfilerChan;
use util::time::TimeProfilerChan;
use std::sync::mpsc::{Receiver, channel};

/// A uniquely-identifiable pipeline of script task, layout task, and paint task.
pub struct Pipeline {
Expand Down
3 changes: 3 additions & 0 deletions components/gfx/Cargo.toml
Expand Up @@ -20,6 +20,9 @@ path = "../util"
[dependencies.msg]
path = "../msg"

[dependencies.profile]
path = "../profile"

[dependencies.style]
path = "../style"

Expand Down
1 change: 1 addition & 0 deletions components/gfx/lib.rs
Expand Up @@ -27,6 +27,7 @@ extern crate layers;
extern crate libc;
extern crate stb_image;
extern crate png;
extern crate profile;
extern crate script_traits;
extern crate "rustc-serialize" as rustc_serialize;
extern crate unicode;
Expand Down
10 changes: 5 additions & 5 deletions components/gfx/paint_task.rs
Expand Up @@ -25,17 +25,17 @@ 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::{TimeProfilerChan, TimeProfilerCategory, profile};
use skia::SkiaGrGLNativeContextRef;
use std::mem;
use std::thread::Builder;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use util::geometry::{Au, ZERO_POINT};
use util::opts;
use util::smallvec::SmallVec;
use util::task::spawn_named_with_send_on_failure;
use util::task_state;
use util::time::{TimeProfilerChan, TimeProfilerCategory, profile};
use std::mem;
use std::thread::Builder;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};

/// Information about a hardware graphics layer that layout sends to the painting task.
#[derive(Clone)]
Expand Down
3 changes: 3 additions & 0 deletions components/layout/Cargo.toml
Expand Up @@ -37,6 +37,9 @@ path = "../plugins"
[dependencies.net]
path = "../net"

[dependencies.profile]
path = "../profile"

[dependencies.util]
path = "../util"

Expand Down
6 changes: 3 additions & 3 deletions components/layout/layout_task.rs
Expand Up @@ -43,6 +43,9 @@ use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, Pipel
use net::image_cache_task::{ImageCacheTask, ImageResponseMsg};
use net::local_image_cache::{ImageResponder, LocalImageCache};
use net::resource_task::{ResourceTask, load_bytes_iter};
use profile::mem::{MemoryProfilerChan, MemoryProfilerMsg, MemoryReport, MemoryReportsChan};
use profile::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan};
use profile::time::{TimerMetadataFrameType, TimerMetadataReflowType, profile};
use script::dom::bindings::js::LayoutJS;
use script::dom::element::ElementTypeId;
use script::dom::htmlelement::HTMLElementTypeId;
Expand Down Expand Up @@ -70,14 +73,11 @@ use url::Url;
use util::cursor::Cursor;
use util::geometry::Au;
use util::logical_geometry::LogicalPoint;
use util::memory::{MemoryProfilerChan, MemoryProfilerMsg, MemoryReport, MemoryReportsChan};
use util::memory::{SizeOf};
use util::opts;
use util::smallvec::{SmallVec, SmallVec1, VecLike};
use util::task::spawn_named_with_send_on_failure;
use util::task_state;
use util::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan};
use util::time::{TimerMetadataFrameType, TimerMetadataReflowType, profile};
use util::workqueue::WorkQueue;

/// Mutable data belonging to the LayoutTask.
Expand Down
2 changes: 2 additions & 0 deletions components/layout/lib.rs
Expand Up @@ -43,6 +43,8 @@ extern crate style;
extern crate "plugins" as servo_plugins;
extern crate net;
extern crate msg;
#[macro_use]
extern crate profile;
extern crate selectors;
#[macro_use]
extern crate util;
Expand Down
6 changes: 3 additions & 3 deletions components/layout/parallel.rs
Expand Up @@ -20,12 +20,12 @@ use wrapper::{layout_node_to_unsafe_layout_node, layout_node_from_unsafe_layout_
use wrapper::{PostorderNodeMutTraversal, UnsafeLayoutNode};
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};

use util::opts;
use util::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan, profile};
use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};
use profile::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan, profile};
use std::mem;
use std::ptr;
use std::sync::atomic::{AtomicIsize, Ordering};
use util::opts;
use util::workqueue::{WorkQueue, WorkUnit, WorkerProxy};

#[allow(dead_code)]
fn static_assertion(node: UnsafeLayoutNode) {
Expand Down
3 changes: 3 additions & 0 deletions components/layout_traits/Cargo.toml
Expand Up @@ -19,6 +19,9 @@ path = "../msg"
[dependencies.net]
path = "../net"

[dependencies.profile]
path = "../profile"

[dependencies.util]
path = "../util"

Expand Down
7 changes: 4 additions & 3 deletions components/layout_traits/lib.rs
Expand Up @@ -6,6 +6,7 @@ extern crate gfx;
extern crate script_traits;
extern crate msg;
extern crate net;
extern crate profile;
extern crate url;
extern crate util;

Expand All @@ -19,11 +20,11 @@ use gfx::paint_task::PaintChan;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, PipelineExitType};
use net::image_cache_task::ImageCacheTask;
use net::resource_task::ResourceTask;
use url::Url;
use util::memory::MemoryProfilerChan;
use util::time::TimeProfilerChan;
use profile::mem::MemoryProfilerChan;
use profile::time::TimeProfilerChan;
use script_traits::{ScriptControlChan, OpaqueScriptLayoutChannel};
use std::sync::mpsc::{Sender, Receiver};
use url::Url;

/// Messages sent to the layout task from the constellation
pub enum LayoutControlMsg {
Expand Down
3 changes: 3 additions & 0 deletions components/net/Cargo.toml
Expand Up @@ -7,6 +7,9 @@ authors = ["The Servo Project Developers"]
name = "net"
path = "lib.rs"

[dependencies.profile]
path = "../profile"

[dependencies.util]
path = "../util"

Expand Down
10 changes: 5 additions & 5 deletions components/net/image_cache_task.rs
Expand Up @@ -7,16 +7,16 @@ use resource_task;
use resource_task::{LoadData, ResourceTask};
use resource_task::ProgressMsg::{Payload, Done};

use util::task::spawn_named;
use util::taskpool::TaskPool;
use util::time::{self, profile, TimeProfilerChan};
use profile::time::{self, profile, TimeProfilerChan};
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::mem::replace;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{channel, Receiver, Sender};
use url::Url;
use util::task::spawn_named;
use util::taskpool::TaskPool;

pub enum Msg {
/// Tell the cache that we may need a particular image soon. Must be posted
Expand Down Expand Up @@ -495,10 +495,10 @@ mod tests {
use resource_task::ProgressMsg::{Payload, Done};
use sniffer_task;
use image::base::test_image_bin;
use util::taskpool::TaskPool;
use util::time::{TimeProfiler, TimeProfilerChan};
use profile::time::{TimeProfiler, TimeProfilerChan};
use std::sync::mpsc::{Sender, channel, Receiver};
use url::Url;
use util::taskpool::TaskPool;

trait Closure {
fn invoke(&self, _response: Sender<resource_task::ProgressMsg>) { }
Expand Down
1 change: 1 addition & 0 deletions components/net/lib.rs
Expand Up @@ -26,6 +26,7 @@ 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 stb_image;
Expand Down
20 changes: 20 additions & 0 deletions components/profile/Cargo.toml
@@ -0,0 +1,20 @@
[package]
name = "profile"
version = "0.0.1"
authors = ["The Servo Project Developers"]

[lib]
name = "profile"
path = "lib.rs"

[dependencies.task_info]
path = "../../support/rust-task_info"

[dependencies.util]
path = "../util"

[dependencies]
libc = "*"
regex = "0.1.14"
time = "0.1.12"
url = "0.2.16"
27 changes: 27 additions & 0 deletions components/profile/lib.rs
@@ -0,0 +1,27 @@
/* 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/. */

#![feature(collections)]
#![feature(core)]
#![cfg_attr(target_os="linux", feature(io))]
#![feature(old_io)]
#![cfg_attr(target_os="linux", feature(page_size))]
#![feature(rustc_private)]
#![feature(std_misc)]
#![cfg_attr(target_os="linux", feature(str_words))]

#[macro_use] extern crate log;

extern crate collections;
extern crate libc;
#[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;

5 comments on commit 52447cc

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from glennw
at nnethercote@52447cc

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nnethercote/servo/profile-crate = 52447cc into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nnethercote/servo/profile-crate = 52447cc merged ok, testing candidate = d1268ec

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d1268ec

Please sign in to comment.