mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
use TreeMap instead of HashMap for profiler buckets
This commit is contained in:
parent
47ec798b92
commit
cf4107e262
1 changed files with 9 additions and 7 deletions
|
@ -8,7 +8,7 @@ use std::cell::Cell;
|
||||||
use std::comm::{Port, SharedChan};
|
use std::comm::{Port, SharedChan};
|
||||||
use extra::sort::tim_sort;
|
use extra::sort::tim_sort;
|
||||||
use std::iterator::AdditiveIterator;
|
use std::iterator::AdditiveIterator;
|
||||||
use std::hashmap::HashMap;
|
use extra::treemap::TreeMap;
|
||||||
|
|
||||||
// front-end representation of the profiler used to communicate with the profiler
|
// front-end representation of the profiler used to communicate with the profiler
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
|
@ -34,7 +34,7 @@ pub enum ProfilerMsg {
|
||||||
PrintMsg,
|
PrintMsg,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Clone, IterBytes)]
|
#[deriving(Eq, Clone, TotalEq, TotalOrd)]
|
||||||
pub enum ProfilerCategory {
|
pub enum ProfilerCategory {
|
||||||
CompositingCategory,
|
CompositingCategory,
|
||||||
LayoutQueryCategory,
|
LayoutQueryCategory,
|
||||||
|
@ -52,7 +52,7 @@ pub enum ProfilerCategory {
|
||||||
// FIXME(rust#8803): workaround for lack of CTFE function on enum types to return length
|
// FIXME(rust#8803): workaround for lack of CTFE function on enum types to return length
|
||||||
NumBuckets,
|
NumBuckets,
|
||||||
}
|
}
|
||||||
type ProfilerBuckets = HashMap<ProfilerCategory, ~[float]>;
|
type ProfilerBuckets = TreeMap<ProfilerCategory, ~[float]>;
|
||||||
|
|
||||||
// back end of the profiler that handles data aggregation and performance metrics
|
// back end of the profiler that handles data aggregation and performance metrics
|
||||||
pub struct Profiler {
|
pub struct Profiler {
|
||||||
|
@ -69,7 +69,7 @@ impl ProfilerCategory {
|
||||||
|
|
||||||
// enumeration of all ProfilerCategory types
|
// enumeration of all ProfilerCategory types
|
||||||
fn empty_buckets() -> ProfilerBuckets {
|
fn empty_buckets() -> ProfilerBuckets {
|
||||||
let mut buckets = HashMap::with_capacity(NumBuckets as uint);
|
let mut buckets = TreeMap::new();
|
||||||
buckets.insert(CompositingCategory, ~[]);
|
buckets.insert(CompositingCategory, ~[]);
|
||||||
buckets.insert(LayoutQueryCategory, ~[]);
|
buckets.insert(LayoutQueryCategory, ~[]);
|
||||||
buckets.insert(LayoutPerformCategory, ~[]);
|
buckets.insert(LayoutPerformCategory, ~[]);
|
||||||
|
@ -128,7 +128,7 @@ impl Profiler {
|
||||||
|
|
||||||
fn handle_msg(&mut self, msg: ProfilerMsg) {
|
fn handle_msg(&mut self, msg: ProfilerMsg) {
|
||||||
match msg {
|
match msg {
|
||||||
TimeMsg(category, t) => self.buckets.get_mut(&category).push(t),
|
TimeMsg(category, t) => self.buckets.find_mut(&category).unwrap().push(t),
|
||||||
PrintMsg => match self.last_msg {
|
PrintMsg => match self.last_msg {
|
||||||
// only print if more data has arrived since the last printout
|
// only print if more data has arrived since the last printout
|
||||||
Some(TimeMsg(*)) => self.print_buckets(),
|
Some(TimeMsg(*)) => self.print_buckets(),
|
||||||
|
@ -142,8 +142,10 @@ impl Profiler {
|
||||||
println(fmt!("%31s %15s %15s %15s %15s %15s",
|
println(fmt!("%31s %15s %15s %15s %15s %15s",
|
||||||
"_category_", "_mean (ms)_", "_median (ms)_",
|
"_category_", "_mean (ms)_", "_median (ms)_",
|
||||||
"_min (ms)_", "_max (ms)_", "_bucket size_"));
|
"_min (ms)_", "_max (ms)_", "_bucket size_"));
|
||||||
for (category, data) in self.buckets.mut_iter() {
|
for (category, data) in self.buckets.iter() {
|
||||||
tim_sort(*data);
|
// FIXME(XXX): TreeMap currently lacks mut_iter()
|
||||||
|
let mut data = data.clone();
|
||||||
|
tim_sort(data);
|
||||||
let data_len = data.len();
|
let data_len = data.len();
|
||||||
if data_len > 0 {
|
if data_len > 0 {
|
||||||
let (mean, median, &min, &max) =
|
let (mean, median, &min, &max) =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue