bug 606574 - Win32 event loop instrumentation. r=jimm

This commit is contained in:
Ted Mielczarek 2011-03-03 11:20:02 -05:00
parent 6b0a6c93bb
commit ab4ffe654b
6 changed files with 189 additions and 26 deletions

View File

@ -5203,6 +5203,7 @@ cairo-windows)
;; ;;
esac esac
MOZ_PDF_PRINTING=1 MOZ_PDF_PRINTING=1
MOZ_INSTRUMENT_EVENT_LOOP=1
;; ;;
cairo-gtk2|cairo-gtk2-x11) cairo-gtk2|cairo-gtk2-x11)

View File

@ -45,6 +45,9 @@ namespace mozilla {
// a thread that's not the UI thread. // a thread that's not the UI thread.
bool FireAndWaitForTracerEvent(); bool FireAndWaitForTracerEvent();
// Signal that the event has been received by the event loop.
void SignalTracerThread();
} }
#endif // WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ #endif // WIDGET_PUBLIC_WIDGETTRACEEVENT_H_

View File

@ -47,32 +47,33 @@ LIBRARY_NAME = widget_windows
LIBXUL_LIBRARY = 1 LIBXUL_LIBRARY = 1
CPPSRCS = \ CPPSRCS = \
nsWindow.cpp \ nsWindow.cpp \
nsWindowGfx.cpp \ nsWindowGfx.cpp \
nsWindowDbg.cpp \ nsWindowDbg.cpp \
nsAppShell.cpp \ nsAppShell.cpp \
nsToolkit.cpp \ nsToolkit.cpp \
nsFilePicker.cpp \ nsFilePicker.cpp \
nsScreenWin.cpp \ nsScreenWin.cpp \
nsScreenManagerWin.cpp \ nsScreenManagerWin.cpp \
nsLookAndFeel.cpp \ nsLookAndFeel.cpp \
nsUXThemeData.cpp \ nsUXThemeData.cpp \
nsNativeThemeWin.cpp \ nsNativeThemeWin.cpp \
nsWinGesture.cpp \ nsWinGesture.cpp \
nsIdleServiceWin.cpp \ nsIdleServiceWin.cpp \
nsSound.cpp \ nsSound.cpp \
nsIMM32Handler.cpp \ nsIMM32Handler.cpp \
WindowHook.cpp \ WindowHook.cpp \
WinTaskbar.cpp \ WinTaskbar.cpp \
TaskbarPreview.cpp \ TaskbarPreview.cpp \
TaskbarTabPreview.cpp \ TaskbarTabPreview.cpp \
TaskbarWindowPreview.cpp \ TaskbarWindowPreview.cpp \
TaskbarPreviewButton.cpp \ TaskbarPreviewButton.cpp \
JumpListBuilder.cpp \ JumpListBuilder.cpp \
JumpListItem.cpp \ JumpListItem.cpp \
GfxInfo.cpp \ GfxInfo.cpp \
$(NULL) WidgetTraceEvent.cpp \
$(NULL)
ifdef MOZ_CRASHREPORTER ifdef MOZ_CRASHREPORTER
CPPSRCS += LSPAnnotator.cpp CPPSRCS += LSPAnnotator.cpp

View File

@ -0,0 +1,148 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ted Mielczarek <ted.mielczarek@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* Windows widget support for event loop instrumentation.
* See toolkit/xre/EventTracer.cpp for more details.
*/
#include <stdio.h>
#include <windows.h>
#include "mozilla/WidgetTraceEvent.h"
#include "nsAppShellCID.h"
#include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h"
#include "nsIAppShellService.h"
#include "nsIBaseWindow.h"
#include "nsIDocShell.h"
#include "nsIWidget.h"
#include "nsIXULWindow.h"
#include "nsAutoPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsWindowDefs.h"
namespace {
// Used for signaling the background thread from the main thread.
HANDLE event_handle = NULL;
// We need a runnable in order to find the hidden window on the main
// thread.
class HWNDGetter : public nsRunnable {
public:
HWNDGetter() : hidden_window_hwnd(NULL) {}
HWND hidden_window_hwnd;
NS_IMETHOD Run() {
// Jump through some hoops to locate the hidden window.
nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
nsCOMPtr<nsIXULWindow> hiddenWindow;
nsresult rv = appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIDocShell> docShell;
rv = hiddenWindow->GetDocShell(getter_AddRefs(docShell));
if (NS_FAILED(rv) || !docShell) {
return rv;
}
nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell));
if (!baseWindow)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWidget> widget;
baseWindow->GetMainWidget(getter_AddRefs(widget));
if (!widget)
return NS_ERROR_FAILURE;
hidden_window_hwnd = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW);
return NS_OK;
}
};
HWND GetHiddenWindowHWND()
{
// Need to dispatch this to the main thread because plenty of
// the things it wants to access are main-thread-only.
nsRefPtr<HWNDGetter> getter = new HWNDGetter();
NS_DispatchToMainThread(getter, NS_DISPATCH_SYNC);
return getter->hidden_window_hwnd;
}
} // namespace
namespace mozilla {
// This function is called from the main (UI) thread.
void SignalTracerThread()
{
if (event_handle != NULL)
SetEvent(event_handle);
}
// This function is called from the background tracer thread.
bool FireAndWaitForTracerEvent()
{
// First, try to find the hidden window.
static HWND hidden_window = NULL;
if (hidden_window == NULL) {
hidden_window = GetHiddenWindowHWND();
}
if (hidden_window == NULL)
return false;
if (event_handle == NULL)
event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
// Post the tracer message into the hidden window's message queue,
// and then block until it's processed.
PostMessage(hidden_window, MOZ_WM_TRACE, 0, 0);
WaitForSingleObject(event_handle, INFINITE);
return true;
}
} // namespace mozilla

View File

@ -118,6 +118,7 @@
#include "prprf.h" #include "prprf.h"
#include "prmem.h" #include "prmem.h"
#include "mozilla/WidgetTraceEvent.h"
#include "nsIAppShell.h" #include "nsIAppShell.h"
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
#include "nsIDOMNSUIEvent.h" #include "nsIDOMNSUIEvent.h"
@ -4596,6 +4597,13 @@ LRESULT CALLBACK nsWindow::WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam
} }
} }
if (msg == MOZ_WM_TRACE) {
// This is a tracer event for measuring event loop latency.
// See WidgetTraceEvent.cpp for more details.
mozilla::SignalTracerThread();
return 0;
}
// Get the window which caused the event and ask it to process the message // Get the window which caused the event and ask it to process the message
nsWindow *someWindow = GetNSWindowPtr(hWnd); nsWindow *someWindow = GetNSWindowPtr(hWnd);

View File

@ -56,6 +56,8 @@
// A magic APP message that can be sent to quit, sort of like a QUERYENDSESSION/ENDSESSION, // A magic APP message that can be sent to quit, sort of like a QUERYENDSESSION/ENDSESSION,
// but without the query. // but without the query.
#define MOZ_WM_APP_QUIT (WM_APP+0x0300) #define MOZ_WM_APP_QUIT (WM_APP+0x0300)
// Used as a "tracer" event to probe event loop latency.
#define MOZ_WM_TRACE (WM_APP+0x0301)
// GetWindowsVersion constants // GetWindowsVersion constants
#define WIN2K_VERSION 0x500 #define WIN2K_VERSION 0x500