diff options
author | Nicholas Nethercote <nnethercote@mozilla.com> | 2015-03-11 19:51:58 -0700 |
---|---|---|
committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2015-03-16 18:12:28 -0700 |
commit | fa9ca206efefea850ef1d8c8b43513653ff07507 (patch) | |
tree | 678265c9feeaeb5189942b9ceebc1b0561737feb /components/util/memory.rs | |
parent | ece2711185cffa8ade21b0ab9538bc1be79cadb9 (diff) | |
download | servo-fa9ca206efefea850ef1d8c8b43513653ff07507.tar.gz servo-fa9ca206efefea850ef1d8c8b43513653ff07507.zip |
Remove the fake memory profiler thread.
Currently if you don't specify the '-m' option, a fake do-nothing memory
profiler thread gets created instead of the real one. It ignores all
events except for `Exit`. And the timer thread doesn't get created so no
`Print` events are sent.
This changeset instead always creates the real thread. If you specify
'-m' the *timer* thread is still absent and it won't print anything.
However, the memory profiler thread will respond to register/unregister
events, which is good, because if there's a bug in those (e.g.
double-registration of a particular name) it'll show up in invocations
that lack '-m'.
Diffstat (limited to 'components/util/memory.rs')
-rw-r--r-- | components/util/memory.rs | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/components/util/memory.rs b/components/util/memory.rs index e72873872f8..11bec328f65 100644 --- a/components/util/memory.rs +++ b/components/util/memory.rs @@ -243,38 +243,28 @@ pub struct MemoryProfiler { impl MemoryProfiler { pub fn create(period: Option<f64>) -> MemoryProfilerChan { let (chan, port) = channel(); - match period { - Some(period) => { - let period = Duration::milliseconds((period * 1000f64) as i64); - let chan = chan.clone(); - spawn_named("Memory profiler timer".to_owned(), move || { - loop { - sleep(period); - if chan.send(MemoryProfilerMsg::Print).is_err() { - break; - } - } - }); - // Spawn the memory profiler. - spawn_named("Memory profiler".to_owned(), move || { - let mut memory_profiler = MemoryProfiler::new(port); - memory_profiler.start(); - }); - } - None => { - // No-op to handle messages when the memory profiler is - // inactive. - spawn_named("Memory profiler".to_owned(), move || { - loop { - match port.recv() { - Err(_) | Ok(MemoryProfilerMsg::Exit) => break, - _ => {} - } + + // Create the timer thread if a period was provided. + if let Some(period) = period { + let period_ms = Duration::milliseconds((period * 1000f64) as i64); + let chan = chan.clone(); + spawn_named("Memory profiler timer".to_owned(), move || { + loop { + sleep(period_ms); + if chan.send(MemoryProfilerMsg::Print).is_err() { + break; } - }); - } + } + }); } + // Always spawn the memory profiler. If there is no timer thread it won't receive regular + // `Print` events, but it will still receive the other events. + spawn_named("Memory profiler".to_owned(), move || { + let mut memory_profiler = MemoryProfiler::new(port); + memory_profiler.start(); + }); + MemoryProfilerChan(chan) } |