Configure threads with their own warning deadlines.

Design document:
https://docs.google.com/document/d/1c_Jk-eqoBl3mZcEW73OO_WOnWVO9nTU854DHcyqjQBo/edit?resourcekey=0-j2bRwX0nxCldQ_VjoPFAOQ#

Bug: webrtc:12405
Change-Id: Idab950a3293d7ca9328dfeb19ec6d3084f7e0e5f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203522
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33218}
This commit is contained in:
Harald Alvestrand
2021-01-27 21:52:14 +00:00
committed by Commit Bot
parent 9e1f08a88c
commit ba69442054
3 changed files with 33 additions and 4 deletions

View File

@ -71,8 +71,6 @@ class ScopedAutoReleasePool {
namespace rtc {
namespace {
const int kSlowDispatchLoggingThreshold = 50; // 50 ms
class MessageHandlerWithTask final : public MessageHandler {
public:
MessageHandlerWithTask() {}
@ -681,14 +679,18 @@ void Thread::Dispatch(Message* pmsg) {
TRACE_EVENT2("webrtc", "Thread::Dispatch", "src_file",
pmsg->posted_from.file_name(), "src_func",
pmsg->posted_from.function_name());
RTC_DCHECK_RUN_ON(this);
int64_t start_time = TimeMillis();
pmsg->phandler->OnMessage(pmsg);
int64_t end_time = TimeMillis();
int64_t diff = TimeDiff(end_time, start_time);
if (diff >= kSlowDispatchLoggingThreshold) {
RTC_LOG(LS_INFO) << "Message took " << diff
if (diff >= dispatch_warning_ms_) {
RTC_LOG(LS_INFO) << "Message to " << name() << " took " << diff
<< "ms to dispatch. Posted from: "
<< pmsg->posted_from.ToString();
// To avoid log spew, move the warning limit to only give warning
// for delays that are larger than the one observed.
dispatch_warning_ms_ = diff + 1;
}
}
@ -740,6 +742,16 @@ bool Thread::SetName(const std::string& name, const void* obj) {
return true;
}
void Thread::SetDispatchWarningMs(int deadline) {
if (!IsCurrent()) {
PostTask(webrtc::ToQueuedTask(
[this, deadline]() { SetDispatchWarningMs(deadline); }));
return;
}
RTC_DCHECK_RUN_ON(this);
dispatch_warning_ms_ = deadline;
}
bool Thread::Start() {
RTC_DCHECK(!IsRunning());