Make RTC_LOG_THREAD_BLOCK_COUNT less spammy for known call counts

Also removing a count check from DestroyTransceiverChannel that's
not useful right now. We can bring it back when we have
DestroyChannelInterface better under control as far as Invokes goes.

Bug: none
Change-Id: I8e9c55a980f8f20e8b996fdc461fd90b0fbd4f3d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215201
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33730}
This commit is contained in:
Tomas Gunnarsson 2021-04-14 12:54:10 +02:00 committed by Commit Bot
parent 5744b7fce7
commit 89f3dd5bf7
4 changed files with 51 additions and 4 deletions

View file

@ -4725,7 +4725,6 @@ void SdpOfferAnswerHandler::DestroyTransceiverChannel(
// worker thread. Can DestroyTransceiverChannel be purely posted to the
// worker?
DestroyChannelInterface(channel);
RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(3);
}
}

View file

@ -362,7 +362,9 @@ Thread::ScopedCountBlockingCalls::ScopedCountBlockingCalls(
result_callback_(std::move(callback)) {}
Thread::ScopedCountBlockingCalls::~ScopedCountBlockingCalls() {
result_callback_(GetBlockingCallCount(), GetCouldBeBlockingCallCount());
if (GetTotalBlockedCallCount() >= min_blocking_calls_for_callback_) {
result_callback_(GetBlockingCallCount(), GetCouldBeBlockingCallCount());
}
}
uint32_t Thread::ScopedCountBlockingCalls::GetBlockingCallCount() const {

View file

@ -61,8 +61,11 @@
// number of blocking thread calls.
// Note: Use of this macro, requires RTC_LOG_THREAD_BLOCK_COUNT() to be called
// first.
#define RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(x) \
RTC_DCHECK_LE(blocked_call_count_printer.GetTotalBlockedCallCount(), x)
#define RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(x) \
do { \
blocked_call_count_printer.set_minimum_call_count_for_callback(x + 1); \
RTC_DCHECK_LE(blocked_call_count_printer.GetTotalBlockedCallCount(), x); \
} while (0)
#else
#define RTC_LOG_THREAD_BLOCK_COUNT()
#define RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(x)
@ -251,10 +254,19 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
uint32_t GetCouldBeBlockingCallCount() const;
uint32_t GetTotalBlockedCallCount() const;
void set_minimum_call_count_for_callback(uint32_t minimum) {
min_blocking_calls_for_callback_ = minimum;
}
private:
Thread* const thread_;
const uint32_t base_blocking_call_count_;
const uint32_t base_could_be_blocking_call_count_;
// The minimum number of blocking calls required in order to issue the
// result_callback_. This is used by RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN to
// tame log spam.
// By default we always issue the callback, regardless of callback count.
uint32_t min_blocking_calls_for_callback_ = 0;
std::function<void(uint32_t, uint32_t)> result_callback_;
};

View file

@ -297,6 +297,40 @@ TEST(ThreadTest, CountBlockingCalls) {
#endif
}
#if RTC_DCHECK_IS_ON
TEST(ThreadTest, CountBlockingCallsOneCallback) {
rtc::Thread* current = rtc::Thread::Current();
ASSERT_TRUE(current);
bool was_called_back = false;
{
rtc::Thread::ScopedCountBlockingCalls blocked_calls(
[&](uint32_t actual_block, uint32_t could_block) {
was_called_back = true;
});
current->Invoke<void>(RTC_FROM_HERE, []() {});
}
EXPECT_TRUE(was_called_back);
}
TEST(ThreadTest, CountBlockingCallsSkipCallback) {
rtc::Thread* current = rtc::Thread::Current();
ASSERT_TRUE(current);
bool was_called_back = false;
{
rtc::Thread::ScopedCountBlockingCalls blocked_calls(
[&](uint32_t actual_block, uint32_t could_block) {
was_called_back = true;
});
// Changed `blocked_calls` to not issue the callback if there are 1 or
// fewer blocking calls (i.e. we set the minimum required number to 2).
blocked_calls.set_minimum_call_count_for_callback(2);
current->Invoke<void>(RTC_FROM_HERE, []() {});
}
// We should not have gotten a call back.
EXPECT_FALSE(was_called_back);
}
#endif
// Test that setting thread names doesn't cause a malfunction.
// There's no easy way to verify the name was set properly at this time.
TEST(ThreadTest, Names) {