mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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'.
This commit is contained in:
parent
ece2711185
commit
fa9ca206ef
1 changed files with 19 additions and 29 deletions
|
@ -243,37 +243,27 @@ pub struct MemoryProfiler {
|
||||||
impl MemoryProfiler {
|
impl MemoryProfiler {
|
||||||
pub fn create(period: Option<f64>) -> MemoryProfilerChan {
|
pub fn create(period: Option<f64>) -> MemoryProfilerChan {
|
||||||
let (chan, port) = channel();
|
let (chan, port) = channel();
|
||||||
match period {
|
|
||||||
Some(period) => {
|
// Create the timer thread if a period was provided.
|
||||||
let period = Duration::milliseconds((period * 1000f64) as i64);
|
if let Some(period) = period {
|
||||||
|
let period_ms = Duration::milliseconds((period * 1000f64) as i64);
|
||||||
let chan = chan.clone();
|
let chan = chan.clone();
|
||||||
spawn_named("Memory profiler timer".to_owned(), move || {
|
spawn_named("Memory profiler timer".to_owned(), move || {
|
||||||
loop {
|
loop {
|
||||||
sleep(period);
|
sleep(period_ms);
|
||||||
if chan.send(MemoryProfilerMsg::Print).is_err() {
|
if chan.send(MemoryProfilerMsg::Print).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Spawn the memory profiler.
|
}
|
||||||
|
|
||||||
|
// 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 || {
|
spawn_named("Memory profiler".to_owned(), move || {
|
||||||
let mut memory_profiler = MemoryProfiler::new(port);
|
let mut memory_profiler = MemoryProfiler::new(port);
|
||||||
memory_profiler.start();
|
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,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryProfilerChan(chan)
|
MemoryProfilerChan(chan)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue