Skip to content

Commit

Permalink
replace profiling macro by simple scope! call
Browse files Browse the repository at this point in the history
faster and more IDE friendly
  • Loading branch information
Uriopass committed Aug 16, 2023
1 parent 8af4da6 commit 490f8b5
Show file tree
Hide file tree
Showing 32 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion egregoria/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ common = { path = "../common" }
slotmapd = { version = "1.0", default-features = false, features = ["serde", "unstable"] }
rayon = "1.6"
atomic_refcell = "0.1.6"
profiling = "1.0.5"
profiling = { version = "1.0.5", default-features = false }
inline_tweak = { version = "1.0.9", features = ["release_tweak"] }
pathfinding = "4.2.1"
serde-big-array = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/economy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ pub fn init_market(_: &mut World, res: &mut Resources) {
res.insert(stats);
}

#[profiling::function]
pub fn market_update(world: &mut World, resources: &mut Resources) {
profiling::scope!("economy::market_update");
let n_workers = world.humans.len();

let mut m = resources.write::<Market>();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ impl Egregoria {
true
}

#[profiling::function]
pub fn tick<'a>(
&mut self,
game_schedule: &mut SeqSchedule,
commands: impl IntoIterator<Item = &'a WorldCommand>,
) -> Duration {
profiling::scope!("egregoria::tick");
let t = Instant::now();
// It is very important that the first thing being done is applying commands
// so that instant commands work on single player but the game is still deterministic
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/map_dynamic/itinerary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ impl Inspect<ItineraryKind> for ItineraryKind {
}
}

#[profiling::function]
pub fn itinerary_update(world: &mut World, resources: &mut Resources) {
profiling::scope!("map_dynamic::itinerary_update");
let time = &*resources.read::<GameTime>();
let map = &*resources.read::<Map>();
let tick = *resources.read::<Tick>();
Expand Down
4 changes: 2 additions & 2 deletions egregoria/src/map_dynamic/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub enum RoutingStep {

debug_inspect_impl!(RoutingStep);

#[profiling::function]
pub fn routing_changed_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("map_dynamic::routing_changed_system");
let map: &Map = &resources.read();
let parking: &mut ParkingManagement = &mut resources.write();

Expand Down Expand Up @@ -109,8 +109,8 @@ pub fn routing_changed_system(world: &mut World, resources: &mut Resources) {
});
}

#[profiling::function]
pub fn routing_update_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("map_dynamic::routing_update_system");
let map: &Map = &resources.read();
let cbuf_human: &ParCommandBuffer<HumanEnt> = &resources.read();
let cbuf_vehicle: &ParCommandBuffer<VehicleEnt> = &resources.read();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/physics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl Collider {
}
}

#[profiling::function]
pub fn coworld_synchronize(world: &mut World, resources: &mut Resources) {
profiling::scope!("physics::coworld_synchronize");
let mut coworld = resources.write::<CollisionWorld>();

world.query_trans_speed_coll_vehicle().for_each(
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/souls/goods_company.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ pub fn company_soul(goria: &mut Egregoria, company: GoodsCompany) -> Option<Soul
Some(soul)
}

#[profiling::function]
pub fn company_system(world: &mut World, res: &mut Resources) {
profiling::scope!("souls::company_system");
let delta = res.read::<GameTime>().realdelta;
let cbuf: &ParCommandBuffer<CompanyEnt> = &res.read();
let cbuf_human: &ParCommandBuffer<HumanEnt> = &res.read();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/souls/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ enum NextDesire<'a> {
Food(&'a mut BuyFood),
}

#[profiling::function]
pub fn update_decision_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("souls::update_decision_system");
let ra = &*resources.read();
let rb = &*resources.read();
let rc = &*resources.read();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/souls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub mod goods_company;
pub mod human;

/// Adds souls to empty buildings
#[profiling::function]
pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) {
profiling::scope!("souls::add_souls_to_empty_buildings");
let map = goria.map();
let infos = goria.read::<BuildingInfos>();
let mut empty_buildings: BTreeMap<BuildingKind, Vec<(BuildingID, Vec3)>> = BTreeMap::default();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/transportation/pedestrian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub fn random_pedestrian_shirt_color(r: &mut RandProvider) -> Color {
unreachable!();
}

#[profiling::function]
pub fn pedestrian_decision_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("transportation::pedestrian_decision_system");
let ra = &*resources.read();
world.humans
.values_mut()
Expand Down
4 changes: 2 additions & 2 deletions egregoria/src/transportation/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::World;
use geom::{angle_lerpxy, Ray, Transform, Vec2, Vec3};
use slotmapd::Key;

#[profiling::function]
pub fn vehicle_decision_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("transportation::vehicle_decision_system");
let ra = &*resources.read();
let rb = &*resources.read();
let rc = &*resources.read();
Expand Down Expand Up @@ -76,8 +76,8 @@ pub fn vehicle_decision(
);
}

#[profiling::function]
pub fn vehicle_state_update_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("transportation::vehicle_state_update_system");
let ra = &*resources.read();
let rb = &*resources.read();
let rc = &*resources.read();
Expand Down
4 changes: 2 additions & 2 deletions egregoria/src/transportation/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ pub fn traverse_forward<'a>(
.take_while(move |(_, acc, _, acc_l)| *acc < dist || *acc_l <= until_length)
}

