From c5d7c52d44f84a153e69a2e0e135d582d17b1aab Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Tue, 3 Dec 2019 10:14:05 -0800 Subject: [PATCH] Remove line number from rtc::Location Concatenating __FILE__ with __LINE__ prevents the compiler from aliasing strings within the same file, contributing ~30KB of .text bloat. Chrome already omits from the file number from its Location type so it doesn't seem to be a big loss. Bug: b/145168048 Change-Id: I000bfdf43f4eb90f8b63ed017b08c1b5a7a84a6d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160744 Commit-Queue: Steve Anton Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#29994} --- modules/utility/source/process_thread_impl.cc | 2 +- rtc_base/location.cc | 18 ++----------- rtc_base/location.h | 27 ++++++++++--------- rtc_base/message_queue.cc | 4 +-- rtc_base/thread.cc | 5 ++-- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc index 472ff33d2e..506e8b6762 100644 --- a/modules/utility/source/process_thread_impl.cc +++ b/modules/utility/source/process_thread_impl.cc @@ -190,7 +190,7 @@ bool ProcessThreadImpl::Process() { { TRACE_EVENT2("webrtc", "ModuleProcess", "function", m.location.function_name(), "file", - m.location.file_and_line()); + m.location.file_name()); m.module->Process(); } // Use a new 'now' reference to calculate when the next callback diff --git a/rtc_base/location.cc b/rtc_base/location.cc index d3c911f257..08425494aa 100644 --- a/rtc_base/location.cc +++ b/rtc_base/location.cc @@ -14,24 +14,10 @@ namespace rtc { -Location::Location(const char* function_name, const char* file_and_line) - : function_name_(function_name), file_and_line_(file_and_line) {} - -Location::Location() : function_name_("Unknown"), file_and_line_("Unknown") {} - -Location::Location(const Location& other) - : function_name_(other.function_name_), - file_and_line_(other.file_and_line_) {} - -Location& Location::operator=(const Location& other) { - function_name_ = other.function_name_; - file_and_line_ = other.file_and_line_; - return *this; -} - std::string Location::ToString() const { char buf[256]; - snprintf(buf, sizeof(buf), "%s@%s", function_name_, file_and_line_); + snprintf(buf, sizeof(buf), "%s@%s:%d", function_name_, file_name_, + line_number_); return buf; } diff --git a/rtc_base/location.h b/rtc_base/location.h index 7590642c30..ad8f479135 100644 --- a/rtc_base/location.h +++ b/rtc_base/location.h @@ -27,31 +27,32 @@ class RTC_EXPORT Location { // Constructor should be called with a long-lived char*, such as __FILE__. // It assumes the provided value will persist as a global constant, and it // will not make a copy of it. - // - // TODO(deadbeef): Tracing is currently limited to 2 arguments, which is - // why the file name and line number are combined into one argument. - // - // Once TracingV2 is available, separate the file name and line number. - Location(const char* function_name, const char* file_and_line); - Location(); - Location(const Location& other); - Location& operator=(const Location& other); + Location(const char* function_name, const char* file_name, int line_number) + : function_name_(function_name), + file_name_(file_name), + line_number_(line_number) {} + Location() = default; const char* function_name() const { return function_name_; } - const char* file_and_line() const { return file_and_line_; } + const char* file_name() const { return file_name_; } + int line_number() const { return line_number_; } + // TODO(steveanton): Remove once all downstream users have been updated to use + // |file_name()| and/or |line_number()|. + const char* file_and_line() const { return file_name_; } std::string ToString() const; private: - const char* function_name_; - const char* file_and_line_; + const char* function_name_ = "Unknown"; + const char* file_name_ = "Unknown"; + int line_number_ = -1; }; // Define a macro to record the current source location. #define RTC_FROM_HERE RTC_FROM_HERE_WITH_FUNCTION(__FUNCTION__) #define RTC_FROM_HERE_WITH_FUNCTION(function_name) \ - ::rtc::Location(function_name, __FILE__ ":" STRINGIZE(__LINE__)) + ::rtc::Location(function_name, __FILE__, __LINE__) } // namespace rtc diff --git a/rtc_base/message_queue.cc b/rtc_base/message_queue.cc index ffa8a5688c..98d4262221 100644 --- a/rtc_base/message_queue.cc +++ b/rtc_base/message_queue.cc @@ -507,8 +507,8 @@ void MessageQueue::ClearInternal(MessageHandler* phandler, } void MessageQueue::Dispatch(Message* pmsg) { - TRACE_EVENT2("webrtc", "MessageQueue::Dispatch", "src_file_and_line", - pmsg->posted_from.file_and_line(), "src_func", + TRACE_EVENT2("webrtc", "MessageQueue::Dispatch", "src_file", + pmsg->posted_from.file_name(), "src_func", pmsg->posted_from.function_name()); int64_t start_time = TimeMillis(); pmsg->phandler->OnMessage(pmsg); diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc index c16c39bb53..90be695885 100644 --- a/rtc_base/thread.cc +++ b/rtc_base/thread.cc @@ -470,9 +470,8 @@ bool Thread::PopSendMessageFromThread(const Thread* source, _SendMessage* msg) { void Thread::InvokeInternal(const Location& posted_from, rtc::FunctionView functor) { - TRACE_EVENT2("webrtc", "Thread::Invoke", "src_file_and_line", - posted_from.file_and_line(), "src_func", - posted_from.function_name()); + TRACE_EVENT2("webrtc", "Thread::Invoke", "src_file", posted_from.file_name(), + "src_func", posted_from.function_name()); class FunctorMessageHandler : public MessageHandler { public: