b=515354; Implement "about:memory"; r=mconnor

This commit is contained in:
Vladimir Vukicevic 2009-10-03 00:21:34 -07:00
Родитель 5c4d79cf3b
Коммит 5312541472
13 изменённых файлов: 579 добавлений и 6 удалений

Просмотреть файл

@ -83,6 +83,8 @@ static RedirEntry kRedirMap[] = {
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
{ "neterror", "chrome://global/content/netError.xhtml",
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
nsIAboutModule::ALLOW_SCRIPT },
{ "memory", "chrome://global/content/aboutMemory.xhtml",
nsIAboutModule::ALLOW_SCRIPT }
};
static const int kRedirTotal = NS_ARRAY_LENGTH(kRedirMap);

Просмотреть файл

@ -204,6 +204,11 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = {
NS_ABOUT_MODULE_CONTRACTID_PREFIX "neterror",
nsAboutRedirector::Create
},
{ "about:memory",
NS_ABOUT_REDIRECTOR_MODULE_CID,
NS_ABOUT_MODULE_CONTRACTID_PREFIX "memory",
nsAboutRedirector::Create
},
// uriloader
{ "Netscape URI Loader Service", NS_URI_LOADER_CID, NS_URI_LOADER_CONTRACTID, nsURILoaderConstructor, },

Просмотреть файл

@ -62,6 +62,7 @@ DIRS += \
typeaheadfind \
parentalcontrols \
passwordmgr \
aboutmemory \
$(NULL)
ifneq (,$(filter cocoa, $(MOZ_WIDGET_TOOLKIT)))

Просмотреть файл

@ -0,0 +1,46 @@
# ***** 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 the Mozilla Password Manager code.
#
# The Initial Developer of the Original Code is
# Brian Ryner.
# Portions created by the Initial Developer are Copyright (C) 2003
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Brian Ryner <bryner@brianryner.com>
# Justin Dolske <dolske@mozilla.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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,79 @@
/* ***** 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 about:memory.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.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 ***** */
html {
background: -moz-dialog;
}
body {
margin: 0;
padding: 0 1em;
color: -moz-FieldText;
font: message-box;
}
h1 {
font-weight: bold;
font-size: x-large;
}
label {
-moz-user-select: text;
}
h2 {
margin-top: 0;
font-weight: bold;
font-size: large;
}
.memBox {
max-width: 30em;
background: white;
margin-top: 25px;
padding: 5px;
border: 1px solid black;
-moz-border-radius: 10px 10px;
}
.memValue {
text-align: right;
}
.memOverview table {
font-size: 120%;
}

Просмотреть файл

@ -0,0 +1,170 @@
/* -*- Mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* ***** 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 about:memory
*
* The Initial Developer of the Original Code is
* Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.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 ***** */
var gMemReporters = { };
function $(n) {
return document.getElementById(n);
}
function makeTableCell(s, c) {
var td = document.createElement("td");
var text = document.createTextNode(s);
td.appendChild(text);
if (c)
td.setAttribute("class", c);
return td;
}
function makeAbbrNode(str, title) {
var abbr = document.createElement("abbr");
var text = document.createTextNode(str);
abbr.appendChild(text);
abbr.setAttribute("title", title);
return abbr;
}
function makeTableRow() {
var row = document.createElement("tr");
for (var i = 0; i < arguments.length; ++i) {
var arg = arguments[i];
if (typeof(arg) == "string") {
row.appendChild(makeTableCell(arg));
} else if (arg.__proto__ == Array.prototype) {
row.appendChild(makeAbbrNode(arg[0], arg[1]));
} else {
row.appendChild(arg);
}
}
return row;
}
function setTextContent(node, s) {
while (node.lastChild)
node.removeChild(node.lastChild);
node.appendChild(document.createTextNode(s));
}
function formatNumber(n) {
var s = "";
var neg = false;
if (n < 0) {
neg = true;
n = -n;
}
do {
var k = n % 1000;
if (n > 999) {
if (k > 99)
s = k + s;
else if (k > 9)
s = "0" + k + s;
else
s = "00" + k + s;
} else {
s = k + s;
}
n = Math.floor(n / 1000);
if (n > 0)
s = "," + s;
} while (n > 0);
return s;
}
function updateMemoryStatus()
{
// if we have the standard reporters for mapped/allocated, put
// those at the top
if ("malloc/mapped" in gMemReporters &&
"malloc/allocated" in gMemReporters)
{
// committed is the total amount of memory that we've touched, that is that we have
// some kind of backing store for
setTextContent($("memMappedValue"),
formatNumber(gMemReporters["malloc/mapped"].memoryUsed));
// allocated is the amount of committed memory that we're actively using (i.e., that isn't free)
setTextContent($("memInUseValue"),
formatNumber(gMemReporters["malloc/allocated"].memoryUsed));
} else {
$("memOverview").style.display = "none";
}
var mo = $("memOtherRows");
while (mo.lastChild)
mo.removeChild(mo.lastChild);
var otherCount = 0;
for each (var rep in gMemReporters) {
var row = makeTableRow([rep.path, rep.description],
makeTableCell(formatNumber(rep.memoryUsed), "memValue"));
mo.appendChild(row);
otherCount++;
}
if (otherCount == 0) {
var row = makeTableRow("No other information available.");
mo.appendChild(row);
}
}
function doLoad()
{
var mgr = Components
.classes["@mozilla.org/memory-reporter-manager;1"]
.getService(Components.interfaces.nsIMemoryReporterManager);
var e = mgr.enumerateReporters();
while (e.hasMoreElements()) {
var mr = e.getNext().QueryInterface(Components.interfaces.nsIMemoryReporter);
gMemReporters[mr.path] = mr;
}
updateMemoryStatus();
}

