Skip to content

Commit

Permalink
use TreeMap instead of HashMap for profiler buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kuehn committed Aug 29, 2013
1 parent 47ec798 commit cf4107e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/util/time.rs
Expand Up @@ -8,7 +8,7 @@ use std::cell::Cell;
use std::comm::{Port, SharedChan};
use extra::sort::tim_sort;
use std::iterator::AdditiveIterator;
use std::hashmap::HashMap;
use extra::treemap::TreeMap;

// front-end representation of the profiler used to communicate with the profiler
#[deriving(Clone)]
Expand All @@ -34,7 +34,7 @@ pub enum ProfilerMsg {
PrintMsg,
}

#[deriving(Eq, Clone, IterBytes)]
#[deriving(Eq, Clone, TotalEq, TotalOrd)]
pub enum ProfilerCategory {
CompositingCategory,
LayoutQueryCategory,
Expand All @@ -52,7 +52,7 @@ pub enum ProfilerCategory {
// FIXME(rust#8803): workaround for lack of CTFE function on enum types to return length
NumBuckets,
}
type ProfilerBuckets = HashMap<ProfilerCategory, ~[float]>;
type ProfilerBuckets = TreeMap<ProfilerCategory, ~[float]>;

// back end of the profiler that handles data aggregation and performance metrics
pub struct Profiler {
Expand All @@ -69,7 +69,7 @@ impl ProfilerCategory {

// enumeration of all ProfilerCategory types
fn empty_buckets() -> ProfilerBuckets {
let mut buckets = HashMap::with_capacity(NumBuckets as uint);
let mut buckets = TreeMap::new();
buckets.insert(CompositingCategory, ~[]);
buckets.insert(LayoutQueryCategory, ~[]);
buckets.insert(LayoutPerformCategory, ~[]);
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Profiler {

fn handle_msg(&mut self, msg: ProfilerMsg) {
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 {
// only print if more data has arrived since the last printout
Some(TimeMsg(*)) => self.print_buckets(),
Expand All @@ -142,8 +142,10 @@ impl Profiler {
println(fmt!("%31s %15s %15s %15s %15s %15s",
"_category_", "_mean (ms)_", "_median (ms)_",
"_min (ms)_", "_max (ms)_", "_bucket size_"));
for (category, data) in self.buckets.mut_iter() {
tim_sort(*data);
for (category, data) in self.buckets.iter() {
// FIXME(XXX): TreeMap currently lacks mut_iter()
let mut data = data.clone();
tim_sort(data);
let data_len = data.len();
if data_len > 0 {
let (mean, median, &min, &max) =
Expand Down

0 comments on commit cf4107e

Please sign in to comment.