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}
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -470,9 +470,8 @@ bool Thread::PopSendMessageFromThread(const Thread* source, _SendMessage* msg) {
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user