Просмотреть файл

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<!-- ***** 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 about:memory.
-
- The Initial Developer of the Original Code is
- Mozilla Corp
- Portions created by the Initial Developer are Copyright (C) 2009
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Vladimir Vukicevic <vladimir@pobox.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 LGPL or the GPL. 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 ***** -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>about:memory</title>
<link rel="stylesheet" href="chrome://global/content/aboutMemory.css" type="text/css"/>
<script type="text/javascript" src="chrome://global/content/aboutMemory.js"/>
</head>
<body onload="doLoad()">
<h1>Memory Usage</h1>
<div id="memOverview" class="memOverview memBox">
<h2>Overview</h2>
<table border="0">
<tbody>
<tr><td width="100%">Memory mapped:</td><td id="memMappedValue" class="memValue"></td></tr>
<tr><td>Memory in use:</td><td id="memInUseValue" class="memValue"></td></tr>
</tbody>
</table>
</div>
<div id="memOther" class="memOther memBox">
<h2>Other Information</h2>
<table border="0">
<thead>
<tr><th style="text-align: left" width="100%">Description</th><th>Value</th></tr>
</thead>
<tbody id="memOtherRows">
</tbody>
</table>
</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,4 @@
toolkit.jar:
+ content/global/aboutMemory.js (content/aboutMemory.js)
+ content/global/aboutMemory.xhtml (content/aboutMemory.xhtml)
+ content/global/aboutMemory.css (content/aboutMemory.css)

Просмотреть файл

