Skip to content

Commit

Permalink
Log: Switch to enum class
Browse files Browse the repository at this point in the history
Need to change the channel to a bitset too.. the string lookups are
horribly slow, and conflict when one is a prefix of another.
  • Loading branch information
stenzek committed Sep 21, 2024
1 parent 8838120 commit 3dca598
Show file tree
Hide file tree
Showing 146 changed files with 292 additions and 292 deletions.
2 changes: 1 addition & 1 deletion src/common/dynamic_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#endif
#endif

Log_SetChannel(DynamicLibrary);
LOG_CHANNEL(DynamicLibrary);

DynamicLibrary::DynamicLibrary() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/common/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <unistd.h>
#endif

Log_SetChannel(FileSystem);
LOG_CHANNEL(FileSystem);

#ifndef __ANDROID__

Expand Down
128 changes: 63 additions & 65 deletions src/common/log.cpp

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions src/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
#include <mutex>
#include <string_view>

enum LOGLEVEL
namespace Log {
enum class Level
{
LOGLEVEL_NONE, // Silences all log traffic
LOGLEVEL_ERROR,
LOGLEVEL_WARNING,
LOGLEVEL_INFO,
LOGLEVEL_VERBOSE,
LOGLEVEL_DEV,
LOGLEVEL_DEBUG,
LOGLEVEL_TRACE,

LOGLEVEL_COUNT
None, // Silences all log traffic
Error,
Warning,
Info,
Verbose,
Dev,
Debug,
Trace,

Count
};

namespace Log {
// log message callback type
using CallbackFunctionType = void (*)(void* pUserParam, const char* channelName, const char* functionName,
LOGLEVEL level, std::string_view message);
using CallbackFunctionType = void (*)(void* pUserParam, const char* channelName, const char* functionName, Level level,
std::string_view message);

// registers a log callback
void RegisterCallback(CallbackFunctionType callbackFunction, void* pUserParam);
Expand All @@ -53,43 +53,43 @@ void SetDebugOutputParams(bool enabled);
void SetFileOutputParams(bool enabled, const char* filename, bool timestamps = true);

// Returns the current global filtering level.
LOGLEVEL GetLogLevel();
Level GetLogLevel();

// Returns true if log messages for the specified log level/filter would not be filtered (and visible).
bool IsLogVisible(LOGLEVEL level, const char* channelName);
bool IsLogVisible(Level level, const char* channelName);

// Sets global filtering level, messages below this level won't be sent to any of the logging sinks.
void SetLogLevel(LOGLEVEL level);
void SetLogLevel(Level level);

// Sets global filter, any messages from these channels won't be sent to any of the logging sinks.
void SetLogFilter(std::string_view filter);

// writes a message to the log
void Write(const char* channelName, LOGLEVEL level, std::string_view message);
void Write(const char* channelName, const char* functionName, LOGLEVEL level, std::string_view message);
void WriteFmtArgs(const char* channelName, LOGLEVEL level, fmt::string_view fmt, fmt::format_args args);
void WriteFmtArgs(const char* channelName, const char* functionName, LOGLEVEL level, fmt::string_view fmt,
void Write(const char* channelName, Level level, std::string_view message);
void Write(const char* channelName, const char* functionName, Level level, std::string_view message);
void WriteFmtArgs(const char* channelName, Level level, fmt::string_view fmt, fmt::format_args args);
void WriteFmtArgs(const char* channelName, const char* functionName, Level level, fmt::string_view fmt,
fmt::format_args args);

ALWAYS_INLINE static void FastWrite(const char* channelName, LOGLEVEL level, std::string_view message)
ALWAYS_INLINE static void FastWrite(const char* channelName, Level level, std::string_view message)
{
if (level <= GetLogLevel()) [[unlikely]]
Write(channelName, level, message);
}
ALWAYS_INLINE static void FastWrite(const char* channelName, const char* functionName, LOGLEVEL level,
ALWAYS_INLINE static void FastWrite(const char* channelName, const char* functionName, Level level,
std::string_view message)
{
if (level <= GetLogLevel()) [[unlikely]]
Write(channelName, functionName, level, message);
}
template<typename... T>
ALWAYS_INLINE static void FastWrite(const char* channelName, LOGLEVEL level, fmt::format_string<T...> fmt, T&&... args)
ALWAYS_INLINE static void FastWrite(const char* channelName, Level level, fmt::format_string<T...> fmt, T&&... args)
{
if (level <= GetLogLevel()) [[unlikely]]
WriteFmtArgs(channelName, level, fmt, fmt::make_format_args(args...));
}
template<typename... T>
ALWAYS_INLINE static void FastWrite(const char* channelName, const char* functionName, LOGLEVEL level,
ALWAYS_INLINE static void FastWrite(const char* channelName, const char* functionName, Level level,
fmt::format_string<T...> fmt, T&&... args)
{
if (level <= GetLogLevel()) [[unlikely]]
Expand All @@ -98,17 +98,17 @@ ALWAYS_INLINE static void FastWrite(const char* channelName, const char* functio
} // namespace Log

// log wrappers
#define Log_SetChannel(ChannelName) [[maybe_unused]] static const char* ___LogChannel___ = #ChannelName;
#define LOG_CHANNEL(name) [[maybe_unused]] static const char* ___LogChannel___ = #name;

#define ERROR_LOG(...) Log::FastWrite(___LogChannel___, __func__, LOGLEVEL_ERROR, __VA_ARGS__)
#define WARNING_LOG(...) Log::FastWrite(___LogChannel___, __func__, LOGLEVEL_WARNING, __VA_ARGS__)
#define INFO_LOG(...) Log::FastWrite(___LogChannel___, LOGLEVEL_INFO, __VA_ARGS__)
#define VERBOSE_LOG(...) Log::FastWrite(___LogChannel___, LOGLEVEL_VERBOSE, __VA_ARGS__)
#define DEV_LOG(...) Log::FastWrite(___LogChannel___, LOGLEVEL_DEV, __VA_ARGS__)
#define ERROR_LOG(...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Error, __VA_ARGS__)
#define WARNING_LOG(...) Log::FastWrite(___LogChannel___, __func__, Log::Level::Warning, __VA_ARGS__)
#define INFO_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Info, __VA_ARGS__)
#define VERBOSE_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Verbose, __VA_ARGS__)
#define DEV_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Dev, __VA_ARGS__)

#ifdef _DEBUG
#define DEBUG_LOG(...) Log::FastWrite(___LogChannel___, LOGLEVEL_DEBUG, __VA_ARGS__)
#define TRACE_LOG(...) Log::FastWrite(___LogChannel___, LOGLEVEL_TRACE, __VA_ARGS__)
#define DEBUG_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Debug, __VA_ARGS__)
#define TRACE_LOG(...) Log::FastWrite(___LogChannel___, Log::Level::Trace, __VA_ARGS__)
#else
#define DEBUG_LOG(...) \
do \
Expand Down
2 changes: 1 addition & 1 deletion src/common/memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <unistd.h>
#endif

Log_SetChannel(MemMap);
LOG_CHANNEL(MemMap);

namespace MemMap {
/// Allocates RWX memory at the specified address.
Expand Down
2 changes: 1 addition & 1 deletion src/common/progress_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdio>
#include <limits>

Log_SetChannel(ProgressCallback);
LOG_CHANNEL(ProgressCallback);

static ProgressCallback s_nullProgressCallbacks;
ProgressCallback* ProgressCallback::NullProgressCallback = &s_nullProgressCallbacks;
Expand Down
2 changes: 1 addition & 1 deletion src/common/threading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif
#endif

Log_SetChannel(Threading);
LOG_CHANNEL(Threading);

#ifdef _WIN32
union FileTimeU64Union
Expand Down
2 changes: 1 addition & 1 deletion src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <unordered_set>
#include <vector>

Log_SetChannel(Achievements);
LOG_CHANNEL(Achievements);

#ifdef ENABLE_RAINTEGRATION
// RA_Interface ends up including windows.h, with its silly macros.
Expand Down
2 changes: 1 addition & 1 deletion src/core/analog_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <cmath>

Log_SetChannel(AnalogController);
LOG_CHANNEL(AnalogController);

AnalogController::AnalogController(u32 index) : Controller(index)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/analog_joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "IconsPromptFont.h"
#include "fmt/format.h"

Log_SetChannel(AnalogJoystick);
LOG_CHANNEL(AnalogJoystick);

AnalogJoystick::AnalogJoystick(u32 index) : Controller(index)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/bios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "common/path.h"
#include "common/string_util.h"

Log_SetChannel(BIOS);
LOG_CHANNEL(BIOS);

namespace BIOS {
static const ImageInfo* GetInfoForHash(const std::span<u8> image, const ImageInfo::Hash& hash);
Expand Down
4 changes: 2 additions & 2 deletions src/core/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <tuple>
#include <utility>

Log_SetChannel(Bus);
LOG_CHANNEL(Bus);

// TODO: Get rid of page code bits, instead use page faults to track SMC.

Expand Down Expand Up @@ -933,7 +933,7 @@ void Bus::AddTTYCharacter(char ch)
{
if (!s_tty_line_buffer.empty())
{
Log::FastWrite("TTY", "", LOGLEVEL_INFO, "\033[1;34m{}\033[0m", s_tty_line_buffer);
Log::FastWrite("TTY", "", Log::Level::Info, "\033[1;34m{}\033[0m", s_tty_line_buffer);
#ifdef _DEBUG
if (CPU::IsTraceEnabled())
CPU::WriteToExecutionLog("TTY: %s\n", s_tty_line_buffer.c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <map>
#include <vector>

Log_SetChannel(CDROM);
LOG_CHANNEL(CDROM);

namespace CDROM {
namespace {
Expand Down Expand Up @@ -1621,7 +1621,7 @@ void CDROM::EndCommand()
void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
{
const CommandInfo& ci = s_command_info[static_cast<u8>(s_command)];
if (Log::IsLogVisible(LOGLEVEL_DEV, ___LogChannel___)) [[unlikely]]
if (Log::IsLogVisible(Log::Level::Dev, ___LogChannel___)) [[unlikely]]
{
SmallString params;
for (u32 i = 0; i < s_param_fifo.GetSize(); i++)
Expand Down
2 changes: 1 addition & 1 deletion src/core/cdrom_async_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "common/assert.h"
#include "common/log.h"
#include "common/timer.h"
Log_SetChannel(CDROMAsyncReader);
LOG_CHANNEL(CDROMAsyncReader);

CDROMAsyncReader::CDROMAsyncReader() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/core/cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <sstream>
#include <type_traits>

Log_SetChannel(Cheats);
LOG_CHANNEL(Cheats);

static std::array<u32, 256> cht_register; // Used for D7 ,51 & 52 cheat types

Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_code_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "common/log.h"
#include "common/memmap.h"

Log_SetChannel(CPU::CodeCache);
LOG_CHANNEL(CPU::CodeCache);

// Enable dumping of recompiled block code size statistics.
// #define DUMP_CODE_SIZE_STATS 1
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <cstdio>

Log_SetChannel(CPU::Core);
LOG_CHANNEL(CPU::Core);

namespace CPU {
enum class ExecutionBreakType
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_newrec_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <cstdint>
#include <limits>

Log_SetChannel(NewRec::Compiler);
LOG_CHANNEL(NewRec::Compiler);

// TODO: direct link skip delay slot check
// TODO: speculative constants
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_newrec_compiler_aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifdef CPU_ARCH_ARM32

Log_SetChannel(CPU::NewRec);
LOG_CHANNEL(CPU::NewRec);

#define PTR(x) vixl::aarch32::MemOperand(RSTATE, (((u8*)(x)) - ((u8*)&g_state)))
#define RMEMBASE vixl::aarch32::r3
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_newrec_compiler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifdef CPU_ARCH_ARM64

Log_SetChannel(CPU::NewRec);
LOG_CHANNEL(CPU::NewRec);

#define PTR(x) vixl::aarch64::MemOperand(RSTATE, (((u8*)(x)) - ((u8*)&g_state)))

Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_newrec_compiler_riscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#ifdef CPU_ARCH_RISCV64

Log_SetChannel(CPU::NewRec);
LOG_CHANNEL(CPU::NewRec);

#ifdef ENABLE_HOST_DISASSEMBLY
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_newrec_compiler_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#ifdef CPU_ARCH_X64

Log_SetChannel(CPU::NewRec);
LOG_CHANNEL(CPU::NewRec);

#define RMEMBASE cg->rbx
#define RSTATE cg->rbp
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_pgxp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <climits>
#include <cmath>

Log_SetChannel(CPU::PGXP);
LOG_CHANNEL(CPU::PGXP);

// #define LOG_VALUES 1
// #define LOG_LOOKUPS 1
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_recompiler_code_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "common/log.h"

Log_SetChannel(CPU::Recompiler);
LOG_CHANNEL(CPU::Recompiler);

// TODO: Turn load+sext/zext into a single signed/unsigned load
// TODO: mulx/shlx/etc
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_recompiler_code_generator_aarch32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#ifdef CPU_ARCH_ARM32

Log_SetChannel(CPU::Recompiler);
LOG_CHANNEL(CPU::Recompiler);

#ifdef ENABLE_HOST_DISASSEMBLY
#include "vixl/aarch32/disasm-aarch32.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_recompiler_code_generator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#ifdef CPU_ARCH_ARM64

Log_SetChannel(CPU::Recompiler);
LOG_CHANNEL(CPU::Recompiler);

#ifdef ENABLE_HOST_DISASSEMBLY
#include "vixl/aarch64/disasm-aarch64.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_recompiler_code_generator_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "common/log.h"

Log_SetChannel(Recompiler::CodeGenerator);
LOG_CHANNEL(Recompiler::CodeGenerator);

namespace CPU::Recompiler {

Expand Down
4 changes: 2 additions & 2 deletions src/core/cpu_recompiler_code_generator_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#ifdef CPU_ARCH_X64

Log_SetChannel(Recompiler::CodeGenerator);
LOG_CHANNEL(Recompiler::CodeGenerator);

#ifdef ENABLE_HOST_DISASSEMBLY
#include "Zycore/Format.h"
Expand Down Expand Up @@ -260,7 +260,7 @@ void CPU::CodeCache::DisassembleAndLogHostCode(const void* start, u32 size)
else
hex.append(" ");
}
Log::FastWrite("HostCode", "", LOGLEVEL_DEBUG, " {:016X} {} {}",
Log::FastWrite("HostCode", "", Log::Level::Debug, " {:016X} {} {}",
static_cast<u64>(reinterpret_cast<uintptr_t>(ptr)), hex, buffer);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_recompiler_register_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <cinttypes>

Log_SetChannel(CPU::Recompiler);
LOG_CHANNEL(CPU::Recompiler);

namespace CPU::Recompiler {

Expand Down
2 changes: 1 addition & 1 deletion src/core/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <memory>
#include <vector>

Log_SetChannel(DMA);
LOG_CHANNEL(DMA);

namespace DMA {
namespace {
Expand Down
Loading

0 comments on commit 3dca598

Please sign in to comment.