MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / Log

Function Log

src/include/kernel_log.hpp:143–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141 */
142template <Level Lvl, typename... Args>
143__always_inline auto Log(etl::format_string<Args...> fmt, Args&&... args)
144 -> void {
145 if constexpr (Lvl < kMinLevel) {
146 return;
147 }
148
149 LogEntry entry{};
150 entry.seq = log_seq.fetch_add(1, std::memory_order_relaxed);
151 entry.core_id = cpu_io::GetCurrentCoreId();
152 entry.level = Lvl;
153 auto* end = etl::format_to_n(entry.msg, sizeof(entry.msg) - 1, fmt,
154 static_cast<Args&&>(args)...);
155 *end = '\0';
156
157 if (!log_queue.push(entry)) {
158 // 队列满:尝试排空后重试一次
159 TryDrain();
160 if (!log_queue.push(entry)) {
161 dropped_count.fetch_add(1, std::memory_order_relaxed);
162 return;
163 }
164 }
165
166 TryDrain();
167}
168
169} // namespace detail
170

Callers

nothing calls this directly

Calls 3

GetCurrentCoreIdFunction · 0.85
TryDrainFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected