From c6416fbe167df739b6551109d48eb435e26a89f9 Mon Sep 17 00:00:00 2001 From: braveyao Date: Thu, 12 Apr 2018 17:40:45 -0700 Subject: [PATCH] [desktopCapture] add some logs into trace event While investigating some screen-capture-track-end-in-meeting issues, the relevant rtc error logs are not uploaded to server as other webrtc modules do, which cause great hardness to identify the reason. This cl is to use existing trace event methods to store error logs of desktop capturers. Bug: chromium:831756 Change-Id: Id0c1b439f9b63916fb9417cf4e6f2b8f3c556fcd Reviewed-on: https://webrtc-review.googlesource.com/69783 Reviewed-by: Jamie Walch Commit-Queue: Brave Yao Cr-Commit-Position: refs/heads/master@{#22866} --- .../desktop_capture/cropping_window_capturer_win.cc | 3 +++ .../mac/desktop_configuration_monitor.cc | 6 ++++++ modules/desktop_capture/mac/screen_capturer_mac.mm | 7 +++++++ modules/desktop_capture/screen_capturer_x11.cc | 6 ++++++ .../win/screen_capturer_win_directx.cc | 2 ++ .../desktop_capture/win/screen_capturer_win_gdi.cc | 12 ++++++++++-- modules/desktop_capture/window_capturer_mac.mm | 7 ++++++- modules/desktop_capture/window_capturer_win.cc | 7 ++++++- modules/desktop_capture/window_capturer_x11.cc | 8 ++++++-- 9 files changed, 52 insertions(+), 6 deletions(-) diff --git a/modules/desktop_capture/cropping_window_capturer_win.cc b/modules/desktop_capture/cropping_window_capturer_win.cc index 2c504a002a..a5616714ba 100644 --- a/modules/desktop_capture/cropping_window_capturer_win.cc +++ b/modules/desktop_capture/cropping_window_capturer_win.cc @@ -13,6 +13,7 @@ #include "modules/desktop_capture/win/screen_capture_utils.h" #include "modules/desktop_capture/win/window_capture_utils.h" #include "rtc_base/logging.h" +#include "rtc_base/trace_event.h" #include "rtc_base/win32.h" namespace webrtc { @@ -244,6 +245,8 @@ bool CroppingWindowCapturerWin::ShouldUseScreenCapturer() { } DesktopRect CroppingWindowCapturerWin::GetWindowRectInVirtualScreen() { + TRACE_EVENT0("webrtc", + "CroppingWindowCapturerWin::GetWindowRectInVirtualScreen"); DesktopRect window_rect; HWND hwnd = reinterpret_cast(selected_window()); if (!GetCroppedWindowRect(hwnd, &window_rect, /* original_rect */ nullptr)) { diff --git a/modules/desktop_capture/mac/desktop_configuration_monitor.cc b/modules/desktop_capture/mac/desktop_configuration_monitor.cc index 4eeee32106..e8378c38d9 100644 --- a/modules/desktop_capture/mac/desktop_configuration_monitor.cc +++ b/modules/desktop_capture/mac/desktop_configuration_monitor.cc @@ -12,6 +12,7 @@ #include "modules/desktop_capture/mac/desktop_configuration.h" #include "rtc_base/logging.h" +#include "rtc_base/trace_event.h" #include "system_wrappers/include/event_wrapper.h" namespace webrtc { @@ -65,6 +66,11 @@ void DesktopConfigurationMonitor::DisplaysReconfiguredCallback( void DesktopConfigurationMonitor::DisplaysReconfigured( CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags) { + TRACE_EVENT0("webrtc", "DesktopConfigurationMonitor::DisplaysReconfigured"); + RTC_LOG(LS_INFO) << "DisplaysReconfigured: " + << "DisplayID " << display << "; ChangeSummaryFlags " + << flags; + if (flags & kCGDisplayBeginConfigurationFlag) { if (reconfiguring_displays_.empty()) { // If this is the first display to start reconfiguring then wait on diff --git a/modules/desktop_capture/mac/screen_capturer_mac.mm b/modules/desktop_capture/mac/screen_capturer_mac.mm index c06723c1a5..06f735d8dc 100644 --- a/modules/desktop_capture/mac/screen_capturer_mac.mm +++ b/modules/desktop_capture/mac/screen_capturer_mac.mm @@ -17,6 +17,7 @@ #include "rtc_base/constructormagic.h" #include "rtc_base/logging.h" #include "rtc_base/timeutils.h" +#include "rtc_base/trace_event.h" #include "sdk/objc/Framework/Classes/Common/scoped_cftyperef.h" namespace webrtc { @@ -232,10 +233,13 @@ ScreenCapturerMac::~ScreenCapturerMac() { } bool ScreenCapturerMac::Init() { + TRACE_EVENT0("webrtc", "ScreenCapturerMac::Init"); + desktop_config_monitor_->Lock(); desktop_config_ = desktop_config_monitor_->desktop_configuration(); desktop_config_monitor_->Unlock(); if (!RegisterRefreshAndMoveHandlers()) { + RTC_LOG(LS_ERROR) << "Failed to register refresh and move handlers."; return false; } ScreenConfigurationChanged(); @@ -252,11 +256,14 @@ void ScreenCapturerMac::ReleaseBuffers() { void ScreenCapturerMac::Start(Callback* callback) { RTC_DCHECK(!callback_); RTC_DCHECK(callback); + TRACE_EVENT_INSTANT1( + "webrtc", "ScreenCapturermac::Start", "target display id ", current_display_); callback_ = callback; } void ScreenCapturerMac::CaptureFrame() { + TRACE_EVENT0("webrtc", "creenCapturerMac::CaptureFrame"); int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); diff --git a/modules/desktop_capture/screen_capturer_x11.cc b/modules/desktop_capture/screen_capturer_x11.cc index 3acd2a8de9..5b099caa3d 100644 --- a/modules/desktop_capture/screen_capturer_x11.cc +++ b/modules/desktop_capture/screen_capturer_x11.cc @@ -30,6 +30,7 @@ #include "rtc_base/constructormagic.h" #include "rtc_base/logging.h" #include "rtc_base/timeutils.h" +#include "rtc_base/trace_event.h" namespace webrtc { namespace { @@ -134,6 +135,7 @@ ScreenCapturerLinux::~ScreenCapturerLinux() { } bool ScreenCapturerLinux::Init(const DesktopCaptureOptions& options) { + TRACE_EVENT0("webrtc", "ScreenCapturerLinux::Init"); options_ = options; root_window_ = RootWindow(display(), DefaultScreen(display())); @@ -225,6 +227,7 @@ void ScreenCapturerLinux::Start(Callback* callback) { } void ScreenCapturerLinux::CaptureFrame() { + TRACE_EVENT0("webrtc", "ScreenCapturerLinux::CaptureFrame"); int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); @@ -238,6 +241,7 @@ void ScreenCapturerLinux::CaptureFrame() { // in a good shape. if (!x_server_pixel_buffer_.is_initialized()) { // We failed to initialize pixel buffer. + RTC_LOG(LS_ERROR) << "Pixel buffer is not initialized."; callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); return; } @@ -253,6 +257,7 @@ void ScreenCapturerLinux::CaptureFrame() { std::unique_ptr result = CaptureScreen(); if (!result) { + RTC_LOG(LS_WARNING) << "Temporarily failed to capture screen."; callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; } @@ -349,6 +354,7 @@ std::unique_ptr ScreenCapturerLinux::CaptureScreen() { } void ScreenCapturerLinux::ScreenConfigurationChanged() { + TRACE_EVENT0("webrtc", "ScreenCapturerLinux::ScreenConfigurationChanged"); // Make sure the frame buffers will be reallocated. queue_.Reset(); diff --git a/modules/desktop_capture/win/screen_capturer_win_directx.cc b/modules/desktop_capture/win/screen_capturer_win_directx.cc index b03d2e17de..807acc6bfd 100644 --- a/modules/desktop_capture/win/screen_capturer_win_directx.cc +++ b/modules/desktop_capture/win/screen_capturer_win_directx.cc @@ -21,6 +21,7 @@ #include "rtc_base/logging.h" #include "rtc_base/ptr_util.h" #include "rtc_base/timeutils.h" +#include "rtc_base/trace_event.h" namespace webrtc { @@ -117,6 +118,7 @@ void ScreenCapturerWinDirectx::SetSharedMemoryFactory( void ScreenCapturerWinDirectx::CaptureFrame() { RTC_DCHECK(callback_); + TRACE_EVENT0("webrtc", "ScreenCapturerWinDirectx::CaptureFrame"); int64_t capture_start_time_nanos = rtc::TimeNanos(); diff --git a/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/modules/desktop_capture/win/screen_capturer_win_gdi.cc index 2c299fc72a..25aa0d110b 100644 --- a/modules/desktop_capture/win/screen_capturer_win_gdi.cc +++ b/modules/desktop_capture/win/screen_capturer_win_gdi.cc @@ -23,6 +23,7 @@ #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/timeutils.h" +#include "rtc_base/trace_event.h" namespace webrtc { @@ -70,6 +71,7 @@ void ScreenCapturerWinGdi::SetSharedMemoryFactory( } void ScreenCapturerWinGdi::CaptureFrame() { + TRACE_EVENT0("webrtc", "ScreenCapturerWinGdi::CaptureFrame"); int64_t capture_start_time_nanos = rtc::TimeNanos(); queue_.MoveToNextFrame(); @@ -79,6 +81,7 @@ void ScreenCapturerWinGdi::CaptureFrame() { PrepareCaptureResources(); if (!CaptureImage()) { + RTC_LOG(WARNING) << "Failed to capture screen by GDI."; callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; } @@ -177,8 +180,10 @@ void ScreenCapturerWinGdi::PrepareCaptureResources() { bool ScreenCapturerWinGdi::CaptureImage() { DesktopRect screen_rect = GetScreenRect(current_screen_id_, current_device_key_); - if (screen_rect.is_empty()) + if (screen_rect.is_empty()) { + RTC_LOG(LS_WARNING) << "Failed to get screen rect."; return false; + } DesktopSize size = screen_rect.size(); // If the current buffer is from an older generation then allocate a new one. @@ -191,8 +196,10 @@ bool ScreenCapturerWinGdi::CaptureImage() { std::unique_ptr buffer = DesktopFrameWin::Create( size, shared_memory_factory_.get(), desktop_dc_); - if (!buffer) + if (!buffer) { + RTC_LOG(LS_WARNING) << "Failed to create frame buffer."; return false; + } queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(buffer))); } queue_.current_frame()->set_top_left( @@ -204,6 +211,7 @@ bool ScreenCapturerWinGdi::CaptureImage() { queue_.current_frame()->GetUnderlyingFrame()); HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); if (!previous_object || previous_object == HGDI_ERROR) { + RTC_LOG(LS_WARNING) << "Failed to select current bitmap into memery dc."; return false; } diff --git a/modules/desktop_capture/window_capturer_mac.mm b/modules/desktop_capture/window_capturer_mac.mm index bbdcdd5283..89a53660ca 100644 --- a/modules/desktop_capture/window_capturer_mac.mm +++ b/modules/desktop_capture/window_capturer_mac.mm @@ -18,15 +18,16 @@ #include "modules/desktop_capture/desktop_capture_options.h" #include "modules/desktop_capture/desktop_capturer.h" #include "modules/desktop_capture/desktop_frame.h" -#include "modules/desktop_capture/window_finder_mac.h" #include "modules/desktop_capture/mac/desktop_configuration.h" #include "modules/desktop_capture/mac/desktop_configuration_monitor.h" #include "modules/desktop_capture/mac/full_screen_chrome_window_detector.h" #include "modules/desktop_capture/mac/window_list_utils.h" +#include "modules/desktop_capture/window_finder_mac.h" #include "rtc_base/constructormagic.h" #include "rtc_base/logging.h" #include "rtc_base/macutils.h" #include "rtc_base/scoped_ref_ptr.h" +#include "rtc_base/trace_event.h" namespace webrtc { @@ -155,7 +156,10 @@ void WindowCapturerMac::Start(Callback* callback) { } void WindowCapturerMac::CaptureFrame() { + TRACE_EVENT0("webrtc", "WindowCapturerMac::CaptureFrame"); + if (!IsWindowValid(window_id_)) { + RTC_LOG(LS_ERROR) << "The window is not valid any longer."; callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); return; } @@ -174,6 +178,7 @@ void WindowCapturerMac::CaptureFrame() { on_screen_window, kCGWindowImageBoundsIgnoreFraming); if (!window_image) { + RTC_LOG(LS_WARNING) << "Temporarily failed to capture window."; callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; } diff --git a/modules/desktop_capture/window_capturer_win.cc b/modules/desktop_capture/window_capturer_win.cc index d1a672b66f..7fa7e34dce 100644 --- a/modules/desktop_capture/window_capturer_win.cc +++ b/modules/desktop_capture/window_capturer_win.cc @@ -14,12 +14,13 @@ #include "modules/desktop_capture/desktop_capturer.h" #include "modules/desktop_capture/desktop_frame_win.h" -#include "modules/desktop_capture/window_finder_win.h" #include "modules/desktop_capture/win/screen_capture_utils.h" #include "modules/desktop_capture/win/window_capture_utils.h" +#include "modules/desktop_capture/window_finder_win.h" #include "rtc_base/checks.h" #include "rtc_base/constructormagic.h" #include "rtc_base/logging.h" +#include "rtc_base/trace_event.h" #include "rtc_base/win32.h" namespace webrtc { @@ -208,6 +209,8 @@ void WindowCapturerWin::Start(Callback* callback) { } void WindowCapturerWin::CaptureFrame() { + TRACE_EVENT0("webrtc", "WindowCapturerWin::CaptureFrame"); + if (!window_) { RTC_LOG(LS_ERROR) << "Window hasn't been selected: " << GetLastError(); callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); @@ -216,6 +219,7 @@ void WindowCapturerWin::CaptureFrame() { // Stop capturing if the window has been closed. if (!IsWindow(window_)) { + RTC_LOG(LS_ERROR) << "target window has been closed"; callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); return; } @@ -277,6 +281,7 @@ void WindowCapturerWin::CaptureFrame() { std::unique_ptr frame( DesktopFrameWin::Create(cropped_rect.size(), nullptr, window_dc)); if (!frame.get()) { + RTC_LOG(LS_WARNING) << "Failed to create frame."; ReleaseDC(window_, window_dc); callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; diff --git a/modules/desktop_capture/window_capturer_x11.cc b/modules/desktop_capture/window_capturer_x11.cc index 8985ab163e..5536b6a2d9 100644 --- a/modules/desktop_capture/window_capturer_x11.cc +++ b/modules/desktop_capture/window_capturer_x11.cc @@ -28,6 +28,7 @@ #include "rtc_base/constructormagic.h" #include "rtc_base/logging.h" #include "rtc_base/scoped_ref_ptr.h" +#include "rtc_base/trace_event.h" namespace webrtc { @@ -181,8 +182,10 @@ void WindowCapturerLinux::Start(Callback* callback) { } void WindowCapturerLinux::CaptureFrame() { + TRACE_EVENT0("webrtc", "WindowCapturerLinux::CaptureFrame"); + if (!x_server_pixel_buffer_.IsWindowValid()) { - RTC_LOG(LS_INFO) << "The window is no longer valid."; + RTC_LOG(LS_ERROR) << "The window is no longer valid."; callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); return; } @@ -193,7 +196,7 @@ void WindowCapturerLinux::CaptureFrame() { // Without the Xcomposite extension we capture when the whole window is // visible on screen and not covered by any other window. This is not // something we want so instead, just bail out. - RTC_LOG(LS_INFO) << "No Xcomposite extension detected."; + RTC_LOG(LS_ERROR) << "No Xcomposite extension detected."; callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); return; } @@ -212,6 +215,7 @@ void WindowCapturerLinux::CaptureFrame() { x_server_pixel_buffer_.Synchronize(); if (!x_server_pixel_buffer_.CaptureRect(DesktopRect::MakeSize(frame->size()), frame.get())) { + RTC_LOG(LS_WARNING) << "Temporarily failed to capture winodw."; callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); return; }