mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Enable profiling in the headless server. #368
(Although actually, I'm liking cargo flamegraph better than cpuprofiler. Might rip out the support for cpuprofiler.)
This commit is contained in:
parent
39ec4a13de
commit
b3525f95a2
@ -325,6 +325,16 @@ fn handle_command(
|
|||||||
&map.edit_road_cmd(r, |_| {}).to_perma(map),
|
&map.edit_road_cmd(r, |_| {}).to_perma(map),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
// Debug
|
||||||
|
"/debug/start-profiler" => {
|
||||||
|
// You have to build with --features abstutil/profiler
|
||||||
|
abstutil::start_profiler();
|
||||||
|
Ok("started".to_string())
|
||||||
|
}
|
||||||
|
"/debug/stop-profiler" => {
|
||||||
|
abstutil::stop_profiler();
|
||||||
|
Ok("stopped".to_string())
|
||||||
|
}
|
||||||
_ => Err("Unknown command".into()),
|
_ => Err("Unknown command".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,10 +297,10 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
CarState::Unparking(front, _, _) => {
|
CarState::Unparking(front, _, _) => {
|
||||||
if car.router.last_step() {
|
if car.router.last_step() {
|
||||||
// Actually, we need to do this first. Ignore the answer -- if we're
|
// Actually, we need to do this first. Ignore the answer -- if we're doing
|
||||||
// doing something weird like vanishing or re-parking immediately
|
// something weird like vanishing or re-parking immediately (quite unlikely),
|
||||||
// (quite unlikely), the next loop will pick that up. Just trigger the
|
// the next loop will pick that up. Just trigger the side effect of choosing an
|
||||||
// side effect of choosing an end_dist.
|
// end_dist.
|
||||||
car.router.maybe_handle_end(
|
car.router.maybe_handle_end(
|
||||||
front,
|
front,
|
||||||
&car.vehicle,
|
&car.vehicle,
|
||||||
@ -351,8 +351,7 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
CarState::WaitingToAdvance { .. } => unreachable!(),
|
CarState::WaitingToAdvance { .. } => unreachable!(),
|
||||||
// They weren't blocked. Note that there's no way the Crossing state could
|
// They weren't blocked. Note that there's no way the Crossing state could
|
||||||
// jump forwards here; the leader is still in front
|
// jump forwards here; the leader is still in front of them.
|
||||||
// of them.
|
|
||||||
CarState::Crossing(_, _)
|
CarState::Crossing(_, _)
|
||||||
| CarState::Unparking(_, _, _)
|
| CarState::Unparking(_, _, _)
|
||||||
| CarState::Parking(_, _, _)
|
| CarState::Parking(_, _, _)
|
||||||
@ -428,9 +427,8 @@ impl DrivingSimState {
|
|||||||
car.last_steps.push_front(last_step);
|
car.last_steps.push_front(last_step);
|
||||||
|
|
||||||
// Optimistically assume we'll be out of the way ASAP.
|
// Optimistically assume we'll be out of the way ASAP.
|
||||||
// This is update, not push, because we might've scheduled a blind retry too
|
// This is update, not push, because we might've scheduled a blind retry too late,
|
||||||
// late, and the car actually crosses an entire new traversable in the
|
// and the car actually crosses an entire new traversable in the meantime.
|
||||||
// meantime.
|
|
||||||
ctx.scheduler.update(
|
ctx.scheduler.update(
|
||||||
car.crossing_state_with_end_dist(
|
car.crossing_state_with_end_dist(
|
||||||
DistanceInterval::new_driving(
|
DistanceInterval::new_driving(
|
||||||
@ -520,9 +518,9 @@ impl DrivingSimState {
|
|||||||
};
|
};
|
||||||
car.state =
|
car.state =
|
||||||
CarState::Parking(our_dist, spot, TimeInterval::new(now, now + delay));
|
CarState::Parking(our_dist, spot, TimeInterval::new(now, now + delay));
|
||||||
// If we don't do this, then we might have another car creep up
|
// If we don't do this, then we might have another car creep up behind, see
|
||||||
// behind, see the spot free, and start parking too. This can
|
// the spot free, and start parking too. This can happen with multiple
|
||||||
// happen with multiple lanes and certain vehicle lengths.
|
// lanes and certain vehicle lengths.
|
||||||
ctx.parking.reserve_spot(spot);
|
ctx.parking.reserve_spot(spot);
|
||||||
ctx.scheduler
|
ctx.scheduler
|
||||||
.push(car.state.get_end_time(), Command::UpdateCar(car.vehicle.id));
|
.push(car.state.get_end_time(), Command::UpdateCar(car.vehicle.id));
|
||||||
@ -667,9 +665,9 @@ impl DrivingSimState {
|
|||||||
if idx != dists.len() - 1 {
|
if idx != dists.len() - 1 {
|
||||||
let (follower_id, follower_dist) = dists[idx + 1];
|
let (follower_id, follower_dist) = dists[idx + 1];
|
||||||
let mut follower = self.cars.get_mut(&follower_id).unwrap();
|
let mut follower = self.cars.get_mut(&follower_id).unwrap();
|
||||||
// TODO If the leader vanished at a border node, this still jumps a bit -- the
|
// TODO If the leader vanished at a border node, this still jumps a bit -- the lead
|
||||||
// lead car's back is still sticking out. Need to still be bound by them, even
|
// car's back is still sticking out. Need to still be bound by them, even though they
|
||||||
// though they don't exist! If the leader just parked, then we're fine.
|
// don't exist! If the leader just parked, then we're fine.
|
||||||
match follower.state {
|
match follower.state {
|
||||||
CarState::Queued { blocked_since } => {
|
CarState::Queued { blocked_since } => {
|
||||||
// Prevent them from jumping forwards.
|
// Prevent them from jumping forwards.
|
||||||
@ -681,9 +679,8 @@ impl DrivingSimState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
CarState::Crossing(_, _) => {
|
CarState::Crossing(_, _) => {
|
||||||
// If the follower was still Crossing, they might not've been blocked
|
// If the follower was still Crossing, they might not've been blocked by leader
|
||||||
// by leader yet. In that case, recalculating their Crossing state is a
|
// yet. In that case, recalculating their Crossing state is a no-op.
|
||||||
// no-op.
|
|
||||||
follower.state = follower.crossing_state(follower_dist, now, ctx.map);
|
follower.state = follower.crossing_state(follower_dist, now, ctx.map);
|
||||||
ctx.scheduler.update(
|
ctx.scheduler.update(
|
||||||
follower.state.get_end_time(),
|
follower.state.get_end_time(),
|
||||||
@ -805,8 +802,8 @@ impl DrivingSimState {
|
|||||||
// right behind us.
|
// right behind us.
|
||||||
if !follower.router.last_step() {
|
if !follower.router.last_step() {
|
||||||
// The follower has been smoothly following while the laggy head
|
// The follower has been smoothly following while the laggy head
|
||||||
// gets out of the way. So
|
// gets out of the way. So immediately promote them to
|
||||||
// immediately promote them to WaitingToAdvance.
|
// WaitingToAdvance.
|
||||||
follower.state = CarState::WaitingToAdvance { blocked_since };
|
follower.state = CarState::WaitingToAdvance { blocked_since };
|
||||||
if self.recalc_lanechanging {
|
if self.recalc_lanechanging {
|
||||||
follower.router.opportunistically_lanechange(
|
follower.router.opportunistically_lanechange(
|
||||||
@ -820,9 +817,8 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CarState::WaitingToAdvance { .. } => unreachable!(),
|
CarState::WaitingToAdvance { .. } => unreachable!(),
|
||||||
// They weren't blocked. Note that there's no way the Crossing state
|
// They weren't blocked. Note that there's no way the Crossing state could
|
||||||
// could jump forwards here; the leader
|
// jump forwards here; the leader vanished from the end of the traversable.
|
||||||
// vanished from the end of the traversable.
|
|
||||||
CarState::Crossing(_, _)
|
CarState::Crossing(_, _)
|
||||||
| CarState::Unparking(_, _, _)
|
| CarState::Unparking(_, _, _)
|
||||||
| CarState::Parking(_, _, _)
|
| CarState::Parking(_, _, _)
|
||||||
@ -830,8 +826,8 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Only the last step we cleared could possibly have cars. Any intermediates,
|
// Only the last step we cleared could possibly have cars. Any intermediates, this
|
||||||
// this car was previously completely blocking them.
|
// car was previously completely blocking them.
|
||||||
assert!(old_queue.cars.is_empty());
|
assert!(old_queue.cars.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user