Skip to content

Commit a10c400

Browse files
author
babenko
committed
Move more checks to the inlined part of IsLevelEnabled
commit_hash:ad986b1f46f36765b3d80b8e527b1f25ad966d42
1 parent e156140 commit a10c400

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

library/cpp/yt/logging/logger-inl.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,26 @@ Y_FORCE_INLINE ELogLevel TLogger::GetEffectiveLoggingLevel(ELogLevel level, cons
7777

7878
Y_FORCE_INLINE bool TLogger::IsLevelEnabled(ELogLevel level) const
7979
{
80-
// This is the first check which is intended to be inlined next to
81-
// logging invocation point. Check below is almost zero-cost due
82-
// to branch prediction (which requires inlining for proper work).
83-
if (level < MinLevel_) {
80+
if (!Category_) {
8481
return false;
8582
}
8683

87-
// Next check is heavier and requires full log manager definition which
88-
// is undesirable in -inl.h header file. This is why we extract it
89-
// to a separate method which is implemented in cpp file.
90-
return IsLevelEnabledHeavy(level);
84+
[[unlikely]] if (
85+
Category_->CurrentVersion.load(std::memory_order::relaxed) !=
86+
Category_->ActualVersion->load(std::memory_order::relaxed))
87+
{
88+
UpdateCategory();
89+
}
90+
91+
if (level < Category_->MinPlainTextLevel) {
92+
return false;
93+
}
94+
95+
if (level < GetThreadMinLogLevel()) {
96+
return false;
97+
}
98+
99+
return true;
91100
}
92101

93102
Y_FORCE_INLINE const TLogger& TLogger::operator()() const

library/cpp/yt/logging/logger.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,9 @@ const TLoggingCategory* TLogger::GetCategory() const
169169
return Category_;
170170
}
171171

172-
bool TLogger::IsLevelEnabledHeavy(ELogLevel level) const
172+
void TLogger::UpdateCategory() const
173173
{
174-
// Note that we managed to reach this point, i.e. level >= MinLevel_,
175-
// which implies that MinLevel_ != ELogLevel::Maximum, so this logger was not
176-
// default constructed, thus it has non-trivial category.
177-
YT_ASSERT(Category_);
178-
179-
if (Category_->CurrentVersion != Category_->ActualVersion->load(std::memory_order::relaxed)) {
180-
LogManager_->UpdateCategory(const_cast<TLoggingCategory*>(Category_));
181-
}
182-
183-
return
184-
level >= Category_->MinPlainTextLevel &&
185-
level >= ThreadMinLogLevel();
174+
LogManager_->UpdateCategory(const_cast<TLoggingCategory*>(Category_));
186175
}
187176

188177
bool TLogger::GetAbortOnAlert() const

library/cpp/yt/logging/logger.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,7 @@ class TLogger
274274
void ResetCoWState();
275275

276276
private:
277-
//! This method checks level against category's min level.
278-
//! Refer to comment in TLogger::IsLevelEnabled for more details.
279-
bool IsLevelEnabledHeavy(ELogLevel level) const;
277+
void UpdateCategory() const;
280278
};
281279

282280
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)