File indexing completed on 2025-12-16 09:40:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef ABSL_LOG_INTERNAL_VLOG_CONFIG_H_
0025 #define ABSL_LOG_INTERNAL_VLOG_CONFIG_H_
0026
0027
0028
0029 #include <atomic>
0030 #include <cstdint>
0031 #include <functional>
0032 #include <limits>
0033 #include <type_traits>
0034
0035 #include "absl/base/attributes.h"
0036 #include "absl/base/config.h"
0037 #include "absl/base/optimization.h"
0038 #include "absl/base/thread_annotations.h"
0039 #include "absl/strings/string_view.h"
0040
0041 namespace absl {
0042 ABSL_NAMESPACE_BEGIN
0043 namespace log_internal {
0044
0045 class SyntheticBinary;
0046 class VLogSite;
0047
0048 int RegisterAndInitialize(VLogSite* v);
0049 void UpdateVLogSites();
0050 constexpr int kUseFlag = (std::numeric_limits<int16_t>::min)();
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 class VLogSite final {
0061 public:
0062
0063 explicit constexpr VLogSite(const char* f)
0064 : file_(f), v_(kUninitialized), next_(nullptr) {}
0065 VLogSite(const VLogSite&) = delete;
0066 VLogSite& operator=(const VLogSite&) = delete;
0067
0068
0069
0070
0071 ABSL_ATTRIBUTE_ALWAYS_INLINE
0072 bool IsEnabled(int level) {
0073 int stale_v = v_.load(std::memory_order_relaxed);
0074 if (ABSL_PREDICT_TRUE(level > stale_v)) {
0075 return false;
0076 }
0077
0078
0079
0080
0081
0082 #if ABSL_HAVE_BUILTIN(__builtin_constant_p) || defined(__GNUC__)
0083 if (__builtin_constant_p(level)) {
0084 if (level == 0) return SlowIsEnabled0(stale_v);
0085 if (level == 1) return SlowIsEnabled1(stale_v);
0086 if (level == 2) return SlowIsEnabled2(stale_v);
0087 if (level == 3) return SlowIsEnabled3(stale_v);
0088 if (level == 4) return SlowIsEnabled4(stale_v);
0089 if (level == 5) return SlowIsEnabled5(stale_v);
0090 }
0091 #endif
0092 return SlowIsEnabled(stale_v, level);
0093 }
0094
0095 private:
0096 friend int log_internal::RegisterAndInitialize(VLogSite* v);
0097 friend void log_internal::UpdateVLogSites();
0098 friend class log_internal::SyntheticBinary;
0099 static constexpr int kUninitialized = (std::numeric_limits<int>::max)();
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 ABSL_ATTRIBUTE_NOINLINE
0110 bool SlowIsEnabled(int stale_v, int level);
0111 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled0(int stale_v);
0112 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled1(int stale_v);
0113 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled2(int stale_v);
0114 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled3(int stale_v);
0115 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled4(int stale_v);
0116 ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled5(int stale_v);
0117
0118
0119 const char* const file_;
0120 std::atomic<int> v_;
0121 std::atomic<VLogSite*> next_;
0122 };
0123 static_assert(std::is_trivially_destructible<VLogSite>::value,
0124 "VLogSite must be trivially destructible");
0125
0126
0127
0128 int VLogLevel(absl::string_view file);
0129
0130
0131
0132
0133 int RegisterAndInitialize(VLogSite* v);
0134
0135
0136 void UpdateVLogSites();
0137
0138
0139
0140 void UpdateVModule(absl::string_view vmodule);
0141
0142
0143
0144 int UpdateGlobalVLogLevel(int v);
0145
0146
0147
0148
0149
0150 int PrependVModule(absl::string_view module_pattern, int log_level);
0151
0152
0153
0154 void OnVLogVerbosityUpdate(std::function<void()> cb);
0155
0156
0157 VLogSite* SetVModuleListHeadForTestOnly(VLogSite* v);
0158
0159 }
0160 ABSL_NAMESPACE_END
0161 }
0162
0163 #endif