mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
more granular profiling
This commit is contained in:
parent
bd19f4c7db
commit
a96b77ba3f
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -18,6 +18,7 @@ name = "abstutil"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"include_dir 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"instant 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -736,7 +737,6 @@ name = "ezgui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"abstutil 0.1.0",
|
||||
"cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"geom 0.1.0",
|
||||
"glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -4,8 +4,12 @@ version = "0.1.0"
|
||||
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
profiler = ["cpuprofiler"]
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.1.2"
|
||||
cpuprofiler = { version = "0.0.3", optional = true }
|
||||
instant = "0.1.2"
|
||||
itertools = "0.9.0"
|
||||
num_cpus = "1.10.0"
|
||||
|
@ -23,7 +23,8 @@ pub use crate::io::{
|
||||
pub use crate::logs::Warn;
|
||||
pub use crate::random::{fork_rng, WeightedUsizeChoice};
|
||||
pub use crate::time::{
|
||||
elapsed_seconds, prettyprint_usize, MeasureMemory, Profiler, Timer, TimerSink,
|
||||
elapsed_seconds, prettyprint_usize, start_profiler, stop_profiler, MeasureMemory, Profiler,
|
||||
Timer, TimerSink,
|
||||
};
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt::Write;
|
||||
|
@ -678,3 +678,27 @@ impl<'a> Read for Timer<'a> {
|
||||
Ok(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "profiler")]
|
||||
pub fn start_profiler() {
|
||||
cpuprofiler::PROFILER
|
||||
.lock()
|
||||
.unwrap()
|
||||
.start("./profile")
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "profiler"))]
|
||||
pub fn start_profiler() {
|
||||
panic!("abstutil/profiler feature not enabled in Cargo.toml");
|
||||
}
|
||||
|
||||
#[cfg(feature = "profiler")]
|
||||
pub fn stop_profiler() {
|
||||
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "profiler"))]
|
||||
pub fn stop_profiler() {
|
||||
panic!("abstutil/profiler feature not enabled in Cargo.toml");
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ Actually, https://github.com/flamegraph-rs/flamegraph is pretty cool too.
|
||||
|
||||
Follow Usage from https://crates.io/crates/cpuprofiler
|
||||
|
||||
Modify `game/Cargo.toml` to include the `profiler` feature on `ezgui`. Then
|
||||
run game or headless with `--enable_profiler`
|
||||
Modify `game/Cargo.toml` to include the `abstutil/profiler` feature. Then run
|
||||
game or headless with `--enable_profiler`
|
||||
|
||||
```
|
||||
google-pprof --no_strip_temp ../target/debug/game profile
|
||||
@ -38,6 +38,9 @@ google-pprof --no_strip_temp ../target/release/headless profile
|
||||
top30 --cum
|
||||
```
|
||||
|
||||
Why aren't the columns labelled?
|
||||
https://groups.google.com/d/msg/golang-nuts/qkDWqFKj8og/tWfYAaWRYqkJ
|
||||
|
||||
## Building releases
|
||||
|
||||
Cross-compilation notes: https://github.com/rust-embedded/cross Or use
|
||||
|
@ -9,12 +9,10 @@ default = ["glium-backend"]
|
||||
glium-backend = ["glium", "glutin", "usvg/text"]
|
||||
glow-backend = ["glow", "glutin", "usvg/text"]
|
||||
wasm-backend = ["glow/stdweb", "instant/stdweb", "stdweb", "webgl_stdweb", "winit/stdweb"]
|
||||
profiler = ["cpuprofiler"]
|
||||
|
||||
[dependencies]
|
||||
abstutil = { path = "../abstutil" }
|
||||
# backtrace = "0.3.40"
|
||||
cpuprofiler = { version = "0.0.3", optional = true }
|
||||
downcast-rs = "1.1.1"
|
||||
geom = { path = "../geom" }
|
||||
glium = { version = "0.27.0", optional = true }
|
||||
|
@ -243,14 +243,7 @@ pub fn run<G: 'static + GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings,
|
||||
let mut state = State { canvas, gui, style };
|
||||
|
||||
if settings.profiling_enabled {
|
||||
#[cfg(feature = "profiler")]
|
||||
{
|
||||
cpuprofiler::PROFILER
|
||||
.lock()
|
||||
.unwrap()
|
||||
.start("./profile")
|
||||
.unwrap();
|
||||
}
|
||||
abstutil::start_profiler();
|
||||
}
|
||||
|
||||
let profiling_enabled = settings.profiling_enabled;
|
||||
@ -271,10 +264,7 @@ pub fn run<G: 'static + GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings,
|
||||
// GPU stuff is dropped. Better to just abort violently and let the OS clean
|
||||
// up.
|
||||
if profiling_enabled {
|
||||
#[cfg(feature = "profiler")]
|
||||
{
|
||||
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
||||
}
|
||||
abstutil::stop_profiler();
|
||||
}
|
||||
state.gui.before_quit(&state.canvas);
|
||||
std::process::exit(0);
|
||||
|
@ -183,6 +183,10 @@ impl TripSpawner {
|
||||
scheduler: &mut Scheduler,
|
||||
timer: &mut Timer,
|
||||
) {
|
||||
let profile = false;
|
||||
if profile {
|
||||
abstutil::start_profiler();
|
||||
}
|
||||
let paths = timer.parallelize(
|
||||
"calculate paths",
|
||||
std::mem::replace(&mut self.trips, Vec::new()),
|
||||
@ -191,6 +195,9 @@ impl TripSpawner {
|
||||
(tuple, req.clone(), req.and_then(|r| map.pathfind(r)))
|
||||
},
|
||||
);
|
||||
if profile {
|
||||
abstutil::stop_profiler();
|
||||
}
|
||||
|
||||
timer.start_iter("spawn trips", paths.len());
|
||||
for ((p, start_time, spec, trip_start), maybe_req, maybe_path) in paths {
|
||||
|
Loading…
Reference in New Issue
Block a user