@ -82,6 +82,11 @@ interface nsIMemoryReporterManager : nsISupports
* Unregister the given memory reporter.
*/
void unregisterReporter (in nsIMemoryReporter reporter);
/*
* Initialize.
*/
void init ();
};
%{C++

Просмотреть файл

@ -1,3 +1,40 @@
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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
* mozilla.org
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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
* 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 ***** */
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
@ -5,8 +42,159 @@
#include "nsArrayEnumerator.h"
/**
** memory reporter implementation for jemalloc and OSX malloc,
** to obtain info on total memory in use (that we know about,
** at least -- on OSX, there are sometimes other zones in use).
**/
/* Because of the way that jemalloc is linked on linux, we can't
* get to jemalloc_stats(). So just do this on Windows until
* that's fixed.
*/
#if defined(MOZ_MEMORY) && defined(XP_WIN)
#define HAVE_JEMALLOC_STATS 1
#else
#undef HAVE_JEMALLOC_STATS
#endif
#if defined(HAVE_JEMALLOC_STATS)
#define HAVE_MALLOC_REPORTERS 1
#include "jemalloc.h"
PRInt64 getMallocMapped(void *) {
jemalloc_stats_t stats;
jemalloc_stats(&stats);
return (PRInt64) stats.mapped;
}
PRInt64 getMallocAllocated(void *) {
jemalloc_stats_t stats;
jemalloc_stats(&stats);
return (PRInt64) stats.allocated;
}
PRInt64 getMallocCommitted(void *) {
jemalloc_stats_t stats;
jemalloc_stats(&stats);
return (PRInt64) stats.committed;
}
PRInt64 getMallocDirty(void *) {
jemalloc_stats_t stats;
jemalloc_stats(&stats);
return (PRInt64) stats.dirty;
}
#elif defined(XP_MACOSX) && !defined(MOZ_MEMORY)
#define HAVE_MALLOC_REPORTERS 1
#include <malloc/malloc.h>
static PRInt64 getMallocAllocated(void *) {
struct mstats stats = mstats();
return (PRInt64) stats.bytes_used;
}
static PRInt64 getMallocMapped(void *) {
struct mstats stats = mstats();
return (PRInt64) stats.bytes_total;
}
static PRInt64 getMallocDefaultCommitted(void *) {
malloc_statistics_t stats;
malloc_zone_statistics(malloc_default_zone(), &stats);
return stats.size_in_use;
}
static PRInt64 getMallocDefaultAllocated(void *) {
malloc_statistics_t stats;
malloc_zone_statistics(malloc_default_zone(), &stats);
return stats.size_allocated;
}
#endif
#ifdef HAVE_MALLOC_REPORTERS
NS_MEMORY_REPORTER_IMPLEMENT(MallocAllocated,
"malloc/allocated",
"Malloc bytes allocated (in use by application)",
getMallocAllocated,
NULL)
NS_MEMORY_REPORTER_IMPLEMENT(MallocMapped,
"malloc/mapped",
"Malloc bytes mapped (not necessarily committed)",
getMallocMapped,
NULL)
#if defined(HAVE_JEMALLOC_STATS)
NS_MEMORY_REPORTER_IMPLEMENT(MallocCommitted,
"malloc/committed",
"Malloc bytes commited (readable/writable)",
getMallocCommitted,
NULL)
NS_MEMORY_REPORTER_IMPLEMENT(MallocDirty,
"malloc/dirty",
"Malloc bytes dirty (committed unused pages)",
getMallocDirty,
NULL)
#elif defined(XP_MACOSX) && !defined(MOZ_MEMORY)
NS_MEMORY_REPORTER_IMPLEMENT(MallocDefaultCommitted,
"malloc/zone0/committed",
"Malloc bytes commited (r/w) in default zone",
getMallocDefaultCommitted,
NULL)
NS_MEMORY_REPORTER_IMPLEMENT(MallocDefaultAllocated,
"malloc/zone0/allocated",
"Malloc bytes allocated (in use) in default zone",
getMallocDefaultAllocated,
NULL)
#endif
#endif
/**
** nsMemoryReporterManager implementation
**/
NS_IMPL_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
NS_IMETHODIMP
nsMemoryReporterManager::Init()
{
nsCOMPtr<nsIMemoryReporter> mr;
/*
* Register our core jemalloc/malloc reporters
*/
#ifdef HAVE_MALLOC_REPORTERS
mr = new NS_MEMORY_REPORTER_NAME(MallocAllocated);
RegisterReporter(mr);
mr = new NS_MEMORY_REPORTER_NAME(MallocMapped);
RegisterReporter(mr);
#if defined(HAVE_JEMALLOC_STATS)
mr = new NS_MEMORY_REPORTER_NAME(MallocCommitted);
RegisterReporter(mr);
mr = new NS_MEMORY_REPORTER_NAME(MallocDirty);
RegisterReporter(mr);
#elif defined(XP_MACOSX) && !defined(MOZ_MEMORY)
mr = new NS_MEMORY_REPORTER_NAME(MallocDefaultCommitted);
RegisterReporter(mr);
mr = new NS_MEMORY_REPORTER_NAME(MallocDefaultAllocated);
RegisterReporter(mr);
#endif
#endif
return NS_OK;
}
NS_IMETHODIMP
nsMemoryReporterManager::EnumerateReporters(nsISimpleEnumerator **result)
{

Просмотреть файл

@ -97,6 +97,11 @@
*/
#define NS_IOUTIL_CONTRACTID "@mozilla.org/io-util;1"
/**
* Memory reporter service CID
*/
#define NS_MEMORY_REPORTER_MANAGER_CONTRACTID "@mozilla.org/memory-reporter-manager;1"
/**
* The following are the CIDs and Contract IDs of the nsISupports wrappers for
* primative types.

Просмотреть файл

@ -77,11 +77,6 @@
*/
#define NS_XPCOMPROXY_CONTRACTID "@mozilla.org/xpcomproxy;1"
/**
* Memory reporter service CID
*/
#define NS_MEMORY_REPORTER_MANAGER_CONTRACTID "@mozilla.org/memory-reporter-manager;1"
/**
* The contract id for the nsIXULAppInfo service.
*/

Просмотреть файл

@ -232,7 +232,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacUtilsImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMemoryReporterManager)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil)