tools/footprint/leak-gauge.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
michael@0 2 "http://www.w3.org/TR/html4/strict.dtd">
michael@0 3 <!--
michael@0 4 vim:sw=4:ts=4:et:
michael@0 5 This Source Code Form is subject to the terms of the Mozilla Public
michael@0 6 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 7 - file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 8 -->
michael@0 9 <html lang="en-US">
michael@0 10 <head>
michael@0 11 <title>Leak Gauge</title>
michael@0 12
michael@0 13 <style type="text/css">
michael@0 14 pre { margin: 0; }
michael@0 15 pre.output { border: medium solid; padding: 1em; margin: 1em; }
michael@0 16 </style>
michael@0 17 <script type="text/javascript">
michael@0 18
michael@0 19 function runFile(file) {
michael@0 20 var result = "Results of processing log " + file.fileName + " :\n";
michael@0 21
michael@0 22 var fileReader = new FileReader();
michael@0 23 fileReader.onload = function(e)
michael@0 24 {
michael@0 25 runContents(result, e.target.result);
michael@0 26 }
michael@0 27 fileReader.readAsText(file, "iso-8859-1");
michael@0 28 }
michael@0 29
michael@0 30 function runContents(result, contents) {
michael@0 31 // A hash of objects (keyed by the first word of the line in the log)
michael@0 32 // that have two public methods, handle_line and dump (to be called using
michael@0 33 // call, above), along with any private data they need.
michael@0 34 var handlers = {
michael@0 35 "DOMWINDOW": {
michael@0 36 count: 0,
michael@0 37 windows: {},
michael@0 38 handle_line: function(line) {
michael@0 39 var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
michael@0 40 if (match) {
michael@0 41 var addr = match[1];
michael@0 42 var verb = match[2];
michael@0 43 var rest = match[3];
michael@0 44 if (verb == "created") {
michael@0 45 var m = rest.match(/ outer=([0-9a-f]*)$/);
michael@0 46 if (!m)
michael@0 47 throw "outer expected";
michael@0 48 this.windows[addr] = { outer: m[1] };
michael@0 49 ++this.count;
michael@0 50 } else if (verb == "destroyed") {
michael@0 51 delete this.windows[addr];
michael@0 52 } else if (verb == "SetNewDocument") {
michael@0 53 var m = rest.match(/^ (.*)$/);
michael@0 54 if (!m)
michael@0 55 throw "URI expected";
michael@0 56 this.windows[addr][m[1]] = true;
michael@0 57 }
michael@0 58 }
michael@0 59 },
michael@0 60 dump: function() {
michael@0 61 for (var addr in this.windows) {
michael@0 62 var winobj = this.windows[addr];
michael@0 63 var outer = winobj.outer;
michael@0 64 delete winobj.outer;
michael@0 65 result += "Leaked " + (outer == "0" ? "outer" : "inner") +
michael@0 66 " window " + addr + " " +
michael@0 67 (outer == "0" ? "" : "(outer " + outer + ") ") +
michael@0 68 "at address " + addr + ".\n";
michael@0 69 for (var uri in winobj) {
michael@0 70 result += " ... with URI \"" + uri + "\".\n";
michael@0 71 }
michael@0 72 }
michael@0 73 },
michael@0 74 summary: function() {
michael@0 75 var len = 0;
michael@0 76 for (var w in this.windows)
michael@0 77 ++len;
michael@0 78 result += 'Leaked ' + len + ' out of ' +
michael@0 79 this.count + " DOM Windows\n";
michael@0 80 }
michael@0 81 },
michael@0 82 "DOCUMENT": {
michael@0 83 count: 0,
michael@0 84 docs: {},
michael@0 85 handle_line: function(line) {
michael@0 86 var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
michael@0 87 if (match) {
michael@0 88 var addr = match[1];
michael@0 89 var verb = match[2];
michael@0 90 var rest = match[3];
michael@0 91 if (verb == "created") {
michael@0 92 this.docs[addr] = {};
michael@0 93 ++this.count;
michael@0 94 } else if (verb == "destroyed") {
michael@0 95 delete this.docs[addr];
michael@0 96 } else if (verb == "ResetToURI" ||
michael@0 97 verb == "StartDocumentLoad") {
michael@0 98 var m = rest.match(/^ (.*)$/);
michael@0 99 if (!m)
michael@0 100 throw "URI expected";
michael@0 101 var uri = m[1];
michael@0 102 var doc_info = this.docs[addr];
michael@0 103 doc_info[uri] = true;
michael@0 104 if ("nim" in doc_info) {
michael@0 105 doc_info["nim"][uri] = true;
michael@0 106 }
michael@0 107 }
michael@0 108 }
michael@0 109 },
michael@0 110 dump: function() {
michael@0 111 for (var addr in this.docs) {
michael@0 112 var doc = this.docs[addr];
michael@0 113 result += "Leaked document at address " + addr + ".\n";
michael@0 114 for (var uri in doc) {
michael@0 115 if (uri != "nim") {
michael@0 116 result += " ... with URI \"" + uri + "\".\n";
michael@0 117 }
michael@0 118 }
michael@0 119 }
michael@0 120 },
michael@0 121 summary: function() {
michael@0 122 var len = 0;
michael@0 123 for (var w in this.docs)
michael@0 124 ++len;
michael@0 125 result += 'Leaked ' + len + ' out of ' +
michael@0 126 this.count + " documents\n";
michael@0 127 }
michael@0 128 },
michael@0 129 "DOCSHELL": {
michael@0 130 count: 0,
michael@0 131 shells: {},
michael@0 132 handle_line: function(line) {
michael@0 133 var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
michael@0 134 if (match) {
michael@0 135 var addr = match[1];
michael@0 136 var verb = match[2];
michael@0 137 var rest = match[3];
michael@0 138 if (verb == "created") {
michael@0 139 this.shells[addr] = {};
michael@0 140 ++this.count;
michael@0 141 } else if (verb == "destroyed") {
michael@0 142 delete this.shells[addr];
michael@0 143 } else if (verb == "InternalLoad" ||
michael@0 144 verb == "SetCurrentURI") {
michael@0 145 var m = rest.match(/^ (.*)$/);
michael@0 146 if (!m)
michael@0 147 throw "URI expected";
michael@0 148 this.shells[addr][m[1]] = true;
michael@0 149 }
michael@0 150 }
michael@0 151 },
michael@0 152 dump: function() {
michael@0 153 for (var addr in this.shells) {
michael@0 154 var doc = this.shells[addr];
michael@0 155 result += "Leaked docshell at address " + addr + ".\n";
michael@0 156 for (var uri in doc) {
michael@0 157 result += " ... which loaded URI \"" + uri + "\".\n";
michael@0 158 }
michael@0 159 }
michael@0 160 },
michael@0 161 summary: function() {
michael@0 162 var len = 0;
michael@0 163 for (var w in this.shells)
michael@0 164 ++len;
michael@0 165 result += 'Leaked ' + len + ' out of ' +
michael@0 166 this.count + " docshells\n";
michael@0 167 }
michael@0 168 },
michael@0 169 "NODEINFOMANAGER": {
michael@0 170 count: 0,
michael@0 171 nims: {},
michael@0 172 handle_line: function(line) {
michael@0 173 var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
michael@0 174 if (match) {
michael@0 175 var addr = match[1];
michael@0 176 var verb = match[2];
michael@0 177 var rest = match[3];
michael@0 178 if (verb == "created") {
michael@0 179 this.nims[addr] = {};
michael@0 180 ++this.count;
michael@0 181 } else if (verb == "destroyed") {
michael@0 182 delete this.nims[addr];
michael@0 183 } else if (verb == "Init") {
michael@0 184 var m = rest.match(/^ document=(.*)$/);
michael@0 185 if (!m)
michael@0 186 throw "document pointer expected";
michael@0 187 var nim_info = this.nims[addr];
michael@0 188 var doc = m[1];
michael@0 189 if (doc != "0") {
michael@0 190 var doc_info = handlers["DOCUMENT"].docs[doc];
michael@0 191 for (var uri in doc_info) {
michael@0 192 nim_info[uri] = true;
michael@0 193 }
michael@0 194 doc_info["nim"] = nim_info;
michael@0 195 }
michael@0 196 }
michael@0 197 }
michael@0 198 },
michael@0 199 dump: function() {
michael@0 200 for (var addr in this.nims) {
michael@0 201 var nim = this.nims[addr];
michael@0 202 result += "Leaked content nodes associated with node info manager at address " + addr + ".\n";
michael@0 203 for (var uri in nim) {
michael@0 204 result += " ... with document URI \"" + uri + "\".\n";
michael@0 205 }
michael@0 206 }
michael@0 207 },
michael@0 208 summary: function() {
michael@0 209 var len = 0;
michael@0 210 for (var w in this.nims)
michael@0 211 ++len;
michael@0 212 result += 'Leaked content nodes in ' + len + ' out of ' +
michael@0 213 this.count + " documents\n";
michael@0 214 }
michael@0 215 }
michael@0 216 };
michael@0 217
michael@0 218 var lines = contents.split(/[\r\n]+/);
michael@0 219 for (var j in lines) {
michael@0 220 var line = lines[j];
michael@0 221 // strip off initial "-", thread id, and thread pointer; separate
michael@0 222 // first word and rest
michael@0 223 var matches = line.match(/^\-?[0-9]*\[[0-9a-f]*\]: (\S*) (.*)$/);
michael@0 224 if (matches) {
michael@0 225 var handler = matches[1];
michael@0 226 var data = matches[2];
michael@0 227 if (typeof(handlers[handler]) != "undefined") {
michael@0 228 handlers[handler].handle_line(data);
michael@0 229 }
michael@0 230 }
michael@0 231 }
michael@0 232
michael@0 233 for (var handler in handlers)
michael@0 234 handlers[handler].dump();
michael@0 235 if (result.length)
michael@0 236 result += "\n";
michael@0 237 result += "Summary:\n";
michael@0 238 for (var handler in handlers)
michael@0 239 handlers[handler].summary();
michael@0 240 result += "\n";
michael@0 241
michael@0 242 var out = document.createElement("pre");
michael@0 243 out.className = "output";
michael@0 244 out.appendChild(document.createTextNode(result));
michael@0 245 document.body.appendChild(out);
michael@0 246 }
michael@0 247
michael@0 248 function run() {
michael@0 249 var input = document.getElementById("fileinput");
michael@0 250 var files = input.files;
michael@0 251 for (var i = 0; i < files.length; ++i)
michael@0 252 runfile(files[i]);
michael@0 253 // So the user can process the same filename again (after
michael@0 254 // overwriting the log), clear the value on the form input so we
michael@0 255 // will always get an onchange event.
michael@0 256 input.value = "";
michael@0 257 }
michael@0 258
michael@0 259 </script>
michael@0 260 </head>
michael@0 261 <body>
michael@0 262
michael@0 263 <h1>Leak Gauge</h1>
michael@0 264
michael@0 265 <pre>$Id: leak-gauge.html,v 1.8 2008/02/08 19:55:34 dbaron%dbaron.org Exp $</pre>
michael@0 266
michael@0 267 <p>This script is designed to help testers isolate and simplify testcases
michael@0 268 for many classes of leaks (those that involve large graphs of core
michael@0 269 data structures) in Mozilla-based browsers. It is designed to print
michael@0 270 information about what has leaked by processing a log taken while
michael@0 271 running the browser. Such a log can be taken over a long session of
michael@0 272 normal browsing and then the log can be processed to find sites that
michael@0 273 leak. Once a site is known to leak, the logging can then be repeated
michael@0 274 to figure out under what conditions the leak occurs.</p>
michael@0 275
michael@0 276 <p>The way to create this log is to set the environment variables:</p>
michael@0 277 <pre> NSPR_LOG_MODULES=DOMLeak:5,DocumentLeak:5,nsDocShellLeak:5,NodeInfoManagerLeak:5
michael@0 278 NSPR_LOG_FILE=nspr.log <i>(or any other filename of your choice)</i></pre>
michael@0 279 <p>in your shell and then run the program.</p>
michael@0 280 <ul>
michael@0 281 <li>In a Windows command prompt, set environment variables with
michael@0 282 <pre> set VAR=value</pre></li>
michael@0 283 <li> In an sh-based shell such as bash, set environment variables with
michael@0 284 <pre> export VAR=value</pre></li>
michael@0 285 <li>In a csh-based shell such as tcsh, set environment variables with
michael@0 286 <pre> setenv VAR value</pre></li>
michael@0 287 </ul>
michael@0 288
michael@0 289 <p>Once you have this log from a complete run of the browser (you have
michael@0 290 to exit; otherwise it will look like everything leaked), you can load
michael@0 291 this page (be careful not to overwrite the log when starting the browser
michael@0 292 to load this page) and enter the filename of the log:</p>
michael@0 293
michael@0 294 <p><input type="file" id="fileinput" onchange="run()"></p>
michael@0 295
michael@0 296 <p>Then you'll see the output below, which will tell you which of
michael@0 297 certain core objects leaked and the URLs associated with those
michael@0 298 objects.</p>
michael@0 299
michael@0 300 </body>
michael@0 301 </html>

mercurial