Bug 1123237 - Part 7. XPCOM interface for memory profiler. r=smaug

Based on patch from Ting-Yuan Huang <laszio.bugzilla@gmail.com>
This commit is contained in:
Kan-Ru Chen 2015-05-08 11:22:38 +08:00
parent 3b13fdd60b
commit c68e2dc6d3
9 changed files with 171 additions and 0 deletions

View File

@ -291,6 +291,9 @@
@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

View File

@ -276,6 +276,9 @@
@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

View File

@ -205,6 +205,9 @@
@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

View File

@ -124,6 +124,7 @@ if CONFIG['MOZ_JPROF']:
DIRS += [
'/tools/power',
'/tools/profiler',
'/tools/memory-profiler',
'/xpfe/components',
]

View File

@ -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;
}

View File

@ -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

View File

@ -0,0 +1,27 @@
# -*- 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']:
FAIL_ON_WARNINGS = True
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'

View File

@ -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();
};

View File

@ -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;