--enable_profiler in headless too

This commit is contained in:
Dustin Carlino 2019-03-02 08:51:17 -08:00
parent bcb0268f7a
commit 214e461601
2 changed files with 23 additions and 13 deletions

View File

@ -4,8 +4,7 @@ apt-get install google-perftools libgoogle-perftools-dev
Follow Usage from https://crates.io/crates/cpuprofiler Follow Usage from https://crates.io/crates/cpuprofiler
Run editor with --enable_profiler Run editor or headless with --enable_profiler
google-pprof --web ../target/debug/editor profile google-pprof --no_strip_temp ../target/debug/editor profile
google-pprof --web ../target/release/headless profile google-pprof --no_strip_temp ../target/release/headless profile
top30 --cum
Or run without --web and do 'top30 --cum'

View File

@ -12,6 +12,10 @@ struct Flags {
/// Optional time to savestate /// Optional time to savestate
#[structopt(long = "save_at")] #[structopt(long = "save_at")]
save_at: Option<String>, save_at: Option<String>,
/// Enable cpuprofiler?
#[structopt(long = "enable_profiler")]
pub enable_profiler: bool,
} }
fn main() { fn main() {
@ -22,7 +26,7 @@ fn main() {
let mut timer = Timer::new("setup headless"); let mut timer = Timer::new("setup headless");
let (map, mut sim, mut rng) = flags let (map, mut sim, mut rng) = flags
.sim_flags .sim_flags
.load(Some(Duration::seconds(30.0)), &mut timer); .load(None, &mut timer);
if load.contains("data/raw_maps/") || load.contains("data/maps/") { if load.contains("data/raw_maps/") || load.contains("data/maps/") {
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer); Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer);
@ -39,22 +43,29 @@ fn main() {
None None
}; };
/*cpuprofiler::PROFILER if flags.enable_profiler {
.lock() cpuprofiler::PROFILER
.unwrap() .lock()
.start("./profile") .unwrap()
.unwrap();*/ .start("./profile")
.unwrap();
}
let enable_profiler = flags.enable_profiler;
sim.run_until_done( sim.run_until_done(
&map, &map,
move |sim| { move |sim| {
if Some(sim.time()) == save_at { if Some(sim.time()) == save_at {
sim.save(); sim.save();
// Some simulatiosn run for a really long time, just do this. // Some simulatiosn run for a really long time, just do this.
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap(); if enable_profiler {
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
}
} }
}, },
None, None,
); );
//sim::save_backtraces("call_graph.json");
println!("{:?}", sim.get_score()); println!("{:?}", sim.get_score());
if flags.enable_profiler && save_at.is_none() {
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
}
} }