Added logger flags, for selectively disabling categories of logging (cpu, apu, kernel). Need to make more log messages make use of these flags.
The "close window" keyboard hotkey (Guide-B) now toggles between loglevel -1 and the loglevel set in your config. Added LoggerBatch class, which accumulates strings into the threads scratch buffer. This is only intended to be used for very high frequency debug logging. if it exhausts the thread buffer, it just silently stops. Cleaned nearly 8 years of dust off of the pm4 packet disassembler code, now supports all packets that the command processor supports. Added extremely verbose logging for gpu register writes. This is not compiled in outside of debug builds, requires LogLevel::Debug and log_guest_driven_gpu_register_written_values = true. Added full logging of all PM4 packets in the cp. This is not compiled in outside of debug builds, requires LogLevel::Debug and disassemble_pm4. Piggybacked an implementation of guest callstack backtraces using the stackpoints from enable_host_guest_stack_synchronization. If enable_host_guest_stack_synchronization = false, no backtraces can be obtained. Added log_ringbuffer_kickoff_initiator_bts. when a thread updates the cp's read pointer, it dumps the backtrace of that thread Changed the names of the gpu registers CALLBACK_ADDRESS and CALLBACK_CONTEXT to the correct names. Added a note about CP_PROG_COUNTER Added CP_RB_WPTR to the gpu register table Added notes about CP_RB_CNTL and CP_RB_RPTR_ADDR. Both aren't necessary for HLE Changed name of UNKNOWN_0E00 gpu register to TC_CNTL_STATUS. Games only seem to write 1 to it (L2 invalidate)
This commit is contained in:
@@ -55,6 +55,12 @@ DEFINE_bool(log_to_debugprint, false, "Dump the log to DebugPrint.", "Logging");
|
||||
#endif // XE_PLATFORM_ANDROID
|
||||
DEFINE_bool(flush_log, true, "Flush log file after each log line batch.",
|
||||
"Logging");
|
||||
|
||||
DEFINE_uint32(log_mask, 0,
|
||||
"Disables specific categorizes for more granular debug logging. "
|
||||
"Kernel = 1, Apu = 2, Cpu = 4.",
|
||||
"Logging");
|
||||
|
||||
DEFINE_int32(
|
||||
log_level, 2,
|
||||
"Maximum level to be logged. (0=error, 1=warning, 2=info, 3=debug)",
|
||||
@@ -465,8 +471,16 @@ void ShutdownLogging() {
|
||||
memory::AlignedFree(logger);
|
||||
}
|
||||
|
||||
bool logging::internal::ShouldLog(LogLevel log_level) {
|
||||
return static_cast<int32_t>(log_level) <= cvars::log_level;
|
||||
static int g_saved_loglevel = static_cast<int>(LogLevel::Disabled);
|
||||
void logging::internal::ToggleLogLevel() {
|
||||
auto swap = g_saved_loglevel;
|
||||
|
||||
g_saved_loglevel = cvars::log_level;
|
||||
cvars::log_level = swap;
|
||||
}
|
||||
bool logging::internal::ShouldLog(LogLevel log_level, uint32_t log_mask) {
|
||||
return static_cast<int32_t>(log_level) <= cvars::log_level &&
|
||||
(log_mask & cvars::log_mask) == 0;
|
||||
}
|
||||
|
||||
std::pair<char*, size_t> logging::internal::GetThreadBuffer() {
|
||||
@@ -483,8 +497,8 @@ void logging::internal::AppendLogLine(LogLevel log_level,
|
||||
}
|
||||
|
||||
void logging::AppendLogLine(LogLevel log_level, const char prefix_char,
|
||||
const std::string_view str) {
|
||||
if (!internal::ShouldLog(log_level) || !str.size()) {
|
||||
const std::string_view str, uint32_t log_mask) {
|
||||
if (!internal::ShouldLog(log_level, log_mask) || !str.size()) {
|
||||
return;
|
||||
}
|
||||
logger_->AppendLine(xe::threading::current_thread_id(), prefix_char,
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace xe {
|
||||
// may be related to. These names should not be taken as fact as what a given
|
||||
// log line from any log level actually is.
|
||||
enum class LogLevel {
|
||||
Disabled = -1,
|
||||
Error = 0,
|
||||
Warning,
|
||||
Info,
|
||||
@@ -34,6 +35,15 @@ enum class LogLevel {
|
||||
Trace,
|
||||
};
|
||||
|
||||
// bitmasks!
|
||||
namespace LogSrc {
|
||||
enum : uint32_t {
|
||||
Uncategorized = 0,
|
||||
Kernel = 1,
|
||||
Apu = 2,
|
||||
Cpu = 4,
|
||||
};
|
||||
}
|
||||
class LogSink {
|
||||
public:
|
||||
virtual ~LogSink() = default;
|
||||
@@ -72,32 +82,38 @@ void ShutdownLogging();
|
||||
namespace logging {
|
||||
namespace internal {
|
||||
|
||||
bool ShouldLog(LogLevel log_level);
|
||||
void ToggleLogLevel();
|
||||
|
||||
bool ShouldLog(LogLevel log_level,
|
||||
uint32_t log_mask = xe::LogSrc::Uncategorized);
|
||||
std::pair<char*, size_t> GetThreadBuffer();
|
||||
XE_NOALIAS
|
||||
void AppendLogLine(LogLevel log_level, const char prefix_char, size_t written);
|
||||
|
||||
} // namespace internal
|
||||
//technically, noalias is incorrect here, these functions do in fact alias global memory,
|
||||
//but msvc will not optimize the calls away, and the global memory modified by the calls is limited to internal logging variables,
|
||||
//so it might as well be noalias
|
||||
// technically, noalias is incorrect here, these functions do in fact alias
|
||||
// global memory, but msvc will not optimize the calls away, and the global
|
||||
// memory modified by the calls is limited to internal logging variables, so it
|
||||
// might as well be noalias
|
||||
template <typename... Args>
|
||||
XE_NOALIAS
|
||||
XE_NOINLINE XE_COLD static void AppendLogLineFormat_Impl(LogLevel log_level,
|
||||
const char prefix_char,
|
||||
const char* format,
|
||||
const Args&... args) {
|
||||
XE_NOALIAS XE_NOINLINE XE_COLD static void AppendLogLineFormat_Impl(
|
||||
LogLevel log_level, const char prefix_char, const char* format,
|
||||
const Args&... args) {
|
||||
auto target = internal::GetThreadBuffer();
|
||||
auto result = fmt::format_to_n(target.first, target.second, format, args...);
|
||||
internal::AppendLogLine(log_level, prefix_char, result.size);
|
||||
}
|
||||
|
||||
// Appends a line to the log with {fmt}-style formatting.
|
||||
//chrispy: inline the initial check, outline the append. the append should happen rarely for end users
|
||||
// Appends a line to the log with {fmt}-style formatting.
|
||||
// chrispy: inline the initial check, outline the append. the append should
|
||||
// happen rarely for end users
|
||||
template <typename... Args>
|
||||
XE_FORCEINLINE static void AppendLogLineFormat(LogLevel log_level, const char prefix_char,
|
||||
const char* format, const Args&... args) {
|
||||
if (!internal::ShouldLog(log_level)) {
|
||||
XE_FORCEINLINE static void AppendLogLineFormat(uint32_t log_src_mask,
|
||||
LogLevel log_level,
|
||||
const char prefix_char,
|
||||
const char* format,
|
||||
const Args&... args) {
|
||||
if (!internal::ShouldLog(log_level, log_src_mask)) {
|
||||
return;
|
||||
}
|
||||
AppendLogLineFormat_Impl(log_level, prefix_char, format, args...);
|
||||
@@ -105,7 +121,36 @@ XE_FORCEINLINE static void AppendLogLineFormat(LogLevel log_level, const char pr
|
||||
|
||||
// Appends a line to the log.
|
||||
void AppendLogLine(LogLevel log_level, const char prefix_char,
|
||||
const std::string_view str);
|
||||
const std::string_view str,
|
||||
uint32_t log_mask = LogSrc::Uncategorized);
|
||||
|
||||
template <LogLevel ll>
|
||||
struct LoggerBatch {
|
||||
char* thrd_buf; // current position in thread buffer
|
||||
size_t thrd_buf_rem; // num left in thrd buffer
|
||||
size_t total_size;
|
||||
|
||||
void reset() {
|
||||
auto target = logging::internal::GetThreadBuffer();
|
||||
|
||||
thrd_buf = target.first;
|
||||
thrd_buf_rem = target.second;
|
||||
total_size = 0;
|
||||
}
|
||||
|
||||
LoggerBatch() { reset(); }
|
||||
template <size_t fmtlen, typename... Ts>
|
||||
void operator()(const char (&fmt)[fmtlen], Ts&&... args) {
|
||||
auto tmpres = fmt::format_to_n(thrd_buf, thrd_buf_rem, fmt, args...);
|
||||
thrd_buf_rem -= tmpres.size;
|
||||
thrd_buf = tmpres.out;
|
||||
total_size += tmpres.size;
|
||||
}
|
||||
|
||||
void submit(char prefix_char) {
|
||||
logging::internal::AppendLogLine(ll, prefix_char, total_size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace logging
|
||||
|
||||
@@ -118,48 +163,56 @@ void AppendLogLine(LogLevel log_level, const char prefix_char,
|
||||
|
||||
template <typename... Args>
|
||||
XE_COLD void XELOGE(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Error, '!', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Error, '!', format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
XE_COLD
|
||||
void XELOGW(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Warning, 'w', format, args...);
|
||||
XE_COLD void XELOGW(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Warning, 'w', format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGI(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'i', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Info, 'i', format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGD(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'd', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Debug, 'd', format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGCPU(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'C', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Cpu, xe::LogLevel::Info, 'C',
|
||||
format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGAPU(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'A', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Apu, xe::LogLevel::Debug, 'A',
|
||||
format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGGPU(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'G', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Debug, 'G', format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGKERNEL(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'K', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Kernel, xe::LogLevel::Info, 'K',
|
||||
format, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void XELOGFS(const char* format, const Args&... args) {
|
||||
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'F', format, args...);
|
||||
xe::logging::AppendLogLineFormat(xe::LogSrc::Uncategorized,
|
||||
xe::LogLevel::Info, 'F', format, args...);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user