Bug 696033 - Add xperf probes (sample startup probes); r=glandium
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Sun, 05 Feb 2012 22:49:37 +0000
changeset 86220 0eebc33d85937dbd96964318d1a0653898134a01
parent 86219 ccaccc29ae9e6ab675fce87a97de56915d7facb6
child 86221 a963e2178e050726121a4ab38369c25a8165b503
push id5726
push userbmo@edmorley.co.uk
push dateSun, 05 Feb 2012 22:50:25 +0000
treeherdermozilla-inbound@0eebc33d8593 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs696033
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 696033 - Add xperf probes (sample startup probes); r=glandium
toolkit/components/startup/mozprofilerprobe.mof
toolkit/components/startup/nsAppStartup.cpp
toolkit/components/startup/nsAppStartup.h
new file mode 100644
--- /dev/null
+++ b/toolkit/components/startup/mozprofilerprobe.mof
@@ -0,0 +1,22 @@
+#pragma namespace("\\\\.\\root\\wmi")
+#pragma autorecover
+
+[dynamic: ToInstance, Description("Mozilla Generic Provider"),
+ Guid("{509962E0-406B-46F4-99BA-5A009F8D2225}")]
+class MozillaProvider : EventTrace
+{
+};
+
+[dynamic: ToInstance, Description("Mozilla Event: Places Init is complete."): Amended,
+ Guid("{A3DA04E0-57D7-482A-A1C1-61DA5F95BACB}"),
+ EventType(1)]
+class MozillaEventPlacesInit : MozillaProvider
+{
+};
+
+[dynamic: ToInstance, Description("Mozilla Event: Session Store Window Restored."): Amended,
+ Guid("{917B96B1-ECAD-4DAB-A760-8D49027748AE}"),
+ EventType(1)]
+class MozillaEventSessionStoreWindowRestored : MozillaProvider
+{
+};
\ No newline at end of file
--- a/toolkit/components/startup/nsAppStartup.cpp
+++ b/toolkit/components/startup/nsAppStartup.cpp
@@ -22,16 +22,17 @@
  *
  * Contributor(s):
  *   Pierre Phaneuf <pp@ludusdesign.com>
  *   Robert O'Callahan <roc+moz@cs.cmu.edu>
  *   Benjamin Smedberg <bsmedberg@covad.net>
  *   Daniel Brooks <db48x@db48x.net>
  *   Taras Glek <tglek@mozilla.com>
  *   Landry Breuil <landry@openbsd.org>
+ *   David Rajchenbach-Teller <dteller@mozilla.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of 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
@@ -93,16 +94,48 @@
 #include <sys/sysctl.h>
 #endif
 
 #include "mozilla/Telemetry.h"
 #include "mozilla/StartupTimeline.h"
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
+#if defined(XP_WIN)
+#include "mozilla/perfprobe.h"
+/**
+ * Events sent to the system for profiling purposes
+ */
+//Keep them syncronized with the .mof file
+
+//Process-wide GUID, used by the OS to differentiate sources
+// {509962E0-406B-46F4-99BA-5A009F8D2225}
+//Keep it synchronized with the .mof file
+#define NS_APPLICATION_TRACING_CID \
+  { 0x509962E0, 0x406B, 0x46F4, \
+  { 0x99, 0xBA, 0x5A, 0x00, 0x9F, 0x8D, 0x22, 0x25} }
+
+//Event-specific GUIDs, used by the OS to differentiate events
+// {A3DA04E0-57D7-482A-A1C1-61DA5F95BACB}
+#define NS_PLACES_INIT_COMPLETE_EVENT_CID \
+  { 0xA3DA04E0, 0x57D7, 0x482A, \
+  { 0xA1, 0xC1, 0x61, 0xDA, 0x5F, 0x95, 0xBA, 0xCB} }
+// {917B96B1-ECAD-4DAB-A760-8D49027748AE}
+#define NS_SESSION_STORE_WINDOW_RESTORED_EVENT_CID \
+  { 0x917B96B1, 0xECAD, 0x4DAB, \
+  { 0xA7, 0x60, 0x8D, 0x49, 0x02, 0x77, 0x48, 0xAE} }
+
+static NS_DEFINE_CID(kApplicationTracingCID,
+  NS_APPLICATION_TRACING_CID);
+static NS_DEFINE_CID(kPlacesInitCompleteCID,
+  NS_PLACES_INIT_COMPLETE_EVENT_CID);
+static NS_DEFINE_CID(kSessionStoreWindowRestoredCID,
+  NS_SESSION_STORE_WINDOW_RESTORED_EVENT_CID);
+#endif //defined(XP_WIN)
+
 using namespace mozilla;
 
 PRUint32 gRestartMode = 0;
 
 class nsAppExitEvent : public nsRunnable {
 private:
   nsRefPtr<nsAppStartup> mService;
 
@@ -154,16 +187,49 @@ nsAppStartup::Init()
   NS_TIME_FUNCTION_MARK("Got Observer service");
 
   os->AddObserver(this, "quit-application-forced", true);
   os->AddObserver(this, "sessionstore-windows-restored", true);
   os->AddObserver(this, "profile-change-teardown", true);
   os->AddObserver(this, "xul-window-registered", true);
   os->AddObserver(this, "xul-window-destroyed", true);
 
+#if defined(XP_WIN)
+  os->AddObserver(this, "places-init-complete", true);
+  // This last event is only interesting to us for xperf-based measures
+
+  // Initialize interaction with profiler
+  mProbesManager =
+    new ProbeManager(
+                     kApplicationTracingCID,
+                     NS_LITERAL_CSTRING("Application startup probe"));
+  // Note: The operation is meant mostly for in-house profiling.
+  // Therefore, we do not warn if probes manager cannot be initialized
+
+  if (mProbesManager) {
+    mPlacesInitCompleteProbe =
+      mProbesManager->
+      GetProbe(kPlacesInitCompleteCID,
+               NS_LITERAL_CSTRING("places-init-complete"));
+    NS_WARN_IF_FALSE(mPlacesInitCompleteProbe,
+                     "Cannot initialize probe 'places-init-complete'");
+
+    mSessionWindowRestoredProbe =
+      mProbesManager->
+      GetProbe(kSessionStoreWindowRestoredCID,
+               NS_LITERAL_CSTRING("sessionstore-windows-restored"));
+    NS_WARN_IF_FALSE(mSessionWindowRestoredProbe,
+                     "Cannot initialize probe 'sessionstore-windows-restored'");
+
+    rv = mProbesManager->StartSession();
+    NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
+                     "Cannot initialize system probe manager");
+  }
+#endif //defined(XP_WIN)
+
   return NS_OK;
 }
 
 
 //
 // nsAppStartup->nsISupports
 //
 
@@ -555,16 +621,25 @@ nsAppStartup::Observe(nsISupports *aSubj
       ExitLastWindowClosingSurvivalArea();
     }
   } else if (!strcmp(aTopic, "xul-window-registered")) {
     EnterLastWindowClosingSurvivalArea();
   } else if (!strcmp(aTopic, "xul-window-destroyed")) {
     ExitLastWindowClosingSurvivalArea();
   } else if (!strcmp(aTopic, "sessionstore-windows-restored")) {
     StartupTimeline::Record(StartupTimeline::SESSION_RESTORED);
+#if defined(XP_WIN)
+    if (mSessionWindowRestoredProbe) {
+      mSessionWindowRestoredProbe->Trigger();
+    }
+  } else if (!strcmp(aTopic, "places-init-complete")) {
+    if (mPlacesInitCompleteProbe) {
+      mPlacesInitCompleteProbe->Trigger();
+    }
+#endif //defined(XP_WIN)
   } else {
     NS_ERROR("Unexpected observer topic.");
   }
 
   return NS_OK;
 }
 
 #if defined(LINUX) || defined(ANDROID)
--- a/toolkit/components/startup/nsAppStartup.h
+++ b/toolkit/components/startup/nsAppStartup.h
@@ -17,16 +17,17 @@
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Benjamin Smedberg <bsmedberg@covad.net>
+ *   David Rajchenbach-Teller <dteller@mozilla.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of 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
@@ -43,16 +44,23 @@
 #include "nsIAppStartup.h"
 #include "nsIWindowCreator2.h"
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 
 #include "nsINativeAppSupport.h"
 #include "nsIAppShell.h"
 
+#if defined(XP_WIN)
+//XPerf-backed probes
+#include "mozilla/perfprobe.h"
+#include "nsAutoPtr.h"
+#endif //defined(XP_WIN)
+
+
 struct PLEvent;
 
 // {7DD4D320-C84B-4624-8D45-7BB9B2356977}
 #define NS_TOOLKIT_APPSTARTUP_CID \
 { 0x7dd4d320, 0xc84b, 0x4624, { 0x8d, 0x45, 0x7b, 0xb9, 0xb2, 0x35, 0x69, 0x77 } }
 
 
 class nsAppStartup : public nsIAppStartup,
@@ -80,11 +88,20 @@ private:
   nsCOMPtr<nsIAppShell> mAppShell;
 
   PRInt32      mConsiderQuitStopper; // if > 0, Quit(eConsiderQuit) fails
   bool mRunning;        // Have we started the main event loop?
   bool mShuttingDown;   // Quit method reentrancy check
   bool mAttemptingQuit; // Quit(eAttemptQuit) still trying
   bool mRestart;        // Quit(eRestart)
   bool mInterrupted;    // Was startup interrupted by an interactive prompt?
+
+#if defined(XP_WIN)
+  //Interaction with OS-provided profiling probes
+  typedef mozilla::probes::ProbeManager ProbeManager;
+  typedef mozilla::probes::Probe        Probe;
+  nsRefPtr<ProbeManager> mProbesManager;
+  nsRefPtr<Probe> mPlacesInitCompleteProbe;
+  nsRefPtr<Probe> mSessionWindowRestoredProbe;
+#endif
 };
 
 #endif // nsAppStartup_h__