diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2016-04-13 15:07:37 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2016-04-14 12:28:00 -0700 |
commit | 1997d034faef7a09ba2d8e3c8b5cc31a1e22b1e3 (patch) | |
tree | 856fb418b93bae67cd016f788e803b6e0a29f6da /components/profile/time.rs | |
parent | 4f6331953e3d6cdb40e2c96c9119a0a3298026c1 (diff) | |
download | servo-1997d034faef7a09ba2d8e3c8b5cc31a1e22b1e3.tar.gz servo-1997d034faef7a09ba2d8e3c8b5cc31a1e22b1e3.zip |
Take the stdout lock when printing profile data
Acquiring the stdout lock while printing the profile data prevents other
messages printed to stdout from being interleaved with prints from elsewhere.
Diffstat (limited to 'components/profile/time.rs')
-rw-r--r-- | components/profile/time.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/components/profile/time.rs b/components/profile/time.rs index 22b917454d6..6a1152a2d72 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -12,6 +12,7 @@ use profile_traits::time::{TimerMetadataReflowType, TimerMetadataFrameType}; use std::borrow::ToOwned; use std::cmp::Ordering; use std::collections::BTreeMap; +use std::io::{self, Write}; use std::time::Duration; use std::{thread, f64}; use std_time::precise_time_ns; @@ -251,10 +252,13 @@ impl Profiler { } fn print_buckets(&mut self) { - println!("{:35} {:14} {:9} {:30} {:15} {:15} {:-15} {:-15} {:-15}", + let stdout = io::stdout(); + let mut lock = stdout.lock(); + + writeln!(&mut lock, "{:35} {:14} {:9} {:30} {:15} {:15} {:-15} {:-15} {:-15}", "_category_", "_incremental?_", "_iframe?_", " _url_", " _mean (ms)_", " _median (ms)_", - " _min (ms)_", " _max (ms)_", " _events_"); + " _min (ms)_", " _max (ms)_", " _events_").unwrap(); for (&(ref category, ref meta), ref mut data) in &mut self.buckets { data.sort_by(|a, b| { if a < b { @@ -270,11 +274,12 @@ impl Profiler { data[data_len / 2], data.iter().fold(f64::INFINITY, |a, &b| a.min(b)), data.iter().fold(-f64::INFINITY, |a, &b| a.max(b))); - println!("{:-35}{} {:15.4} {:15.4} {:15.4} {:15.4} {:15}", - category.format(), meta.format(), mean, median, min, max, data_len); + writeln!(&mut lock, "{:-35}{} {:15.4} {:15.4} {:15.4} {:15.4} {:15}", + category.format(), meta.format(), mean, median, min, max, + data_len).unwrap(); } } - println!(""); + writeln!(&mut lock, "").unwrap(); } } |