-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add ENVOY_LOG_PERIODIC #12961
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
Merged
Merged
Add ENVOY_LOG_PERIODIC #12961
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
42a4eba
Add ENVOY_LOG_PERIODIC
oschaaf 85003d4
Review feedback
oschaaf aca8716
Amend comment
oschaaf 541e555
Review feedback II
oschaaf 15819e6
review feedback: uint64 where it's not implied
oschaaf cc387f0
Merge remote-tracking branch 'upstream/master' into envoy-log-periodic
oschaaf efbabc5
Fix platform issue, eliminate sleep() call.
oschaaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include <bitset> | ||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
@@ -403,9 +404,11 @@ template <Id id> class Loggable { | |
|
|
||
| #define ENVOY_LOG_FIRST_N(LEVEL, N, ...) \ | ||
| do { \ | ||
| static auto* countdown = new std::atomic<uint64_t>(); \ | ||
| if (countdown->fetch_add(1) < N) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
| static auto* countdown = new std::atomic<uint64_t>(); \ | ||
| if (countdown->fetch_add(1) < N) { \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The counter may eventually overflow. ;) |
||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| } \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
|
|
@@ -416,17 +419,40 @@ template <Id id> class Loggable { | |
|
|
||
| #define ENVOY_LOG_EVERY_NTH(LEVEL, N, ...) \ | ||
| do { \ | ||
| static auto* count = new std::atomic<uint64_t>(); \ | ||
| if ((count->fetch_add(1) % N) == 0) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
| static auto* count = new std::atomic<uint64_t>(); \ | ||
| if ((count->fetch_add(1) % N) == 0) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| } \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| #define ENVOY_LOG_EVERY_POW_2(LEVEL, ...) \ | ||
| do { \ | ||
| static auto* count = new std::atomic<uint64_t>(); \ | ||
| if (std::bitset<64>(1 + count->fetch_add(1)).count() == 1) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
| static auto* count = new std::atomic<uint64_t>(); \ | ||
| if (std::bitset<64>(1 /* for the first hit*/ + count->fetch_add(1)).count() == 1) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| } \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| // This is to get us to pass the format check. We reference a real-world time source here. | ||
| // We'd have to introduce a singleton for a time source here, and consensus was that avoiding | ||
| // that is preferable. | ||
| using t_logclock = std::chrono::steady_clock; // NOLINT | ||
|
|
||
| #define ENVOY_LOG_PERIODIC(LEVEL, CHRONO_DURATION, ...) \ | ||
| do { \ | ||
| if (ENVOY_LOG_COMP_LEVEL(ENVOY_LOGGER(), LEVEL)) { \ | ||
| static auto* last_hit = new std::atomic<int64_t>(); \ | ||
| auto last = last_hit->load(); \ | ||
| const auto now = t_logclock::now().time_since_epoch().count(); \ | ||
| if ((now - last) > \ | ||
oschaaf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::chrono::duration_cast<std::chrono::nanoseconds>(CHRONO_DURATION).count() && \ | ||
| last_hit->compare_exchange_strong(last, now)) { \ | ||
| ENVOY_LOG(LEVEL, ##__VA_ARGS__); \ | ||
| } \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.