flag-based profiling of GUI

This commit is contained in:
Dustin Carlino 2019-02-14 13:01:26 -08:00
parent ee16c864c5
commit 06c8ed72a9
7 changed files with 28 additions and 10 deletions

View File

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

View File

@ -8,7 +8,6 @@ edition = "2018"
aabb-quadtree = "0.1.0"
abstutil = { path = "../abstutil" }
counter = "0.4.3"
cpuprofiler = "0.0.3"
downcast = "0.9.2"
ezgui = { path = "../ezgui" }
generator = "0.6"

View File

@ -13,11 +13,6 @@ use structopt::StructOpt;
fn main() {
let flags = state::Flags::from_args();
/*cpuprofiler::PROFILER
.lock()
.unwrap()
.start("./profile")
.unwrap();*/
if flags.sim_flags.load == "../data/raw_maps/ban_left_turn.abst" {
ezgui::run("A/B Street", 1024.0, 768.0, |mut canvas, prerender| {

View File

@ -39,6 +39,10 @@ pub struct Flags {
/// Should lane markings be drawn? Sometimes they eat too much GPU memory.
#[structopt(long = "dont_draw_lane_markings")]
pub dont_draw_lane_markings: bool,
/// Enable cpuprofiler?
#[structopt(long = "enable_profiler")]
pub enable_profiler: bool,
}
pub trait UIState {

View File

@ -1,10 +1,9 @@
use abstutil;
//use cpuprofiler;
use crate::objects::{DrawCtx, RenderingHints, ID};
use crate::render::{
draw_vehicle, AgentCache, DrawPedestrian, RenderOptions, Renderable, MIN_ZOOM_FOR_MARKINGS,
};
use crate::state::UIState;
use abstutil;
use ezgui::{
Canvas, Color, EventCtx, EventLoopMode, Folder, GfxCtx, Key, ModalMenu, Prerender, Text,
TopMenu, BOTTOM_LEFT, GUI,
@ -366,7 +365,10 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
self.save_editor_state(canvas);
self.state.get_state().cs.save();
info!("Saved color_scheme");
//cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
}
fn profiling_enabled(&self) -> bool {
self.state.get_state().primary.current_flags.enable_profiler
}
}

View File

@ -6,6 +6,7 @@ edition = "2018"
[dependencies]
abstutil = { path = "../abstutil" }
cpuprofiler = "0.0.3"
geom = { path = "../geom" }
glium = "0.23.0"
glium-glyph = "0.3.0"

View File

@ -33,6 +33,10 @@ pub trait GUI<T> {
fn dump_before_abort(&self, _canvas: &Canvas) {}
// Only before a normal exit, like window close
fn before_quit(&self, _canvas: &Canvas) {}
fn profiling_enabled(&self) -> bool {
false
}
}
#[derive(Clone, Copy, PartialEq)]
@ -214,6 +218,14 @@ fn loop_forever<T, G: GUI<T>>(
program: glium::Program,
prerender: Prerender,
) {
if state.gui.profiling_enabled() {
cpuprofiler::PROFILER
.lock()
.unwrap()
.start("./profile")
.unwrap();
}
let mut wait_for_events = false;
loop {
@ -223,6 +235,9 @@ fn loop_forever<T, G: GUI<T>>(
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent { event, .. } = event {
if event == glutin::WindowEvent::CloseRequested {
if state.gui.profiling_enabled() {
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
}
state.gui.before_quit(&state.canvas);
process::exit(0);
}