Add task profiler, which works by instrumenting each task runtime when enabled.

This commit is contained in:
Glenn Watson 2014-10-29 07:24:34 +10:00
parent 3aad350a64
commit 90d793cdc8
7 changed files with 241 additions and 10 deletions

View file

@ -7,17 +7,21 @@ use std::task;
use std::comm::Sender;
use std::task::TaskBuilder;
use native::task::NativeTaskBuilder;
use rtinstrument;
use task_state;
pub fn spawn_named<S: IntoMaybeOwned<'static>>(name: S, f: proc():Send) {
let builder = task::TaskBuilder::new().named(name);
builder.spawn(f);
builder.spawn(proc() {
rtinstrument::instrument(f);
});
}
pub fn spawn_named_native<S: IntoMaybeOwned<'static>>(name: S, f: proc():Send) {
let builder = task::TaskBuilder::new().named(name).native();
builder.spawn(f);
builder.spawn(proc() {
rtinstrument::instrument(f);
});
}
/// Arrange to send a particular message to a channel if the task fails.
@ -29,7 +33,7 @@ pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
native: bool) {
let with_state = proc() {
task_state::initialize(state);
f()
rtinstrument::instrument(f);
};
let future_result = if native {
@ -41,12 +45,14 @@ pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
let watched_name = name.to_string();
let watcher_name = format!("{:s}Watcher", watched_name);
TaskBuilder::new().named(watcher_name).spawn(proc() {
match future_result.unwrap() {
Ok(()) => (),
Err(..) => {
debug!("{:s} failed, notifying constellation", name);
dest.send(msg);
rtinstrument::instrument(proc() {
match future_result.unwrap() {
Ok(()) => (),
Err(..) => {
debug!("{:s} failed, notifying constellation", name);
dest.send(msg);
}
}
}
});
});
}