Fixup for LOG system.

Register all channels at program initialization and allow duplicates.
This commit is contained in:
Nekotekina 2020-01-31 12:01:17 +03:00
parent 59a0f810b9
commit 007a7a5859
27 changed files with 63 additions and 105 deletions

View File

@ -49,7 +49,6 @@ void fmt_class_string<logs::level>::format(std::string& out, u64 arg)
case logs::level::warning: return "Warning";
case logs::level::notice: return "Notice";
case logs::level::trace: return "Trace";
case logs::level::_uninit: return unknown;
}
return unknown;
@ -94,22 +93,6 @@ namespace logs
void log(logs::level sev, const char* text, std::size_t size);
};
struct channel_info
{
channel* pointer = nullptr;
level enabled = level::notice;
void set_level(level value)
{
enabled = value;
if (pointer)
{
pointer->enabled = value;
}
}
};
struct stored_message
{
message m;
@ -128,7 +111,7 @@ namespace logs
virtual void log(u64 stamp, const message& msg, const std::string& prefix, const std::string& text) override;
// Channel registry
std::unordered_map<std::string, channel_info> channels;
std::unordered_multimap<std::string, channel*> channels;
// Messages for delayed listener initialization
std::vector<stored_message> messages;
@ -174,19 +157,11 @@ namespace logs
return timebase.get();
}
channel GENERAL("");
channel LOADER("LDR");
channel MEMORY("MEM");
channel RSX("RSX");
channel HLE("HLE");
channel PPU("PPU");
channel SPU("SPU");
// Channel registry mutex
shared_mutex g_mutex;
static shared_mutex g_mutex;
// Must be set to true in main()
atomic_t<bool> g_init{false};
static atomic_t<bool> g_init{false};
void reset()
{
@ -194,7 +169,7 @@ namespace logs
for (auto&& pair : get_logger()->channels)
{
pair.second.set_level(level::notice);
pair.second->enabled = level::notice;
}
}
@ -202,7 +177,13 @@ namespace logs
{
std::lock_guard lock(g_mutex);
get_logger()->channels[ch_name].set_level(value);
auto found = get_logger()->channels.equal_range(ch_name);
while (found.first != found.second)
{
found.first->second->enabled = value;
found.first++;
}
}
// Must be called in main() to stop accumulating messages in g_messages
@ -211,6 +192,7 @@ namespace logs
if (!g_init)
{
std::lock_guard lock(g_mutex);
printf("DEBUG: %zu log messages accumulated. %zu channels registered.\n", get_logger()->messages.size(), get_logger()->channels.size());
get_logger()->messages.clear();
g_init = true;
}
@ -241,35 +223,20 @@ void logs::listener::add(logs::listener* _new)
}
}
logs::channel::channel(const char* name)
: name(name)
, enabled(level::notice)
{
std::lock_guard lock(g_mutex);
get_logger()->channels.emplace(name, this);
}
void logs::message::broadcast(const char* fmt, const fmt_type_info* sup, ...) const
{
// Get timestamp
const u64 stamp = get_stamp();
// Register channel
if (ch->enabled == level::_uninit)
{
std::lock_guard lock(g_mutex);
auto& info = get_logger()->channels[ch->name];
if (info.pointer && info.pointer != ch)
{
fmt::throw_exception("logs::channel repetition: %s", ch->name);
}
else if (!info.pointer)
{
info.pointer = ch;
ch->enabled = info.enabled;
// Check level again
if (info.enabled < sev)
{
return;
}
}
}
// Get text, extract va_args
thread_local std::string text;
thread_local std::vector<u64> args;
@ -662,7 +629,6 @@ void logs::file_listener::log(u64 stamp, const logs::message& msg, const std::st
case level::warning: text = u8"·W "; break;
case level::notice: text = u8"·! "; break;
case level::trace: text = u8"·T "; break;
case level::_uninit: text = u8"· "; break;
}
// Print µs timestamp

View File

@ -17,8 +17,6 @@ namespace logs
warning,
notice,
trace, // Lowest severity (usually disabled)
_uninit = UINT_MAX, // Special value for delayed initialization
};
struct channel;
@ -63,12 +61,8 @@ namespace logs
// The lowest logging level enabled for this channel (used for early filtering)
atomic_t<level> enabled;
// Constant initialization: channel name
constexpr channel(const char* name)
: name(name)
, enabled(level::_uninit)
{
}
// Initialize and register channel
channel(const char* name);
#define GEN_LOG_METHOD(_sev)\
const message msg_##_sev{this, level::_sev};\
@ -93,16 +87,6 @@ namespace logs
#undef GEN_LOG_METHOD
};
/* Small set of predefined channels */
extern channel GENERAL;
extern channel LOADER;
extern channel MEMORY;
extern channel RSX;
extern channel HLE;
extern channel PPU;
extern channel SPU;
// Log level control: set all channels to level::notice
void reset();
@ -110,10 +94,23 @@ namespace logs
void set_level(const std::string&, level);
}
#define LOG_CHANNEL(ch, ...) ::logs::channel ch(#ch, ##__VA_ARGS__)
#define LOG_CHANNEL(ch, ...) inline ::logs::channel ch(#ch, ##__VA_ARGS__)
// Legacy:
namespace logs
{
/* Small set of predefined channels */
inline channel GENERAL("");
inline channel LOADER("LDR");
inline channel MEMORY("MEM");
LOG_CHANNEL(RSX);
LOG_CHANNEL(HLE);
LOG_CHANNEL(PPU);
LOG_CHANNEL(SPU);
}
#define LOG_SUCCESS(ch, fmt, ...) logs::ch.success("" fmt, ##__VA_ARGS__)
#define LOG_NOTICE(ch, fmt, ...) logs::ch.notice ("" fmt, ##__VA_ARGS__)
#define LOG_WARNING(ch, fmt, ...) logs::ch.warning("" fmt, ##__VA_ARGS__)