#[profiling::function]
pub fn train_reservations_update(world: &mut World, resources: &mut Resources) {
profiling::scope!("transportation::train_reservations_update");
let map = &*resources.read::<Map>();
let reservations = &mut *resources.write::<TrainReservations>();
let lanes = map.lanes();
Expand Down Expand Up @@ -301,8 +301,8 @@ pub fn train_reservations_update(world: &mut World, resources: &mut Resources) {
});
}

#[profiling::function]
pub fn locomotive_system(world: &mut World, resources: &mut Resources) {
profiling::scope!("transportation::locomotive_system");
let map: &Map = &resources.read();
let time: &GameTime = &resources.read();
let reservs: &TrainReservations = &resources.read();
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/utils/par_command_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl<E: GoriaDrop> ParCommandBuffer<E> {
})
}

#[profiling::function]
pub fn apply(goria: &mut Egregoria) {
profiling::scope!("par_command_buffer::apply");
let mut deleted: Vec<E::ID> = std::mem::take(
&mut *goria
.write::<ParCommandBuffer<E>>()
Expand Down
2 changes: 1 addition & 1 deletion egregoria/src/utils/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl SeqSchedule {
self
}

#[profiling::function]
#[inline(never)]
pub fn execute(&mut self, goria: &mut Egregoria) {
profiling::scope!("scheduler::execute");
for (sys, h) in &mut self.systems {
let start = Instant::now();

Expand Down
2 changes: 1 addition & 1 deletion native_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ slotmapd = { version = "1.0", default-features = false }
winit = { version = "0.28.1" }
atomic_refcell = "0.1.6"
rayon = "1.6"
profiling = { version = "1.0.8" }
profiling = { version = "1.0.8", default-features = false }
include_dir = "0.7.2"
egui-inspect = { path = "../egui-inspect" }
egui = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/addtrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::option::Option::None;

/// Addtrain handles the "Adding a train" tool
/// It allows to add a train to any rail lane
#[profiling::function]
pub fn addtrain(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::addtrain");
let tool = *uiworld.read::<Tool>();
if !matches!(tool, Tool::Train) {
return;
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/bulldozer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct BulldozerState {

/// Bulldozer tool
/// Allows to remove roads, intersections and buildings
#[profiling::function]
pub fn bulldozer(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::bulldozer");
let tool: &Tool = &uiworld.read::<Tool>();

if !matches!(*tool, Tool::Bulldozer) {
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/inspected_aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use egregoria::{AnyEntity, Egregoria};
use geom::Color;

/// InspectedAura shows the circle around the inspected entity
#[profiling::function]
pub fn inspected_aura(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::inspected_aura");
let inspected = uiworld.write::<InspectedEntity>();
let inspected_b = uiworld.write::<InspectedBuilding>();
let map = goria.map();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/lotbrush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub struct LotBrushResource {

/// Lot brush tool
/// Allows to build houses on lots
#[profiling::function]
pub fn lotbrush(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::lotbrush");
let res = uiworld.read::<LotBrushResource>();
let tool = *uiworld.read::<Tool>();
let inp = uiworld.read::<InputMap>();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod zoneedit;
pub use follow::FollowEntity;
pub use topgui::*;

#[profiling::function]
pub fn run_ui_systems(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::run_ui_systems");
bulldozer::bulldozer(goria, uiworld);
inspected_aura::inspected_aura(goria, uiworld);
lotbrush::lotbrush(goria, uiworld);
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/roadbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct RoadBuildResource {

/// Road building tool
/// Allows to build roads and intersections
#[profiling::function]
pub fn roadbuild(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::roadbuild");
let state = &mut *uiworld.write::<RoadBuildResource>();
let immdraw = &mut *uiworld.write::<ImmediateDraw>();
let immsound = &mut *uiworld.write::<ImmediateSound>();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/roadeditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct RoadEditorResource {

/// RoadEditor tool
/// Allows to edit intersections properties like turns and signals
#[profiling::function]
pub fn roadeditor(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::roadeditor");
let tool = uiworld.read::<Tool>();
let inp = uiworld.read::<InputMap>();
let mut state = uiworld.write::<RoadEditorResource>();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/selectable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn select_radius(id: AnyEntity) -> f32 {
}

/// Selectable allows to select entities by clicking on them
#[profiling::function]
pub fn selectable(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::selectable");
let mut inspected = uiworld.write::<InspectedEntity>();
let mut inspected_b = uiworld.write::<InspectedBuilding>();
let inp = uiworld.read::<InputMap>();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/specialbuilding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct SpecialBuildingResource {

/// SpecialBuilding tool
/// Allows to build special buildings like farms, factories, etc.
#[profiling::function]
pub fn specialbuilding(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::specialbuilding");
let mut state = uiworld.write::<SpecialBuildingResource>();
let tool = *uiworld.read::<Tool>();
let inp = uiworld.read::<InputMap>();
Expand Down
3 changes: 1 addition & 2 deletions native_app/src/gui/topgui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl Gui {
self.tooltip(ui, uiworld, goria);
}

#[profiling::function]
pub fn tooltip(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) {
profiling::scope!("gui::tooltip");
let tooltip = std::mem::take(&mut *uiworld.write::<ErrorTooltip>());
if let Some(msg) = tooltip.msg {
if !(tooltip.isworld && ui.is_pointer_over_area()) {
Expand Down Expand Up @@ -121,7 +121,6 @@ impl Gui {
});
}

#[profiling::function]
pub fn auto_save(&mut self, uiworld: &mut UiWorld) {
let every = uiworld.read::<Settings>().auto_save_every.into();
if let Some(every) = every {
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl GUIWindows {
}
}

#[profiling::function]
pub fn render(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) {
profiling::scope!("windows::render");
if uiworld
.write::<InputMap>()
.just_act
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/zoneedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct ZoneEditState {

/// ZoneEdit tool
/// Allows to edit the zone of a building like a farm field or solarpanel field
#[profiling::function]
pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) {
profiling::scope!("gui::zoneedit");
let mut inspected_b = uiworld.write::<InspectedBuilding>();
let mut state = uiworld.write::<ZoneEditState>();
let mut potentialcommand = uiworld.write::<PotentialCommands>();
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/rendering/entity_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl InstancedRender {
}
}

#[profiling::function]
pub fn render(&mut self, goria: &Egregoria, fctx: &mut FrameContext<'_>) {
profiling::scope!("entity_render::render");
self.cars.instances.clear();
self.trucks.instances.clear();
self.pedestrians.instances.clear();
Expand Down
2 changes: 1 addition & 1 deletion wgpu_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ log = "0.4.11"
raw-window-handle = "0.5.0"
gltf = { version = "1.2.0", default-features=false, features=["import", "utils", "names"] }
itertools = { version = "0.10.0", default-features = false }
profiling = "1.0.1"
profiling = { version = "1.0.1", default-features = false }
rayon = "1.6"
beul = "1.0.0"
slotmapd = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion wgpu_engine/src/drawables/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ impl<const CSIZE: usize, const CRESOLUTION: usize> TerrainRender<CSIZE, CRESOLUT
true
}

#[profiling::function]
pub fn draw_terrain(
&mut self,
cam: &Camera,
frustrum: &InfiniteFrustrum,
fctx: &mut FrameContext<'_>,
) {
profiling::scope!("terrain::draw_terrain");
for b in self.borders.iter() {
fctx.objs.push(Box::new(b.clone()));
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu_engine/src/gfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,13 @@ impl GfxContext {
)
}

#[profiling::function]
pub fn render_objs(
&mut self,
encs: &mut Encoders,
frame: &TextureView,
mut prepare: impl FnMut(&mut FrameContext<'_>),
) {
profiling::scope!("gfx::render_objs");
let mut objs = vec![];
let mut fc = FrameContext {
objs: &mut objs,
Expand Down Expand Up @@ -612,13 +612,13 @@ impl GfxContext {
render_background(self, encs, &frame);
}

#[profiling::function]
pub fn render_gui(
&mut self,
encoders: &mut Encoders,
frame: &TextureView,
mut render_gui: impl FnMut(GuiRenderContext<'_, '_>),
) {
profiling::scope!("gfx::render_gui");
render_gui(GuiRenderContext {
encoder: &mut encoders.end,
view: frame,
Expand Down
Loading

0 comments on commit 490f8b5

Please sign in to comment.