Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify callsite enabled check #3112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,28 +1105,32 @@ pub mod __macro_support {
}
}

/// Returns the callsite's cached Interest, or registers it for the
/// first time if it has not yet been registered.
/// Returns whether the callsite is enabled.
///
/// /!\ WARNING: This is *not* a stable API! /!\
/// This method, and all code contained in the `__macro_support` module, is
/// This type, and all code contained in the `__macro_support` module, is
/// a *private* API of `tracing`. It is exposed publicly because it is used
/// by the `tracing` macros, but it is not part of the stable versioned API.
/// Breaking changes to this module may occur in small-numbered versions
/// without warning.
#[inline]
pub fn interest(&'static self) -> Interest {
match self.interest.load(Ordering::Relaxed) {
pub fn is_enabled(&'static self) -> bool {
let interest = match self.interest.load(Ordering::Relaxed) {
Comment on lines 1116 to +1118
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should preserve the intent of #943. Namely, that the per-callsite cached interest check is still inlined.

Self::INTEREST_NEVER => Interest::never(),
Self::INTEREST_SOMETIMES => Interest::sometimes(),
Self::INTEREST_ALWAYS => Interest::always(),
_ => self.register(),
};

if interest.is_never() {
return false;
}

if interest.is_always() {
return true;
}
}

pub fn is_enabled(&self, interest: Interest) -> bool {
interest.is_always()
|| crate::dispatch::get_default(|default| default.enabled(self.meta))
crate::dispatch::get_default(|default| default.enabled(self.meta))
}

#[inline]
Expand Down
56 changes: 14 additions & 42 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ macro_rules! span {
level: $lvl,
fields: $($fields)*
};
let mut interest = $crate::collect::Interest::never();
if $crate::level_enabled!($lvl)
&& { interest = __CALLSITE.interest(); !interest.is_never() }
&& __CALLSITE.is_enabled(interest)
{

if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
let meta = __CALLSITE.metadata();
// span with explicit parent
$crate::Span::child_of(
Expand Down Expand Up @@ -63,11 +60,7 @@ macro_rules! span {
fields: $($fields)*
};

let mut interest = $crate::collect::Interest::never();
if $crate::level_enabled!($lvl)
&& { interest = __CALLSITE.interest(); !interest.is_never() }
&& __CALLSITE.is_enabled(interest)
{
if $crate::level_enabled!($lvl)&& __CALLSITE.is_enabled() {
let meta = __CALLSITE.metadata();
// span with contextual parent
$crate::Span::new(
Expand Down Expand Up @@ -595,11 +588,7 @@ macro_rules! event {
fields: $($fields)*
};

let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {
if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
$crate::__tracing_log!(
$lvl,
Expand Down Expand Up @@ -648,11 +637,8 @@ macro_rules! event {
level: $lvl,
fields: $($fields)*
};
let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {

if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
let meta = __CALLSITE.metadata();
// event with contextual parent
Expand Down Expand Up @@ -705,11 +691,7 @@ macro_rules! event {
fields: $($fields)*
};

let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {
if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
$crate::__tracing_log!(
$lvl,
Expand Down Expand Up @@ -758,11 +740,7 @@ macro_rules! event {
fields: $($fields)*
};

let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {
if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
$crate::__tracing_log!(
$lvl,
Expand Down Expand Up @@ -810,11 +788,8 @@ macro_rules! event {
level: $lvl,
fields: $($fields)*
};
let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {

if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
let meta = __CALLSITE.metadata();
// event with contextual parent
Expand Down Expand Up @@ -865,11 +840,8 @@ macro_rules! event {
level: $lvl,
fields: $($fields)*
};
let enabled = $crate::level_enabled!($lvl) && {
let interest = __CALLSITE.interest();
!interest.is_never() && __CALLSITE.is_enabled(interest)
};
if enabled {

if $crate::level_enabled!($lvl) && __CALLSITE.is_enabled() {
(|value_set: $crate::field::ValueSet| {
let meta = __CALLSITE.metadata();
// event with contextual parent
Expand Down Expand Up @@ -1195,8 +1167,8 @@ macro_rules! enabled {
level: $lvl,
fields: $($fields)*
};
let interest = __CALLSITE.interest();
if !interest.is_never() && __CALLSITE.is_enabled(interest) {

if __CALLSITE.is_enabled() {
let meta = __CALLSITE.metadata();
$crate::dispatch::get_default(|current| current.enabled(meta))
} else {
Expand Down