View File

@ -3,7 +3,7 @@
#include "cellAudioOut.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellAudioOutError>::format(std::string& out, u64 arg)

View File

@ -6,7 +6,7 @@
#include "Emu/Io/KeyboardHandler.h"
#include "cellKb.h"
extern logs::channel sys_io;
LOG_CHANNEL(sys_io);
template<>
void fmt_class_string<CellKbError>::format(std::string& out, u64 arg)

View File

@ -7,7 +7,7 @@
#include "cellMouse.h"
extern logs::channel sys_io;
LOG_CHANNEL(sys_io);
template<>
void fmt_class_string<CellMouseError>::format(std::string& out, u64 arg)

View File

@ -13,7 +13,7 @@
#include "util/init_mutex.hpp"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellMsgDialogError>::format(std::string& out, u64 arg)

View File

@ -7,7 +7,7 @@
#include "Input/pad_thread.h"
#include "cellPad.h"
extern logs::channel sys_io;
LOG_CHANNEL(sys_io);
template<>
void fmt_class_string<CellPadError>::format(std::string& out, u64 arg)

View File

@ -13,11 +13,7 @@
#include <thread>
#include <mutex>
//----------------------------------------------------------------------------
// Externs
//----------------------------------------------------------------------------
extern logs::channel cellSpurs;
LOG_CHANNEL(cellSpurs);
//----------------------------------------------------------------------------
// Function prototypes

View File

@ -3,8 +3,7 @@
#include "cellSysutil.h"
#include "cellStorage.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
template <>
void fmt_class_string<CellStorageError>::format(std::string& out, u64 arg)

View File

@ -8,7 +8,7 @@
#include "util/init_mutex.hpp"
#include "Utilities/StrUtil.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellSysCacheError>::format(std::string& out, u64 arg)

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
s32 cellSysutilAvcByeRequest()
{

View File

@ -6,7 +6,7 @@
#include "cellVideoOut.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
const extern std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map
{

View File

@ -4,7 +4,7 @@
#include "cellWebBrowser.h"
#include "Emu/IdManager.h"
extern logs::channel cellSysutil;
LOG_CHANNEL(cellSysutil);
struct browser_info
{

View File

@ -6,7 +6,8 @@
#include "Emu/Cell/lv2/sys_process.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
extern vm::gvar<u32> g_ppu_exit_mutex;
extern vm::gvar<vm::ptr<void()>> g_ppu_atexitspawn;
extern vm::gvar<vm::ptr<void()>> g_ppu_at_Exitspawn;

View File

@ -5,7 +5,7 @@
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
struct HeapInfo
{

View File

@ -5,7 +5,7 @@
#include <string.h>
#include <ctype.h>
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
// cfmt implementation (TODO)

View File

@ -9,7 +9,7 @@
#include "Emu/Cell/lv2/sys_cond.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
error_code sys_lwcond_create(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwcond_attribute_t> attr)
{

View File

@ -10,7 +10,7 @@
#include <atomic>
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
error_code sys_lwmutex_create(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwmutex_attribute_t> attr)
{

View File

@ -11,8 +11,7 @@
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
using sys_mempool_t = u32;

View File

@ -2,7 +2,7 @@
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_mmapper.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
s32 sys_mmapper_allocate_memory(ppu_thread& ppu, u32 size, u64 flags, vm::ptr<u32> mem_id)
{

View File

@ -9,7 +9,7 @@
#include "Emu/Cell/lv2/sys_mutex.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
vm::gvar<sys_lwmutex_t> g_ppu_atexit_lwm;
vm::gvar<vm::ptr<void()>[8]> g_ppu_atexit;

View File

@ -6,7 +6,7 @@
#include "Emu/Cell/lv2/sys_prx.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
extern vm::gvar<sys_lwmutex_t> g_ppu_prx_lwm;

View File

@ -4,7 +4,7 @@
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
s32 sys_rsxaudio_close_connection()
{

View File

@ -4,7 +4,7 @@
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
void sys_spinlock_initialize(vm::ptr<atomic_be_t<u32>> lock)
{

View File

@ -8,7 +8,7 @@
#include "Loader/ELF.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
LOG_CHANNEL(sysPrxForUser);
spu_printf_cb_t g_spu_printf_agcb;
spu_printf_cb_t g_spu_printf_dgcb;

View File

@ -7,7 +7,7 @@
#include "Emu/Io/usb_device.h"
#include <libusb.h>
extern logs::channel sys_usbd;
LOG_CHANNEL(sys_usbd);
extern void LIBUSB_CALL callback_transfer(struct libusb_transfer* transfer);

View File

@ -24,7 +24,7 @@ constexpr auto qstr = QString::fromStdString;
struct gui_listener : logs::listener
{
atomic_t<logs::level> enabled{logs::level::_uninit};
atomic_t<logs::level> enabled{logs::level{UINT_MAX}};
struct packet_t
{