Commit e89195fc authored by Marco Perronet's avatar Marco Perronet
Browse files

Add duration parameter and cleanup on panic

parent 8ea66b0b
......@@ -62,7 +62,7 @@ pub struct Opt {
#[structopt(short = "o", long)]
pub allpids: bool,
/// Trace duration (iff run ftrace only)
/// Trace duration (necessary if running with ftrace only)
#[structopt(short = "l", long)]
pub ftrace_len: Option<Time>,
}
......@@ -48,7 +48,10 @@ impl EventsGenerator for FTraceEVG {
loop {
/* Continue to flush the remaining contents of the pipes.
After this, read_stream_parse() returns Some until the pipes are empty */
if !self.recorders_stopped && (self.duration_reached() || self.targets_are_dead()) {
if !self.recorders_stopped &&
(self.targets_are_dead() ||
crate::params::ftrace_stop_on_timeout() && self.duration_reached()) {
self.disable_tracing_stop_recorders();
}
......@@ -145,7 +148,7 @@ impl FTraceEVG {
processed_events: 0,
processed_events_all: 0,
start_time: std::time::Instant::now(), // Will be set when reading the first event
duration: 100000, // TODO use arg
duration: crate::params::ftrace_lifetime_sec(),
recorders_stopped: false,
extra_event: None,
......@@ -271,7 +274,7 @@ fn is_deactivation(raw_event: &bindings::rbftrace_event_raw) -> bool {
return !is_preemption(raw_event);
}
// It's important to do this to avoid errors in the invocation cycle in the next run
/* Cleanup on ctrl+C */
// TODO this is very ugly, but rust won't let the use the EVG instance because of the presence of raw pointers
fn sigint_handle() {
// Stop tracing
......@@ -280,3 +283,10 @@ fn sigint_handle() {
fs::write("/sys/kernel/debug/tracing/trace", " ").expect("Can't write to file 'trace'");
std::process::exit(0);
}
/* Cleanup on panic */
impl Drop for FTraceEVG {
fn drop(&mut self) {
self.shutdown();
}
}
......@@ -29,6 +29,8 @@ pub static mut FTRACE_BUF_SIZE: u32 = 65536;
// Use RBFtrace as a wrapper for ftrace, trace for FTRACE_LIFETIME_SEC seconds.
pub static mut FTRACE_ONLY: bool = false;
pub static mut FTRACE_LIFETIME_SEC: Time = 180;
// Normally we stop when all target pids died. If this is true, we will stop after FTRACE_LIFETIME_SEC
pub static mut FTRACE_STOP_ON_TIMEOUT: bool = false;
// Trace every pid, not only rt pids
pub static mut FTRACE_ALL_PIDS: bool = false;
......@@ -158,6 +160,7 @@ pub fn set_from_args(args: Opt) {
}
if args.ftrace_len.is_some() {
FTRACE_LIFETIME_SEC = args.ftrace_len.unwrap();
FTRACE_STOP_ON_TIMEOUT = true;
}
}
}
......@@ -208,6 +211,9 @@ pub fn ftrace_only() -> bool {
pub fn ftrace_lifetime_sec() -> u64 {
unsafe { return FTRACE_LIFETIME_SEC; }
}
pub fn ftrace_stop_on_timeout() -> bool {
unsafe { return FTRACE_STOP_ON_TIMEOUT; }
}
pub fn ftrace_all_pids() -> bool {
unsafe { return FTRACE_ALL_PIDS; }
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment