Un-inline LogMessage::Loggable
Make min_sev_ and dbg_sev_ file-local, and don't inline Loggable(). This should shrink the size of each RTC_LOG statement by a few instructions. In my local tests the android binary becomes ~12k smaller. Bug: webrtc:8529 Change-Id: Ic90cf8a7b042d49370cc8d0b1b08058940b615f8 Reviewed-on: https://webrtc-review.googlesource.com/53680 Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22081}
This commit is contained in:
parent
9d138fc7ce
commit
2b6f13508e
@ -48,6 +48,14 @@ static const char kLibjingle[] = "libjingle";
|
||||
|
||||
namespace rtc {
|
||||
namespace {
|
||||
// By default, release builds don't log, debug builds at info level
|
||||
#if !defined(NDEBUG)
|
||||
static LoggingSeverity g_min_sev = LS_INFO;
|
||||
static LoggingSeverity g_dbg_sev = LS_INFO;
|
||||
#else
|
||||
static LoggingSeverity g_min_sev = LS_NONE;
|
||||
static LoggingSeverity g_dbg_sev = LS_NONE;
|
||||
#endif
|
||||
|
||||
// Return the filename portion of the string (that following the last slash).
|
||||
const char* FilenameFromPath(const char* file) {
|
||||
@ -59,6 +67,8 @@ const char* FilenameFromPath(const char* file) {
|
||||
return (end1 > end2) ? end1 + 1 : end2 + 1;
|
||||
}
|
||||
|
||||
// Global lock for log subsystem, only needed to serialize access to streams_.
|
||||
CriticalSection g_log_crit;
|
||||
} // namespace
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -92,21 +102,8 @@ std::string ErrorName(int err, const ConstantLabel* err_table) {
|
||||
// LogMessage
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// By default, release builds don't log, debug builds at info level
|
||||
#if !defined(NDEBUG)
|
||||
LoggingSeverity LogMessage::min_sev_ = LS_INFO;
|
||||
LoggingSeverity LogMessage::dbg_sev_ = LS_INFO;
|
||||
#else
|
||||
LoggingSeverity LogMessage::min_sev_ = LS_NONE;
|
||||
LoggingSeverity LogMessage::dbg_sev_ = LS_NONE;
|
||||
#endif
|
||||
bool LogMessage::log_to_stderr_ = true;
|
||||
|
||||
namespace {
|
||||
// Global lock for log subsystem, only needed to serialize access to streams_.
|
||||
CriticalSection g_log_crit;
|
||||
} // namespace
|
||||
|
||||
// The list of logging streams currently configured.
|
||||
// Note: we explicitly do not clean this up, because of the uncertain ordering
|
||||
// of destructors at program exit. Let the person who sets the stream trigger
|
||||
@ -203,7 +200,7 @@ LogMessage::~LogMessage() {
|
||||
print_stream_ << std::endl;
|
||||
|
||||
const std::string& str = print_stream_.str();
|
||||
if (severity_ >= dbg_sev_) {
|
||||
if (severity_ >= g_dbg_sev) {
|
||||
OutputToDebug(str, severity_, tag_);
|
||||
}
|
||||
|
||||
@ -215,6 +212,17 @@ LogMessage::~LogMessage() {
|
||||
}
|
||||
}
|
||||
|
||||
bool LogMessage::Loggable(LoggingSeverity sev) {
|
||||
return sev >= g_min_sev;
|
||||
}
|
||||
|
||||
int LogMessage::GetMinLogSeverity() {
|
||||
return g_min_sev;
|
||||
}
|
||||
|
||||
LoggingSeverity LogMessage::GetLogToDebug() {
|
||||
return g_dbg_sev;
|
||||
}
|
||||
int64_t LogMessage::LogStartTime() {
|
||||
static const int64_t g_start = SystemTimeMillis();
|
||||
return g_start;
|
||||
@ -234,7 +242,7 @@ void LogMessage::LogTimestamps(bool on) {
|
||||
}
|
||||
|
||||
void LogMessage::LogToDebug(LoggingSeverity min_sev) {
|
||||
dbg_sev_ = min_sev;
|
||||
g_dbg_sev = min_sev;
|
||||
CritScope cs(&g_log_crit);
|
||||
UpdateMinLogSeverity();
|
||||
}
|
||||
@ -335,11 +343,11 @@ void LogMessage::ConfigureLogging(const char* params) {
|
||||
|
||||
void LogMessage::UpdateMinLogSeverity()
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(g_log_crit) {
|
||||
LoggingSeverity min_sev = dbg_sev_;
|
||||
LoggingSeverity min_sev = g_dbg_sev;
|
||||
for (auto& kv : streams_) {
|
||||
min_sev = std::min(dbg_sev_, kv.second);
|
||||
min_sev = std::min(g_dbg_sev, kv.second);
|
||||
}
|
||||
min_sev_ = min_sev;
|
||||
g_min_sev = min_sev;
|
||||
}
|
||||
|
||||
void LogMessage::OutputToDebug(const std::string& str,
|
||||
|
||||
@ -158,7 +158,7 @@ class LogMessage {
|
||||
|
||||
~LogMessage();
|
||||
|
||||
static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); }
|
||||
static bool Loggable(LoggingSeverity sev);
|
||||
std::ostream& stream() { return print_stream_; }
|
||||
|
||||
// Returns the time at which this function was called for the first time.
|
||||
@ -181,7 +181,7 @@ class LogMessage {
|
||||
// These are the available logging channels
|
||||
// Debug: Debug console on Windows, otherwise stderr
|
||||
static void LogToDebug(LoggingSeverity min_sev);
|
||||
static LoggingSeverity GetLogToDebug() { return dbg_sev_; }
|
||||
static LoggingSeverity GetLogToDebug();
|
||||
|
||||
// Sets whether logs will be directed to stderr in debug mode.
|
||||
static void SetLogToStderr(bool log_to_stderr);
|
||||
@ -199,7 +199,7 @@ class LogMessage {
|
||||
|
||||
// Testing against MinLogSeverity allows code to avoid potentially expensive
|
||||
// logging operations by pre-checking the logging level.
|
||||
static int GetMinLogSeverity() { return min_sev_; }
|
||||
static int GetMinLogSeverity();
|
||||
|
||||
// Parses the provided parameter stream to configure the options above.
|
||||
// Useful for configuring logging from the command line.
|
||||
@ -230,13 +230,6 @@ class LogMessage {
|
||||
// the message before output.
|
||||
std::string extra_;
|
||||
|
||||
// dbg_sev_ is the thresholds for those output targets
|
||||
// min_sev_ is the minimum (most verbose) of those levels, and is used
|
||||
// as a short-circuit in the logging macros to identify messages that won't
|
||||
// be logged.
|
||||
// ctx_sev_ is the minimum level at which file context is displayed
|
||||
static LoggingSeverity min_sev_, dbg_sev_, ctx_sev_;
|
||||
|
||||
// The output streams and their associated severities
|
||||
static StreamList streams_;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user