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 <steveanton@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29994}
diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc
index 472ff33..506e8b6 100644
--- a/modules/utility/source/process_thread_impl.cc
+++ b/modules/utility/source/process_thread_impl.cc
@@ -190,7 +190,7 @@
{
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 d3c911f..0842549 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 7590642..ad8f479 100644
--- a/rtc_base/location.h
+++ b/rtc_base/location.h
@@ -27,31 +27,32 @@
// 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 ffa8a56..98d4262 100644
--- a/rtc_base/message_queue.cc
+++ b/rtc_base/message_queue.cc
@@ -507,8 +507,8 @@
}
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 c16c39b..90be695 100644
--- a/rtc_base/thread.cc
+++ b/rtc_base/thread.cc
@@ -470,9 +470,8 @@
void Thread::InvokeInternal(const Location& posted_from,
rtc::FunctionView<void()> 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: