Bug 1380659 - Introduce code coverage component to dump/reset coverage counters. r=erahm
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 14 Jul 2017 10:58:56 +0200
changeset 419207 c7686d42d8ad3c6c8d1874ef074775c93f3660ab
parent 419206 5decf9441f50df54458f9d35fe0d583acbbec12f
child 419208 d771b46e84df61453e0e5522b9d32ed5be83241b
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1380659
milestone56.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 1380659 - Introduce code coverage component to dump/reset coverage counters. r=erahm
browser/installer/package-manifest.in
ipc/glue/CodeCoverageHandler.cpp
ipc/glue/CodeCoverageHandler.h
ipc/glue/moz.build
toolkit/toolkit.mozbuild
tools/code-coverage/CodeCoverageHandler.cpp
tools/code-coverage/CodeCoverageHandler.h
tools/code-coverage/moz.build
tools/code-coverage/nsCodeCoverage.cpp
tools/code-coverage/nsCodeCoverage.h
tools/code-coverage/nsCodeCoverageFactory.cpp
tools/code-coverage/nsICodeCoverage.idl
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -180,16 +180,19 @@
 @RESPATH@/components/appstartup.xpt
 @RESPATH@/components/autocomplete.xpt
 @RESPATH@/components/autoconfig.xpt
 @RESPATH@/components/browser-element.xpt
 @RESPATH@/browser/components/browsercompsbase.xpt
 @RESPATH@/browser/components/browser-feeds.xpt
 @RESPATH@/components/caps.xpt
 @RESPATH@/components/chrome.xpt
+#ifdef MOZ_CODE_COVERAGE
+@RESPATH@/components/code-coverage.xpt
+#endif
 @RESPATH@/components/commandhandler.xpt
 @RESPATH@/components/commandlines.xpt
 @RESPATH@/components/composer.xpt
 @RESPATH@/components/content_events.xpt
 @RESPATH@/components/content_html.xpt
 @RESPATH@/components/content_geckomediaplugins.xpt
 #ifdef MOZ_WEBRTC
 @RESPATH@/components/content_webrtc.xpt
--- a/ipc/glue/moz.build
+++ b/ipc/glue/moz.build
@@ -209,25 +209,16 @@ IPDL_SOURCES = [
 
 LOCAL_INCLUDES += [
     '/dom/ipc',
     '/toolkit/crashreporter',
     '/toolkit/xre',
     '/xpcom/threads',
 ]
 
-if CONFIG['MOZ_CODE_COVERAGE']:
-    SOURCES += [
-        'CodeCoverageHandler.cpp',
-    ]
-
-    EXPORTS.mozilla += [
-        'CodeCoverageHandler.h',
-    ]
-
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 for var in ('MOZ_CHILD_PROCESS_NAME', 'MOZ_CHILD_PROCESS_NAME_PIE',
             'MOZ_CHILD_PROCESS_BUNDLE', 'DLL_PREFIX', 'DLL_SUFFIX'):
     DEFINES[var] = '"%s"' % CONFIG[var]
 
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -106,16 +106,17 @@ else:
 
 # toolkit
 
 # This must precede xpfe.
 if CONFIG['MOZ_JPROF']:
     DIRS += ['/tools/jprof']
 
 DIRS += [
+    '/tools/code-coverage',
     '/tools/power',
     '/tools/profiler',
     '/tools/memory-profiler',
     '/xpfe/components',
 ]
 
 if CONFIG['MOZ_ENABLE_XREMOTE']:
     DIRS += ['/widget/xremoteclient']
rename from ipc/glue/CodeCoverageHandler.cpp
rename to tools/code-coverage/CodeCoverageHandler.cpp
rename from ipc/glue/CodeCoverageHandler.h
rename to tools/code-coverage/CodeCoverageHandler.h
new file mode 100644
--- /dev/null
+++ b/tools/code-coverage/moz.build
@@ -0,0 +1,31 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+if CONFIG['MOZ_CODE_COVERAGE']:
+    XPIDL_MODULE = 'code-coverage'
+
+    XPIDL_SOURCES += [
+        'nsICodeCoverage.idl',
+    ]
+
+    SOURCES += [
+        'CodeCoverageHandler.cpp',
+        'nsCodeCoverage.cpp',
+        'nsCodeCoverageFactory.cpp',
+    ]
+
+    EXPORTS.mozilla += [
+        'CodeCoverageHandler.h',
+    ]
+
+    LOCAL_INCLUDES += [
+        '/ipc/chromium/src',
+        '/xpcom/base',
+    ]
+
+    include('/ipc/chromium/chromium-config.mozbuild')
+
+    FINAL_LIBRARY = 'xul'
new file mode 100644
--- /dev/null
+++ b/tools/code-coverage/nsCodeCoverage.cpp
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsCodeCoverage.h"
+#include "mozilla/CodeCoverageHandler.h"
+#include "mozilla/Unused.h"
+#include "mozilla/dom/ContentParent.h"
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
+NS_IMPL_ISUPPORTS(nsCodeCoverage,
+                  nsICodeCoverage)
+
+nsCodeCoverage::nsCodeCoverage()
+{
+}
+
+nsCodeCoverage::~nsCodeCoverage()
+{
+}
+
+NS_IMETHODIMP nsCodeCoverage::DumpCounters()
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(NS_IsMainThread());
+
+  CodeCoverageHandler::DumpCounters(0);
+  for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
+    Unused << cp->SendDumpCodeCoverageCounters();
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsCodeCoverage::ResetCounters()
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(NS_IsMainThread());
+
+  CodeCoverageHandler::ResetCounters(0);
+  for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
+    Unused << cp->SendResetCodeCoverageCounters();
+  }
+
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/tools/code-coverage/nsCodeCoverage.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef tools_codecoverage_nscodecoverage_h
+#define tools_codecoverage_nscodecoverage_h
+
+#include "nsICodeCoverage.h"
+
+#define NS_CODECOVERAGE_CID \
+{ 0x93576af0, 0xa62f, 0x4c88, \
+{ 0xbc, 0x12, 0xf1, 0x85, 0x5d, 0x4e, 0x01, 0x73 } }
+
+class nsCodeCoverage final : nsICodeCoverage {
+public:
+  NS_DECL_THREADSAFE_ISUPPORTS
+  NS_DECL_NSICODECOVERAGE
+
+  nsCodeCoverage();
+
+private:
+  ~nsCodeCoverage();
+};
+
+#endif // tools_codecoverage_nscodecoverage_h
new file mode 100644
--- /dev/null
+++ b/tools/code-coverage/nsCodeCoverageFactory.cpp
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/ModuleUtils.h"
+#include "nsCOMPtr.h"
+#include "nsCodeCoverage.h"
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsCodeCoverage)
+
+NS_DEFINE_NAMED_CID(NS_CODECOVERAGE_CID);
+
+static const mozilla::Module::CIDEntry kCodeCoverageCIDs[] = {
+    { &kNS_CODECOVERAGE_CID, false, nullptr, nsCodeCoverageConstructor },
+    { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kCodeCoverageContracts[] = {
+    { "@mozilla.org/tools/code-coverage;1", &kNS_CODECOVERAGE_CID },
+    { nullptr }
+};
+
+static const mozilla::Module kCodeCoverageModule = {
+    mozilla::Module::kVersion,
+    kCodeCoverageCIDs,
+    kCodeCoverageContracts
+};
+
+NSMODULE_DEFN(nsCodeCoverageModule) = &kCodeCoverageModule;
new file mode 100644
--- /dev/null
+++ b/tools/code-coverage/nsICodeCoverage.idl
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsISupports.idl"
+
+/**
+ * The nsICodeCoverage component allows controlling the code coverage counters
+ * collected by Firefox during execution.
+ * By resetting and dumping the counters, one can analyze the coverage information
+ * for a subset of the program execution (e.g. startup code coverage).
+ *
+ */
+
+[scriptable, uuid(57d92056-37b4-4d0a-a52f-deb8f6dac8bc)]
+interface nsICodeCoverage : nsISupports
+{
+  /**
+   * Write the coverage counters to disk.
+   */
+  void dumpCounters();
+
+  /**
+   * Reset the coverage counters to 0 (as if nothing was executed).
+   */
+  void resetCounters();
+};