Skip to content

Commit

Permalink
fixup 1
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Jan 6, 2024
1 parent 9e3a43e commit 59b42fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
6 changes: 2 additions & 4 deletions tracing-tracy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ pub trait Config {
/// Specify the maximum number of stack frames that will be collected.
///
/// Note that enabling callstack collection can and will introduce a non-trivial overhead at
/// every instrumentation point. Specifying 0 frames (which is the default) will disable stack
/// trace collection.
/// every instrumentation point. Specifying 0 frames will disable stack trace collection.
///
/// Default implementation returns `0`.
fn stack_depth(&self) -> u16 {
Expand Down Expand Up @@ -103,8 +102,7 @@ impl DynamicConfig {
/// Specify the maximum number of stack frames that will be collected.
///
/// Note that enabling callstack collection can and will introduce a non-trivial overhead at
/// every instrumentation point. Specifying 0 frames (which is the default) will disable stack
/// trace collection.
/// every instrumentation point. Specifying 0 frames will disable stack trace collection.
///
/// Defaults to `0`.
#[must_use]
Expand Down
27 changes: 10 additions & 17 deletions tracing-tracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ use tracing_core::{
};
use tracing_subscriber::fmt::format::FormatFields;
use tracing_subscriber::{
fmt::FormattedFields,
layer::{Context, Layer},
registry,
};
Expand All @@ -68,6 +67,8 @@ use utils::{StrCache, StrCacheGuard, VecCell};
pub use client;
mod config;

type TracyFields<C> = tracing_subscriber::fmt::FormattedFields<<C as Config>::Formatter>;

thread_local! {
/// A stack of spans currently active on the current thread.
static TRACY_SPAN_STACK: VecCell<(Span, u64)> = const { VecCell::new() };
Expand Down Expand Up @@ -171,13 +172,9 @@ where
let Some(span) = ctx.span(id) else { return };

let mut extensions = span.extensions_mut();
if extensions
.get_mut::<FormattedFields<C::Formatter>>()
.is_none()
{
let mut fields = FormattedFields::<C::Formatter>::new(
CACHE.with(|cache| cache.acquire().into_inner()),
);
if extensions.get_mut::<TracyFields<C>>().is_none() {
let mut fields =
TracyFields::<C>::new(CACHE.with(|cache| cache.acquire().into_inner()));
if self
.config
.formatter()
Expand All @@ -193,12 +190,11 @@ where
let Some(span) = ctx.span(id) else { return };

let mut extensions = span.extensions_mut();
if let Some(fields) = extensions.get_mut::<FormattedFields<C::Formatter>>() {
if let Some(fields) = extensions.get_mut::<TracyFields<C>>() {
let _ = self.config.formatter().add_fields(fields, values);
} else {
let mut fields = FormattedFields::<C::Formatter>::new(
CACHE.with(|cache| cache.acquire().into_inner()),
);
let mut fields =
TracyFields::<C>::new(CACHE.with(|cache| cache.acquire().into_inner()));
if self
.config
.formatter()
Expand Down Expand Up @@ -240,7 +236,7 @@ where
let Some(span) = ctx.span(id) else { return };

let extensions = span.extensions();
let fields = extensions.get::<FormattedFields<C::Formatter>>();
let fields = extensions.get::<TracyFields<C>>();
let stack_frame = {
let metadata = span.metadata();
let file = metadata.file().unwrap_or("<not available>");
Expand Down Expand Up @@ -311,10 +307,7 @@ where
fn on_close(&self, id: Id, ctx: Context<'_, S>) {
let Some(span) = ctx.span(&id) else { return };

if let Some(fields) = span
.extensions_mut()
.get_mut::<FormattedFields<C::Formatter>>()
{
if let Some(fields) = span.extensions_mut().get_mut::<TracyFields<C>>() {
let buf = mem::take(&mut fields.fields);
CACHE.with(|cache| drop(StrCacheGuard::new(cache, buf)));
};
Expand Down

0 comments on commit 59b42fa

Please sign in to comment.