mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 13:56:59 +01:00
perf: skip LOGF formatting when logging is silent
LOGF/LOGF_COLOR always ran fmt::sprintf even when the output was discarded; at emulator log volume the formatting alone costs frames. Add Log::IsSilent() and short-circuit before formatting. Behavior-preserving on all platforms (it only skips work whose result is thrown away); before init it reports non-silent so early logs still print. (cherry picked from commit 1749e0fc68ae4290055fb12f72c9bb4baf466190)
This commit is contained in:
@@ -178,6 +178,11 @@ Direction GetDirection() {
|
|||||||
return g_direction;
|
return g_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsSilent() {
|
||||||
|
// Before init LOGF must keep writing to stdout, so report non-silent.
|
||||||
|
return g_initialized && g_direction == Direction::Silent;
|
||||||
|
}
|
||||||
|
|
||||||
void Write(std::string_view text) {
|
void Write(std::string_view text) {
|
||||||
WriteImpl(text);
|
WriteImpl(text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ KYTY_SUBSYSTEM_DEFINE(Log);
|
|||||||
enum class Direction { Silent, Console, File };
|
enum class Direction { Silent, Console, File };
|
||||||
|
|
||||||
Direction GetDirection();
|
Direction GetDirection();
|
||||||
|
bool IsSilent();
|
||||||
void Write(std::string_view text);
|
void Write(std::string_view text);
|
||||||
void Write(fmt::text_style style, std::string_view text);
|
void Write(fmt::text_style style, std::string_view text);
|
||||||
void WriteFatal(std::string_view text);
|
void WriteFatal(std::string_view text);
|
||||||
@@ -41,8 +42,18 @@ inline constexpr auto BrightWhite = fmt::fg(fmt::terminal_color::bright_white)
|
|||||||
} // namespace Log
|
} // namespace Log
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||||
#define LOGF(...) ::Log::Write(::fmt::sprintf(__VA_ARGS__))
|
#define LOGF(...) \
|
||||||
|
do { \
|
||||||
|
if (!::Log::IsSilent()) { \
|
||||||
|
::Log::Write(::fmt::sprintf(__VA_ARGS__)); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||||
#define LOGF_COLOR(style, ...) ::Log::Write((style), ::fmt::sprintf(__VA_ARGS__))
|
#define LOGF_COLOR(style, ...) \
|
||||||
|
do { \
|
||||||
|
if (!::Log::IsSilent()) { \
|
||||||
|
::Log::Write((style), ::fmt::sprintf(__VA_ARGS__)); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
#endif /* KYTY_COMMON_LOGGING_LOG_H_ */
|
#endif /* KYTY_COMMON_LOGGING_LOG_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user