Skip to content

Commit 260111c

Browse files
committed
Remove InstrumentedAsset* and instead just annotate the loads at the callsites.
1 parent 28b62ef commit 260111c

File tree

4 files changed

+30
-81
lines changed

4 files changed

+30
-81
lines changed

crates/bevy_asset/src/processor/mod.rs

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ use tracing::{debug, error, trace, warn};
7777
#[cfg(feature = "trace")]
7878
use {
7979
alloc::string::ToString,
80-
bevy_reflect::TypePath,
81-
bevy_tasks::ConditionalSendFuture,
8280
tracing::{info_span, instrument::Instrument},
8381
};
8482

@@ -754,8 +752,6 @@ impl AssetProcessor {
754752
.processors
755753
.write()
756754
.unwrap_or_else(PoisonError::into_inner);
757-
#[cfg(feature = "trace")]
758-
let processor = InstrumentedAssetProcessor(processor);
759755
let processor = Arc::new(processor);
760756
processors
761757
.type_path_to_processor
@@ -1195,9 +1191,17 @@ impl AssetProcessor {
11951191
reader_for_process,
11961192
&mut new_processed_info,
11971193
);
1198-
processor
1199-
.process(&mut context, settings, &mut *writer)
1200-
.await?
1194+
let process = processor.process(&mut context, settings, &mut *writer);
1195+
#[cfg(feature = "trace")]
1196+
let process = {
1197+
let span = info_span!(
1198+
"asset processing",
1199+
processor = processor.type_path(),
1200+
asset = asset_path.to_string(),
1201+
);
1202+
process.instrument(span)
1203+
};
1204+
process.await?
12011205
};
12021206

12031207
writer
@@ -1504,32 +1508,6 @@ impl ProcessingState {
15041508
}
15051509
}
15061510

1507-
#[cfg(feature = "trace")]
1508-
#[derive(TypePath)]
1509-
struct InstrumentedAssetProcessor<T>(T);
1510-
1511-
#[cfg(feature = "trace")]
1512-
impl<T: Process> Process for InstrumentedAssetProcessor<T> {
1513-
type Settings = T::Settings;
1514-
type OutputLoader = T::OutputLoader;
1515-
1516-
fn process(
1517-
&self,
1518-
context: &mut ProcessContext,
1519-
settings: &Self::Settings,
1520-
writer: &mut crate::io::Writer,
1521-
) -> impl ConditionalSendFuture<
1522-
Output = Result<<Self::OutputLoader as crate::AssetLoader>::Settings, ProcessError>,
1523-
> {
1524-
let span = info_span!(
1525-
"asset processing",
1526-
processor = T::type_path(),
1527-
asset = context.path().to_string(),
1528-
);
1529-
self.0.process(context, settings, writer).instrument(span)
1530-
}
1531-
}
1532-
15331511
/// The (successful) result of processing an asset
15341512
#[derive(Debug, Clone)]
15351513
pub enum ProcessResult {

crates/bevy_asset/src/processor/process.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ pub trait ErasedProcessor: Send + Sync {
245245
/// Deserialized `meta` as type-erased [`AssetMeta`], operating under the assumption that it matches the meta
246246
/// for the underlying [`Process`] impl.
247247
fn deserialize_meta(&self, meta: &[u8]) -> Result<Box<dyn AssetMetaDyn>, DeserializeMetaError>;
248+
/// Returns the type-path of the original [`Process`].
249+
fn type_path(&self) -> &'static str;
248250
/// Returns the default type-erased [`AssetMeta`] for the underlying [`Process`] impl.
249251
fn default_meta(&self) -> Box<dyn AssetMetaDyn>;
250252
}
@@ -281,6 +283,10 @@ impl<P: Process> ErasedProcessor for P {
281283
Ok(Box::new(meta))
282284
}
283285

286+
fn type_path(&self) -> &'static str {
287+
P::type_path()
288+
}
289+
284290
fn default_meta(&self) -> Box<dyn AssetMetaDyn> {
285291
Box::new(AssetMeta::<(), P>::new(AssetAction::Process {
286292
processor: P::type_path().to_string(),

crates/bevy_asset/src/server/loaders.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@ use crate::{
55
use alloc::{boxed::Box, sync::Arc, vec::Vec};
66
use async_broadcast::RecvError;
77
use bevy_platform::collections::HashMap;
8-
#[cfg(feature = "trace")]
9-
use bevy_reflect::TypePath;
108
use bevy_tasks::IoTaskPool;
119
use bevy_utils::TypeIdMap;
1210
use core::any::TypeId;
1311
use thiserror::Error;
1412
use tracing::warn;
1513

16-
#[cfg(feature = "trace")]
17-
use {
18-
crate::io::ReaderRequiredFeatures,
19-
alloc::string::ToString,
20-
bevy_tasks::ConditionalSendFuture,
21-
tracing::{info_span, instrument::Instrument},
22-
};
23-
2414
#[derive(Default)]
2515
pub(crate) struct AssetLoaders {
2616
loaders: Vec<MaybeAssetLoader>,
@@ -43,8 +33,6 @@ impl AssetLoaders {
4333
let loader_asset_type = TypeId::of::<L::Asset>();
4434
let loader_asset_type_name = core::any::type_name::<L::Asset>();
4535

46-
#[cfg(feature = "trace")]
47-
let loader = InstrumentedAssetLoader(loader);
4836
let loader = Arc::new(loader);
4937

5038
let (loader_index, is_new) =
@@ -314,39 +302,6 @@ impl MaybeAssetLoader {
314302
}
315303
}
316304

317-
#[cfg(feature = "trace")]
318-
#[derive(TypePath)]
319-
struct InstrumentedAssetLoader<T>(T);
320-
321-
#[cfg(feature = "trace")]
322-
impl<T: AssetLoader> AssetLoader for InstrumentedAssetLoader<T> {
323-
type Asset = T::Asset;
324-
type Settings = T::Settings;
325-
type Error = T::Error;
326-
327-
fn load(
328-
&self,
329-
reader: &mut dyn crate::io::Reader,
330-
settings: &Self::Settings,
331-
load_context: &mut crate::LoadContext,
332-
) -> impl ConditionalSendFuture<Output = Result<Self::Asset, Self::Error>> {
333-
let span = info_span!(
334-
"asset loading",
335-
loader = T::type_path(),
336-
asset = load_context.path().to_string(),
337-
);
338-
self.0.load(reader, settings, load_context).instrument(span)
339-
}
340-
341-
fn reader_required_features(settings: &Self::Settings) -> ReaderRequiredFeatures {
342-
T::reader_required_features(settings)
343-
}
344-
345-
fn extensions(&self) -> &[&str] {
346-
self.0.extensions()
347-
}
348-
}
349-
350305
#[cfg(test)]
351306
mod tests {
352307
use alloc::{format, string::String};

crates/bevy_asset/src/server/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,9 +1543,19 @@ impl AssetServer {
15431543
let asset_path = asset_path.clone_owned();
15441544
let load_context =
15451545
LoadContext::new(self, asset_path.clone(), load_dependencies, populate_hashes);
1546-
AssertUnwindSafe(loader.load(reader, settings, load_context))
1547-
.catch_unwind()
1548-
.await
1546+
let load = AssertUnwindSafe(loader.load(reader, settings, load_context)).catch_unwind();
1547+
#[cfg(feature = "trace")]
1548+
let load = {
1549+
use tracing::Instrument;
1550+
1551+
let span = tracing::info_span!(
1552+
"asset loading",
1553+
loader = loader.type_path(),
1554+
asset = asset_path.to_string()
1555+
);
1556+
load.instrument(span)
1557+
};
1558+
load.await
15491559
.map_err(|_| AssetLoadError::AssetLoaderPanic {
15501560
path: asset_path.clone_owned(),
15511561
loader_name: loader.type_path(),

0 commit comments

Comments
 (0)