Skip to content

Instantly share code, notes, and snippets.

@azu
Created December 25, 2010 15:21
Show Gist options
  • Save azu/754908 to your computer and use it in GitHub Desktop.
Save azu/754908 to your computer and use it in GitHub Desktop.
メモリ情報をcontentスコープから取得できるように拡張
// ==UserScript==
// @name getMemoryInfo
// @namespace http://efcl.info/
// @description メモリ情報をcontentスコープから取得できるように拡張
// @include main
// ==/UserScript==
var memoryInfo = {
init: function(event) {
let doc = event.originalTarget;
//alert(doc.defaultView.location.href);
if (doc instanceof HTMLDocument) {
var win = doc.defaultView.wrappedJSObject;
if (!win.getMemoryInfo) {
win.getMemoryInfo = memoryInfo.getMemoryInfo;
}
}
},
getMemoryInfo: function() {
var mgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(Ci.nsIMemoryReporterManager);
var e = mgr.enumerateReporters();
var gMemReporters = {};
while (e.hasMoreElements()) {
var mr = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
gMemReporters[mr.path] = mr;
}
var mapped = gMemReporters["malloc/mapped"].memoryUsed;
var allocated = gMemReporters["malloc/allocated"].memoryUsed;
var committed = gMemReporters["malloc/committed"].memoryUsed;
var dirty = gMemReporters["malloc/dirty"].memoryUsed;
return {
"mapped": mapped,
"allocated": allocated,
"committed": committed,
"dirty": dirty
}
}
}
gBrowser.addEventListener("load", memoryInfo.init, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment