Bug 1123237 - Part 7. XPCOM interface for memory profiler. r=smaug
authorKan-Ru Chen <kanru@kanru.info>
Fri, 08 May 2015 11:22:38 +0800
changeset 295334 660efe6d6e57ed63b2be2dcba3c70cc1d2b9c75d
parent 295333 ec9d11f8bfa172c43409da56bbe9d6cddd13476d
child 295335 a7bc50840fa23fd8b391c3b0d9f1bc4c98751871
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1123237
milestone43.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 1123237 - Part 7. XPCOM interface for memory profiler. r=smaug Based on patch from Ting-Yuan Huang <laszio.bugzilla@gmail.com>
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
mobile/android/installer/package-manifest.in
toolkit/toolkit.mozbuild
tools/memory-profiler/MemoryProfiler.cpp
tools/memory-profiler/MemoryProfiler.h
tools/memory-profiler/moz.build
tools/memory-profiler/nsIMemoryProfiler.idl
tools/memory-profiler/nsMemoryProfilerFactory.cpp
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -280,16 +280,19 @@
 @RESPATH@/components/layout_base.xpt
 #ifdef NS_PRINTING
 @RESPATH@/components/layout_printing.xpt
 #endif
 @RESPATH@/components/layout_xul_tree.xpt
 @RESPATH@/components/layout_xul.xpt
 @RESPATH@/components/locale.xpt
 @RESPATH@/components/lwbrk.xpt
+#ifdef MOZ_ENABLE_PROFILER_SPS
+@RESPATH@/components/memory_profiler.xpt
+#endif
 @RESPATH@/components/migration.xpt
 @RESPATH@/components/mimetype.xpt
 @RESPATH@/components/mozfind.xpt
 @RESPATH@/components/necko_about.xpt
 @RESPATH@/components/necko_cache.xpt
 @RESPATH@/components/necko_cache2.xpt
 @RESPATH@/components/necko_cookie.xpt
 @RESPATH@/components/necko_dns.xpt
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -266,16 +266,19 @@
 @RESPATH@/components/layout_base.xpt
 #ifdef NS_PRINTING
 @RESPATH@/components/layout_printing.xpt
 #endif
 @RESPATH@/components/layout_xul_tree.xpt
 @RESPATH@/components/layout_xul.xpt
 @RESPATH@/components/locale.xpt
 @RESPATH@/components/lwbrk.xpt
+#ifdef MOZ_ENABLE_PROFILER_SPS
+@RESPATH@/components/memory_profiler.xpt
+#endif
 @RESPATH@/browser/components/migration.xpt
 @RESPATH@/components/mimetype.xpt
 @RESPATH@/components/mozfind.xpt
 @RESPATH@/components/necko_about.xpt
 @RESPATH@/components/necko_cache.xpt
 @RESPATH@/components/necko_cache2.xpt
 @RESPATH@/components/necko_cookie.xpt
 @RESPATH@/components/necko_dns.xpt
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -200,16 +200,19 @@
 @BINPATH@/components/layout_base.xpt
 #ifdef NS_PRINTING
 @BINPATH@/components/layout_printing.xpt
 #endif
 @BINPATH@/components/layout_xul_tree.xpt
 @BINPATH@/components/layout_xul.xpt
 @BINPATH@/components/locale.xpt
 @BINPATH@/components/lwbrk.xpt
+#ifdef MOZ_ENABLE_PROFILER_SPS
+@BINPATH@/components/memory_profiler.xpt
+#endif
 @BINPATH@/components/migration.xpt
 @BINPATH@/components/mimetype.xpt
 @BINPATH@/components/mozfind.xpt
 @BINPATH@/components/necko_about.xpt
 @BINPATH@/components/necko_cache.xpt
 @BINPATH@/components/necko_cache2.xpt
 @BINPATH@/components/necko_cookie.xpt
 @BINPATH@/components/necko_dns.xpt
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -119,16 +119,17 @@ else:
 
 # This must precede xpfe.
 if CONFIG['MOZ_JPROF']:
     DIRS += ['/tools/jprof']
 
 DIRS += [
     '/tools/power',
     '/tools/profiler',
+    '/tools/memory-profiler',
     '/xpfe/components',
 ]
 
 if CONFIG['MOZ_ENABLE_XREMOTE']:
     DIRS += ['/widget/xremoteclient']
 
 if CONFIG['MOZ_SPELLCHECK']:
     DIRS += ['/extensions/spellcheck']
new file mode 100644
--- /dev/null
+++ b/tools/memory-profiler/MemoryProfiler.cpp
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 8; 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 "MemoryProfiler.h"
+#include "nsIDOMClassInfo.h"
+#include "nsIGlobalObject.h"
+#include "js/TypeDecls.h"
+#include "xpcprivate.h"
+
+NS_IMPL_ISUPPORTS(MemoryProfiler, nsIMemoryProfiler)
+
+MemoryProfiler::MemoryProfiler()
+{
+  /* member initializers and constructor code */
+}
+
+MemoryProfiler::~MemoryProfiler()
+{
+  /* destructor code */
+}
+
+NS_IMETHODIMP
+MemoryProfiler::StartProfiler()
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+MemoryProfiler::StopProfiler()
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+MemoryProfiler::ResetProfiler()
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+MemoryProfiler::GetResults(JSContext *cx, JS::MutableHandle<JS::Value> aResult)
+{
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/tools/memory-profiler/MemoryProfiler.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* 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_profiler_MemoryProfiler_h
+#define tools_profiler_MemoryProfiler_h
+
+#include "nsIMemoryProfiler.h"
+
+#include "nsString.h"
+
+#define MEMORY_PROFILER_CID                                     \
+  { 0xf976eaa2, 0xcc1f, 0x47ee,                                 \
+    { 0x81, 0x29, 0xb8, 0x26, 0x2a, 0x3d, 0xb6, 0xb2 } }
+
+#define MEMORY_PROFILER_CONTRACT_ID "@mozilla.org/tools/memory-profiler;1"
+
+class MemoryProfiler : public nsIMemoryProfiler
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIMEMORYPROFILER
+
+  MemoryProfiler();
+
+private:
+  virtual ~MemoryProfiler();
+
+protected:
+  /* additional members */
+};
+
+#endif
new file mode 100644
--- /dev/null
+++ b/tools/memory-profiler/moz.build
@@ -0,0 +1,25 @@
+# -*- Mode: python; c-basic-offset: 4; 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_ENABLE_PROFILER_SPS']:
+    XPIDL_MODULE = 'memory_profiler'
+    XPIDL_SOURCES += [
+        'nsIMemoryProfiler.idl',
+    ]
+
+    # This file cannot be built in unified mode because of name clashes with mozglue headers on Android.
+    SOURCES += [
+        'MemoryProfiler.cpp',
+        'nsMemoryProfilerFactory.cpp',
+    ]
+
+    LOCAL_INCLUDES += [
+        '/js/xpconnect/src',
+        '/xpcom/base',
+    ]
+
+    FINAL_LIBRARY = 'xul'
+
new file mode 100644
--- /dev/null
+++ b/tools/memory-profiler/nsIMemoryProfiler.idl
@@ -0,0 +1,23 @@
+/* -*- Mode: IDL; 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"
+
+[scriptable, uuid(f70db623-3bd5-4719-b8ce-4c6b350a925c)]
+interface nsIMemoryProfiler : nsISupports
+{
+  void startProfiler();
+  void stopProfiler();
+  void resetProfiler();
+
+  // Get results in an object which contains three tables:
+  // {
+  //  names, // an array of function names and positions
+  //  traces, // an array of {nameIdx, parentIdx}
+  //  events, // an array of {size, timestamp, traceIdx}
+  // }
+  [implicit_jscontext]
+  jsval getResults();
+};
new file mode 100644
--- /dev/null
+++ b/tools/memory-profiler/nsMemoryProfilerFactory.cpp
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 20; 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 "mozilla/ModuleUtils.h"
+#include "nsCOMPtr.h"
+#include "MemoryProfiler.h"
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(MemoryProfiler)
+
+NS_DEFINE_NAMED_CID(MEMORY_PROFILER_CID);
+
+static const mozilla::Module::CIDEntry kMemoryProfilerCIDs[] = {
+  { &kMEMORY_PROFILER_CID, false, nullptr, MemoryProfilerConstructor },
+  { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kMemoryProfilerContracts[] = {
+  { MEMORY_PROFILER_CONTRACT_ID, &kMEMORY_PROFILER_CID },
+  { nullptr }
+};
+
+static const mozilla::Module kMemoryProfilerModule = {
+  mozilla::Module::kVersion,
+  kMemoryProfilerCIDs,
+  kMemoryProfilerContracts
+};
+
+NSMODULE_DEFN(nsMemoryProfilerModule) = &kMemoryProfilerModule;