mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +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,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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
// 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,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue