Skip to content

Commit

Permalink
Merge #262
Browse files Browse the repository at this point in the history
262: Binary: Extract tracing setup into function r=mkroening a=mkroening



Co-authored-by: Martin Kröning <[email protected]>
  • Loading branch information
bors[bot] and mkroening authored Jan 1, 2022
2 parents 36c04bd + f4f7e20 commit 5b3ab23
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/bin/uhyve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ extern crate log;
#[macro_use]
extern crate clap;

#[cfg(feature = "instrument")]
extern crate rftrace_frontend;

use std::collections::HashSet;
use std::env;
use std::path::PathBuf;
Expand All @@ -19,38 +16,39 @@ use uhyvelib::Uhyve;

use byte_unit::Byte;
use clap::{App, Arg};
#[cfg(feature = "instrument")]
use rftrace_frontend::Events;

const MINIMAL_GUEST_SIZE: usize = 16 * 1024 * 1024;
const DEFAULT_GUEST_SIZE: usize = 64 * 1024 * 1024;

#[cfg(feature = "instrument")]
static mut EVENTS: Option<&mut Events> = None;
fn setup_trace() {
use rftrace_frontend::Events;

#[cfg(feature = "instrument")]
extern "C" fn dump_trace() {
unsafe {
if let Some(ref mut e) = EVENTS {
rftrace_frontend::dump_full_uftrace(&mut *e, "uhyve_trace", "uhyve", true)
.expect("Saving trace failed");
static mut EVENTS: Option<&mut Events> = None;

extern "C" fn dump_trace() {
unsafe {
if let Some(e) = &mut EVENTS {
rftrace_frontend::dump_full_uftrace(e, "uhyve_trace", "uhyve", true)
.expect("Saving trace failed");
}
}
}

let events = rftrace_frontend::init(1000000, true);
rftrace_frontend::enable();

unsafe {
EVENTS = Some(events);
libc::atexit(dump_trace);
}
}

// Note that we end main with `std::process::exit` to set the return value and
// as a result destructors are not run and cleanup may not happen.
fn main() {
#[cfg(feature = "instrument")]
{
let events = rftrace_frontend::init(1000000, true);
rftrace_frontend::enable();

unsafe {
EVENTS = Some(events);
libc::atexit(dump_trace);
}
}
setup_trace();

env_logger::init();

Expand Down

0 comments on commit 5b3ab23

Please sign in to comment.