Add support for Location (RTC_FROM_HERE) to ProcessThread::RegisterModule.
This makes a few things a lot clearer when looking at perf trace data:
* What module instances (where they were created) are called
* On what thread
* How frequently
* For how long
ProcessThread will be replaced by TaskQueue moving forward and this is a step towards understanding the behavior of the affected code.
BUG=webrtc:7219
Review-Url: https://codereview.webrtc.org/2729053002
Cr-Original-Commit-Position: refs/heads/master@{#16998}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: dea489f33e63c518854231fd3a98fabdb2b81563
diff --git a/call/call.cc b/call/call.cc
index e2b1e70..7302335 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -23,6 +23,7 @@
#include "webrtc/base/basictypes.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/optional.h"
#include "webrtc/base/task_queue.h"
@@ -355,11 +356,12 @@
config_.bitrate_config.max_bitrate_bps);
module_process_thread_->Start();
- module_process_thread_->RegisterModule(call_stats_.get());
- module_process_thread_->RegisterModule(congestion_controller_.get());
- pacer_thread_->RegisterModule(congestion_controller_->pacer());
+ module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE);
+ module_process_thread_->RegisterModule(congestion_controller_.get(),
+ RTC_FROM_HERE);
+ pacer_thread_->RegisterModule(congestion_controller_->pacer(), RTC_FROM_HERE);
pacer_thread_->RegisterModule(
- congestion_controller_->GetRemoteBitrateEstimator(true));
+ congestion_controller_->GetRemoteBitrateEstimator(true), RTC_FROM_HERE);
pacer_thread_->Start();
}
diff --git a/call/flexfec_receive_stream_impl.cc b/call/flexfec_receive_stream_impl.cc
index 290b897..fcfb3ef 100644
--- a/call/flexfec_receive_stream_impl.cc
+++ b/call/flexfec_receive_stream_impl.cc
@@ -13,6 +13,7 @@
#include <string>
#include "webrtc/base/checks.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h"
#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
@@ -140,7 +141,7 @@
rtp_rtcp_->SetSendingMediaStatus(false);
rtp_rtcp_->SetRTCPStatus(config_.rtcp_mode);
rtp_rtcp_->SetSSRC(config_.local_ssrc);
- process_thread_->RegisterModule(rtp_rtcp_.get());
+ process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE);
}
FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() {
diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn
index ddf74c6..2df1a66 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -330,6 +330,7 @@
deps = [
":audio_device",
"../..:webrtc_common",
+ "../../base:rtc_base_approved",
"../../system_wrappers",
"../../test:test_main",
"../../test:test_support",
diff --git a/modules/audio_device/test/audio_device_test_api.cc b/modules/audio_device/test/audio_device_test_api.cc
index e36fc1d..5bf01e6 100644
--- a/modules/audio_device/test/audio_device_test_api.cc
+++ b/modules/audio_device/test/audio_device_test_api.cc
@@ -14,15 +14,14 @@
#include <memory>
-#include "webrtc/modules/audio_device/test/audio_device_test_defines.h"
-
-#include "webrtc/test/gtest.h"
-#include "webrtc/test/testsupport/fileutils.h"
-
+#include "webrtc/base/location.h"
#include "webrtc/modules/audio_device/audio_device_config.h"
#include "webrtc/modules/audio_device/audio_device_impl.h"
+#include "webrtc/modules/audio_device/test/audio_device_test_defines.h"
#include "webrtc/modules/utility/include/process_thread.h"
#include "webrtc/system_wrappers/include/sleep.h"
+#include "webrtc/test/gtest.h"
+#include "webrtc/test/testsupport/fileutils.h"
// Helper functions
#if defined(ANDROID)
@@ -218,7 +217,7 @@
FAIL() << "Failed creating audio device object!";
}
- process_thread_->RegisterModule(audio_device_);
+ process_thread_->RegisterModule(audio_device_, RTC_FROM_HERE);
AudioDeviceModule::AudioLayer audio_layer =
AudioDeviceModule::kPlatformDefaultAudio;
diff --git a/modules/utility/include/mock/mock_process_thread.h b/modules/utility/include/mock/mock_process_thread.h
index 6625a74..4d24033 100644
--- a/modules/utility/include/mock/mock_process_thread.h
+++ b/modules/utility/include/mock/mock_process_thread.h
@@ -13,8 +13,8 @@
#include <memory>
+#include "webrtc/base/location.h"
#include "webrtc/modules/utility/include/process_thread.h"
-
#include "webrtc/test/gmock.h"
namespace webrtc {
@@ -29,7 +29,7 @@
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(WakeUp, void(Module* module));
MOCK_METHOD1(PostTask, void(rtc::QueuedTask* task));
- MOCK_METHOD1(RegisterModule, void(Module* module));
+ MOCK_METHOD2(RegisterModule, void(Module* module, const rtc::Location&));
MOCK_METHOD1(DeRegisterModule, void(Module* module));
// MOCK_METHOD1 gets confused with mocking this method, so we work around it
diff --git a/modules/utility/include/process_thread.h b/modules/utility/include/process_thread.h
index 8524a51..2132ee4 100644
--- a/modules/utility/include/process_thread.h
+++ b/modules/utility/include/process_thread.h
@@ -25,6 +25,10 @@
}
#endif
+namespace rtc {
+class Location;
+}
+
namespace webrtc {
class Module;
@@ -61,7 +65,7 @@
// Adds a module that will start to receive callbacks on the worker thread.
// Can be called from any thread.
- virtual void RegisterModule(Module* module) = 0;
+ virtual void RegisterModule(Module* module, const rtc::Location& from) = 0;
// Removes a previously registered module.
// Can be called from any thread.
diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc
index 3332cd6..6252931 100644
--- a/modules/utility/source/process_thread_impl.cc
+++ b/modules/utility/source/process_thread_impl.cc
@@ -13,6 +13,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/timeutils.h"
+#include "webrtc/base/trace_event.h"
#include "webrtc/modules/include/module.h"
#include "webrtc/system_wrappers/include/logging.h"
@@ -129,7 +130,8 @@
wake_up_->Set();
}
-void ProcessThreadImpl::RegisterModule(Module* module) {
+void ProcessThreadImpl::RegisterModule(Module* module,
+ const rtc::Location& from) {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(module);
@@ -150,7 +152,7 @@
{
rtc::CritScope lock(&lock_);
- modules_.push_back(ModuleCallback(module));
+ modules_.push_back(ModuleCallback(module, from));
}
// Wake the thread calling ProcessThreadImpl::Process() to update the
@@ -189,6 +191,7 @@
}
bool ProcessThreadImpl::Process() {
+ TRACE_EVENT1("webrtc", "ProcessThreadImpl", "name", thread_name_);
int64_t now = rtc::TimeMillis();
int64_t next_checkpoint = now + (1000 * 60);
@@ -206,7 +209,12 @@
if (m.next_callback <= now ||
m.next_callback == kCallProcessImmediately) {
- m.module->Process();
+ {
+ TRACE_EVENT2("webrtc", "ModuleProcess", "function",
+ m.location.function_name(), "file",
+ m.location.file_and_line());
+ m.module->Process();
+ }
// Use a new 'now' reference to calculate when the next callback
// should occur. We'll continue to use 'now' above for the baseline
// of calculating how long we should wait, to reduce variance.
diff --git a/modules/utility/source/process_thread_impl.h b/modules/utility/source/process_thread_impl.h
index 510ab52..e07c3d7 100644
--- a/modules/utility/source/process_thread_impl.h
+++ b/modules/utility/source/process_thread_impl.h
@@ -16,6 +16,7 @@
#include <queue>
#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/platform_thread.h"
#include "webrtc/base/thread_checker.h"
#include "webrtc/modules/utility/include/process_thread.h"
@@ -35,7 +36,7 @@
void WakeUp(Module* module) override;
void PostTask(std::unique_ptr<rtc::QueuedTask> task) override;
- void RegisterModule(Module* module) override;
+ void RegisterModule(Module* module, const rtc::Location& from) override;
void DeRegisterModule(Module* module) override;
protected:
@@ -44,16 +45,18 @@
private:
struct ModuleCallback {
- ModuleCallback() : module(nullptr), next_callback(0) {}
- ModuleCallback(const ModuleCallback& cb)
- : module(cb.module), next_callback(cb.next_callback) {}
- ModuleCallback(Module* module) : module(module), next_callback(0) {}
+ ModuleCallback() = delete;
+ ModuleCallback(ModuleCallback&& cb) = default;
+ ModuleCallback(const ModuleCallback& cb) = default;
+ ModuleCallback(Module* module, const rtc::Location& location)
+ : module(module), location(location) {}
bool operator==(const ModuleCallback& cb) const {
return cb.module == module;
}
Module* const module;
- int64_t next_callback; // Absolute timestamp.
+ int64_t next_callback = 0; // Absolute timestamp.
+ const rtc::Location location;
private:
ModuleCallback& operator=(ModuleCallback&);
diff --git a/modules/utility/source/process_thread_impl_unittest.cc b/modules/utility/source/process_thread_impl_unittest.cc
index fae4c07..8b0fb96 100644
--- a/modules/utility/source/process_thread_impl_unittest.cc
+++ b/modules/utility/source/process_thread_impl_unittest.cc
@@ -11,6 +11,7 @@
#include <memory>
#include <utility>
+#include "webrtc/base/location.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/timeutils.h"
#include "webrtc/modules/include/module.h"
@@ -93,7 +94,7 @@
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout));
EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
@@ -114,7 +115,7 @@
.WillOnce(DoAll(SetEvent(event.get()), Return()))
.WillRepeatedly(Return());
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start();
@@ -141,7 +142,7 @@
Return()))
.WillRepeatedly(DoAll(Increment(&process_count), Return()));
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
thread.Start();
@@ -183,7 +184,7 @@
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
// Add a buffer of 50ms due to slowness of some trybots
// (e.g. win_drmemory_light)
@@ -244,7 +245,7 @@
Return()));
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventTimeout, event->Wait(1000));
@@ -290,7 +291,7 @@
.WillRepeatedly(Return());
EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
- thread.RegisterModule(&module);
+ thread.RegisterModule(&module, RTC_FROM_HERE);
EXPECT_EQ(kEventSignaled, started->Wait(kEventWaitTimeout));
thread.WakeUp(&module);
diff --git a/modules/video_coding/jitter_buffer_unittest.cc b/modules/video_coding/jitter_buffer_unittest.cc
index 99d4ee6..2a52eb2 100644
--- a/modules/video_coding/jitter_buffer_unittest.cc
+++ b/modules/video_coding/jitter_buffer_unittest.cc
@@ -14,6 +14,7 @@
#include <memory>
#include <vector>
+#include "webrtc/base/location.h"
#include "webrtc/common_video/h264/h264_common.h"
#include "webrtc/modules/video_coding/frame_buffer.h"
#include "webrtc/modules/video_coding/jitter_buffer.h"
@@ -199,7 +200,7 @@
MOCK_METHOD0(Start, void());
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(WakeUp, void(Module* module));
- MOCK_METHOD1(RegisterModule, void(Module* module));
+ MOCK_METHOD2(RegisterModule, void(Module* module, const rtc::Location&));
MOCK_METHOD1(DeRegisterModule, void(Module* module));
void PostTask(std::unique_ptr<rtc::QueuedTask> task) /*override*/ {}
};
diff --git a/video/rtp_stream_receiver.cc b/video/rtp_stream_receiver.cc
index e964d10..b8ef10d 100644
--- a/video/rtp_stream_receiver.cc
+++ b/video/rtp_stream_receiver.cc
@@ -14,6 +14,7 @@
#include <utility>
#include "webrtc/base/checks.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_types.h"
#include "webrtc/config.h"
@@ -184,12 +185,12 @@
// Stats callback for CNAME changes.
rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy);
- process_thread_->RegisterModule(rtp_rtcp_.get());
+ process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE);
if (config_.rtp.nack.rtp_history_ms != 0) {
nack_module_.reset(
new NackModule(clock_, nack_sender, keyframe_request_sender));
- process_thread_->RegisterModule(nack_module_.get());
+ process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE);
}
packet_buffer_ = video_coding::PacketBuffer::Create(
diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc
index fbfdb2b..c0c5dca 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -17,6 +17,7 @@
#include <utility>
#include "webrtc/base/checks.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/optional.h"
#include "webrtc/common_video/h264/profile_level_id.h"
@@ -227,8 +228,8 @@
frame_buffer_.reset(new video_coding::FrameBuffer(
clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_));
- process_thread_->RegisterModule(&video_receiver_);
- process_thread_->RegisterModule(&rtp_stream_sync_);
+ process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE);
+ process_thread_->RegisterModule(&rtp_stream_sync_, RTC_FROM_HERE);
}
VideoReceiveStream::~VideoReceiveStream() {
diff --git a/video/video_send_stream.cc b/video/video_send_stream.cc
index 3f2bba8..bc7338e 100644
--- a/video/video_send_stream.cc
+++ b/video/video_send_stream.cc
@@ -16,13 +16,14 @@
#include <utility>
#include <vector>
-#include "webrtc/common_types.h"
-#include "webrtc/common_video/include/video_bitrate_allocator.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/file.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/trace_event.h"
#include "webrtc/base/weak_ptr.h"
+#include "webrtc/common_types.h"
+#include "webrtc/common_video/include/video_bitrate_allocator.h"
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
#include "webrtc/modules/pacing/packet_router.h"
@@ -883,7 +884,7 @@
module_process_thread_ = module_process_thread;
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_)
- module_process_thread_->RegisterModule(rtp_rtcp);
+ module_process_thread_->RegisterModule(rtp_rtcp, RTC_FROM_HERE);
}
void VideoSendStreamImpl::DeRegisterProcessThread() {
diff --git a/video/vie_encoder.cc b/video/vie_encoder.cc
index 7880c4a..c30752b 100644
--- a/video/vie_encoder.cc
+++ b/video/vie_encoder.cc
@@ -16,9 +16,10 @@
#include "webrtc/base/arraysize.h"
#include "webrtc/base/checks.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
-#include "webrtc/base/trace_event.h"
#include "webrtc/base/timeutils.h"
+#include "webrtc/base/trace_event.h"
#include "webrtc/common_video/include/video_bitrate_allocator.h"
#include "webrtc/modules/pacing/paced_sender.h"
#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
@@ -329,7 +330,7 @@
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(!module_process_thread_);
module_process_thread_ = module_process_thread;
- module_process_thread_->RegisterModule(&video_sender_);
+ module_process_thread_->RegisterModule(&video_sender_, RTC_FROM_HERE);
module_process_thread_checker_.DetachFromThread();
}
diff --git a/voice_engine/channel.cc b/voice_engine/channel.cc
index 0573245..a9b9f3a 100644
--- a/voice_engine/channel.cc
+++ b/voice_engine/channel.cc
@@ -18,6 +18,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/format_macros.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/rate_limiter.h"
#include "webrtc/base/thread_checker.h"
@@ -1025,7 +1026,7 @@
// --- Add modules to process thread (for periodic schedulation)
- _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get());
+ _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get(), RTC_FROM_HERE);
// --- ACM initialization
diff --git a/voice_engine/transmit_mixer.cc b/voice_engine/transmit_mixer.cc
index ae9f0f9..eb5866c 100644
--- a/voice_engine/transmit_mixer.cc
+++ b/voice_engine/transmit_mixer.cc
@@ -14,6 +14,7 @@
#include "webrtc/audio/utility/audio_frame_operations.h"
#include "webrtc/base/format_macros.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/trace.h"
@@ -203,7 +204,7 @@
_channelManagerPtr = &channelManager;
#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
- _processThreadPtr->RegisterModule(&_monitorModule);
+ _processThreadPtr->RegisterModule(&_monitorModule, RTC_FROM_HERE);
#endif
return 0;
}
diff --git a/voice_engine/voe_base_impl.cc b/voice_engine/voe_base_impl.cc
index ecf5b94..95a30d0 100644
--- a/voice_engine/voe_base_impl.cc
+++ b/voice_engine/voe_base_impl.cc
@@ -12,6 +12,7 @@
#include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
#include "webrtc/base/format_macros.h"
+#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
@@ -213,7 +214,8 @@
// Register the ADM to the process thread, which will drive the error
// callback mechanism
if (shared_->process_thread()) {
- shared_->process_thread()->RegisterModule(shared_->audio_device());
+ shared_->process_thread()->RegisterModule(shared_->audio_device(),
+ RTC_FROM_HERE);
}
bool available = false;