mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-28 13:04:47 +00:00
Fix tracing-duration-export
compilation (#835)
## Summary I'm unable to run `puffin-cli` on `main` as the `tracing-durations-export` is marked as optional, but the crate actually depends on it to compile. Further, without `tracing-durations-export`, there are `Option` types that can't resolve to a concrete type. This PR fixes compilation with and without the feature.
This commit is contained in:
parent
c06bf658bb
commit
aeefe65227
4 changed files with 56 additions and 50 deletions
|
@ -81,6 +81,7 @@ tokio-util = { version = "0.7.10", features = ["compat"] }
|
||||||
toml = { version = "0.8.8" }
|
toml = { version = "0.8.8" }
|
||||||
toml_edit = { version = "0.21.0" }
|
toml_edit = { version = "0.21.0" }
|
||||||
tracing = { version = "0.1.40" }
|
tracing = { version = "0.1.40" }
|
||||||
|
tracing-durations-export = { version = "0.1.0", features = ["plot"] }
|
||||||
tracing-indicatif = { version = "0.3.6" }
|
tracing-indicatif = { version = "0.3.6" }
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
tracing-tree = { version = "0.3.0" }
|
tracing-tree = { version = "0.3.0" }
|
||||||
|
|
|
@ -61,12 +61,12 @@ thiserror = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
toml = { workspace = true }
|
toml = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
|
tracing-durations-export = { workspace = true, features = ["plot"], optional = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
tracing-tree = { workspace = true }
|
tracing-tree = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
waitmap = { workspace = true }
|
waitmap = { workspace = true }
|
||||||
which = { workspace = true }
|
which = { workspace = true }
|
||||||
tracing-durations-export = { version = "0.1.0", features = ["plot"], optional = true }
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
mimalloc = "0.1.39"
|
mimalloc = "0.1.39"
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
use tracing_durations_export::plot::PlotConfig;
|
#[cfg(feature = "tracing-durations-export")]
|
||||||
use tracing_durations_export::{DurationsLayerBuilder, DurationsLayerDropGuard};
|
use tracing_durations_export::{
|
||||||
|
plot::PlotConfig, DurationsLayer, DurationsLayerBuilder, DurationsLayerDropGuard,
|
||||||
|
};
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::{EnvFilter, Layer, Registry};
|
||||||
use tracing_tree::time::Uptime;
|
use tracing_tree::time::Uptime;
|
||||||
use tracing_tree::HierarchicalLayer;
|
use tracing_tree::HierarchicalLayer;
|
||||||
|
|
||||||
|
@ -26,39 +24,7 @@ pub(crate) enum Level {
|
||||||
/// The [`Level`] is used to dictate the default filters (which can be overridden by the `RUST_LOG`
|
/// The [`Level`] is used to dictate the default filters (which can be overridden by the `RUST_LOG`
|
||||||
/// environment variable) along with the formatting of the output. For example, [`Level::Verbose`]
|
/// environment variable) along with the formatting of the output. For example, [`Level::Verbose`]
|
||||||
/// includes targets and timestamps, along with all `puffin=debug` messages by default.
|
/// includes targets and timestamps, along with all `puffin=debug` messages by default.
|
||||||
pub(crate) fn setup_logging(level: Level) -> Option<DurationsLayerDropGuard> {
|
pub(crate) fn setup_logging(level: Level, duration: impl Layer<Registry> + Send + Sync) {
|
||||||
let (duration_layer, guard) = {
|
|
||||||
#[cfg(feature = "tracing-durations-export")]
|
|
||||||
if let Ok(location) = env::var("TRACING_DURATIONS_FILE") {
|
|
||||||
let location = PathBuf::from(location);
|
|
||||||
if let Some(parent) = location.parent() {
|
|
||||||
fs_err::create_dir_all(parent)
|
|
||||||
.expect("Failed to create parent of TRACING_DURATIONS_FILE");
|
|
||||||
}
|
|
||||||
let plot_config = PlotConfig {
|
|
||||||
multi_lane: true,
|
|
||||||
min_length: Some(Duration::from_secs_f32(0.002)),
|
|
||||||
remove: Some(
|
|
||||||
["get_cached_with_callback".to_string()]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
),
|
|
||||||
..PlotConfig::default()
|
|
||||||
};
|
|
||||||
let (layer, guard) = DurationsLayerBuilder::default()
|
|
||||||
.durations_file(&location)
|
|
||||||
.plot_file(location.with_extension("svg"))
|
|
||||||
.plot_config(plot_config)
|
|
||||||
.build()
|
|
||||||
.expect("Couldn't create TRACING_DURATIONS_FILE files");
|
|
||||||
(Some(layer), Some(guard))
|
|
||||||
} else {
|
|
||||||
(None, None)
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "tracing-durations-export"))]
|
|
||||||
(None, None)
|
|
||||||
};
|
|
||||||
|
|
||||||
match level {
|
match level {
|
||||||
Level::Default => {
|
Level::Default => {
|
||||||
// Show nothing, but allow `RUST_LOG` to override.
|
// Show nothing, but allow `RUST_LOG` to override.
|
||||||
|
@ -68,7 +34,7 @@ pub(crate) fn setup_logging(level: Level) -> Option<DurationsLayerDropGuard> {
|
||||||
|
|
||||||
// Regardless of the tracing level, show messages without any adornment.
|
// Regardless of the tracing level, show messages without any adornment.
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(duration_layer)
|
.with(duration)
|
||||||
.with(filter)
|
.with(filter)
|
||||||
.with(
|
.with(
|
||||||
tracing_subscriber::fmt::layer()
|
tracing_subscriber::fmt::layer()
|
||||||
|
@ -86,7 +52,7 @@ pub(crate) fn setup_logging(level: Level) -> Option<DurationsLayerDropGuard> {
|
||||||
|
|
||||||
// Regardless of the tracing level, include the uptime and target for each message.
|
// Regardless of the tracing level, include the uptime and target for each message.
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(duration_layer)
|
.with(duration)
|
||||||
.with(filter)
|
.with(filter)
|
||||||
.with(
|
.with(
|
||||||
HierarchicalLayer::default()
|
HierarchicalLayer::default()
|
||||||
|
@ -97,6 +63,38 @@ pub(crate) fn setup_logging(level: Level) -> Option<DurationsLayerDropGuard> {
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
guard
|
|
||||||
|
/// Setup the `TRACING_DURATIONS_FILE` environment variable to enable tracing durations.
|
||||||
|
#[cfg(feature = "tracing-durations-export")]
|
||||||
|
pub(crate) fn setup_duration() -> (
|
||||||
|
Option<DurationsLayer<Registry>>,
|
||||||
|
Option<DurationsLayerDropGuard>,
|
||||||
|
) {
|
||||||
|
if let Ok(location) = std::env::var("TRACING_DURATIONS_FILE") {
|
||||||
|
let location = std::path::PathBuf::from(location);
|
||||||
|
if let Some(parent) = location.parent() {
|
||||||
|
fs_err::create_dir_all(parent)
|
||||||
|
.expect("Failed to create parent of TRACING_DURATIONS_FILE");
|
||||||
|
}
|
||||||
|
let plot_config = PlotConfig {
|
||||||
|
multi_lane: true,
|
||||||
|
min_length: Some(std::time::Duration::from_secs_f32(0.002)),
|
||||||
|
remove: Some(
|
||||||
|
["get_cached_with_callback".to_string()]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
..PlotConfig::default()
|
||||||
|
};
|
||||||
|
let (layer, guard) = DurationsLayerBuilder::default()
|
||||||
|
.durations_file(&location)
|
||||||
|
.plot_file(location.with_extension("svg"))
|
||||||
|
.plot_config(plot_config)
|
||||||
|
.build()
|
||||||
|
.expect("Couldn't create TRACING_DURATIONS_FILE files");
|
||||||
|
(Some(layer), Some(guard))
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,11 +415,18 @@ async fn inner() -> Result<ExitStatus> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
// Configure the `tracing` crate, which controls internal logging.
|
// Configure the `tracing` crate, which controls internal logging.
|
||||||
let _guard = logging::setup_logging(if cli.verbose {
|
#[cfg(feature = "tracing-durations-export")]
|
||||||
|
let (duration_layer, _duration_guard) = logging::setup_duration();
|
||||||
|
#[cfg(not(feature = "tracing-durations-export"))]
|
||||||
|
let duration_layer = None::<tracing_subscriber::layer::Identity>;
|
||||||
|
logging::setup_logging(
|
||||||
|
if cli.verbose {
|
||||||
logging::Level::Verbose
|
logging::Level::Verbose
|
||||||
} else {
|
} else {
|
||||||
logging::Level::Default
|
logging::Level::Default
|
||||||
});
|
},
|
||||||
|
duration_layer,
|
||||||
|
);
|
||||||
|
|
||||||
// Configure the `Printer`, which controls user-facing output in the CLI.
|
// Configure the `Printer`, which controls user-facing output in the CLI.
|
||||||
let printer = if cli.quiet {
|
let printer = if cli.quiet {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue