Skip to content

Commit

Permalink
Move event traces to detailed_trace! (#7732)
Browse files Browse the repository at this point in the history
# Objective
Noticed while writing #7728 that we are using `trace!` logs in our event
functions. This has shown to have significant overhead, even trace level
logs are disabled globally, as seen in #7639.

## Solution
Use the `detailed_trace!` macro introduced in #7639. Also removed the
`event_trace` function that was only used in one location.

---

## Changelog
Changed: Event trace logs are now feature gated behind the
`detailed-trace` feature.
  • Loading branch information
james7132 authored Apr 11, 2023
1 parent 52ee83e commit d623731
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/bevy_ecs/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate as bevy_ecs;
use crate::system::{Local, Res, ResMut, Resource, SystemParam};
use bevy_utils::tracing::trace;
use bevy_utils::detailed_trace;
use std::ops::{Deref, DerefMut};
use std::{fmt, hash::Hash, iter::Chain, marker::PhantomData, slice::Iter};
/// A type that can be stored in an [`Events<E>`] resource
Expand Down Expand Up @@ -419,10 +419,6 @@ pub struct ManualEventIteratorWithId<'a, E: Event> {
unread: usize,
}

fn event_trace<E: Event>(id: EventId<E>) {
trace!("EventReader::iter() -> {}", id);
}

impl<'a, E: Event> ManualEventIteratorWithId<'a, E> {
pub fn new(reader: &'a mut ManualEventReader<E>, events: &'a Events<E>) -> Self {
let a_index = (reader.last_event_count).saturating_sub(events.events_a.start_event_count);
Expand Down Expand Up @@ -459,7 +455,7 @@ impl<'a, E: Event> Iterator for ManualEventIteratorWithId<'a, E> {
.map(|instance| (&instance.event, instance.event_id))
{
Some(item) => {
event_trace(item.1);
detailed_trace!("EventReader::iter() -> {}", item.1);
self.reader.last_event_count += 1;
self.unread -= 1;
Some(item)
Expand Down Expand Up @@ -513,7 +509,7 @@ impl<E: Event> Events<E> {
id: self.event_count,
_marker: PhantomData,
};
trace!("Events::send() -> id: {}", event_id);
detailed_trace!("Events::send() -> id: {}", event_id);

let event_instance = EventInstance { event_id, event };

Expand Down Expand Up @@ -654,7 +650,7 @@ impl<E: Event> std::iter::Extend<E> for Events<E> {
self.events_b.extend(events);

if old_count != event_count {
trace!(
detailed_trace!(
"Events::extend() -> ids: ({}..{})",
self.event_count,
event_count
Expand Down

0 comments on commit d623731

Please sign in to comment.