Mercurial > hg > config
changeset 198:59d4f04497dd
package into extension for profile, add direct file logging instead of stdout r=vlad
author | Joel Maher <jmaher@mozilla.com> |
---|---|
date | Tue, 05 Oct 2010 17:01:29 -0400 |
parents | b4da709724e1 |
children | eab9ffc922b1 |
files | chrome/MozillaFileLogger.js chrome/pageloader.js chrome/pageloader.xul install.rdf |
diffstat | 4 files changed, 185 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/MozillaFileLogger.js Tue Oct 05 17:01:29 2010 -0400 @@ -0,0 +1,153 @@ +/** + * MozillaFileLogger, a log listener that can write to a local file. + */ + +var ipcMode = false; // running in e10s build and need to use IPC? +try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var ipcsanity = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + ipcsanity.setIntPref("mochitest.ipcmode", 0); +} catch (e) { + ipcMode = true; +} + +function contentDispatchEvent(type, data, sync) { + if (typeof(data) === "undefined") { + data = {}; + } + + var element = document.createEvent("datacontainerevent"); + element.initEvent("contentEvent", true, false); + element.setData("sync", sync); + element.setData("type", type); + element.setData("data", JSON.stringify(data)); + document.dispatchEvent(element); +} + +function contentSyncEvent(type, data) { + contentDispatchEvent(type, data, 1); +} + +function contentAsyncEvent(type, data) { + contentDispatchEvent(type, data, 0); +} + +try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + if (Cc === undefined) { + var Cc = Components.classes; + var Ci = Components.interfaces; + } +} catch (ex) {} //running in ipcMode-chrome + +try { + const FOSTREAM_CID = "@mozilla.org/network/file-output-stream;1"; + const LF_CID = "@mozilla.org/file/local;1"; + + // File status flags. It is a bitwise OR of the following bit flags. + // Only one of the first three flags below may be used. + const PR_READ_ONLY = 0x01; // Open for reading only. + const PR_WRITE_ONLY = 0x02; // Open for writing only. + const PR_READ_WRITE = 0x04; // Open for reading and writing. + + // If the file does not exist, the file is created. + // If the file exists, this flag has no effect. + const PR_CREATE_FILE = 0x08; + + // The file pointer is set to the end of the file prior to each write. + const PR_APPEND = 0x10; + + // If the file exists, its length is truncated to 0. + const PR_TRUNCATE = 0x20; + + // If set, each write will wait for both the file data + // and file status to be physically updated. + const PR_SYNC = 0x40; + + // If the file does not exist, the file is created. If the file already + // exists, no action and NULL is returned. + const PR_EXCL = 0x80; +} catch (ex) { + // probably not running in the test harness +} + +/** Init the file logger with the absolute path to the file. + It will create and append if the file already exists **/ +var MozillaFileLogger = {}; + + +MozillaFileLogger.init = function(path) { + if (ipcMode) { + contentAsyncEvent("LoggerInit", {"filename": path}); + return; + } + + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + } catch (ex) {} //running in ipcMode-chrome + + MozillaFileLogger._file = Cc[LF_CID].createInstance(Ci.nsILocalFile); + MozillaFileLogger._file.initWithPath(path); + MozillaFileLogger._foStream = Cc[FOSTREAM_CID].createInstance(Ci.nsIFileOutputStream); + MozillaFileLogger._foStream.init(this._file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND, + 0664, 0); +} + +MozillaFileLogger.getLogCallback = function() { + if (ipcMode) { + return function(msg) { + contentAsyncEvent("Logger", {"num": msg.num, "level": msg.level, "info": msg.info.join(' ')}); + } + } + + return function (msg) { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + } catch(ex) {} //running in ipcMode-chrome + + var data = msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"; + if (MozillaFileLogger._foStream) + MozillaFileLogger._foStream.write(data, data.length); + + if (data.indexOf("SimpleTest FINISH") >= 0) { + MozillaFileLogger.close(); + } + } +} + +// This is only used from chrome space by the reftest harness +MozillaFileLogger.log = function(msg) { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + if (MozillaFileLogger._foStream) + MozillaFileLogger._foStream.write(msg, msg.length); +} + +MozillaFileLogger.close = function() { + if (ipcMode) { + contentAsyncEvent("LoggerClose"); + return; + } + + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + } catch(ex) {} //running in ipcMode-chrome + + if(MozillaFileLogger._foStream) + MozillaFileLogger._foStream.close(); + + MozillaFileLogger._foStream = null; + MozillaFileLogger._file = null; +} + +if (ipcMode == false) { + try { + var prefs = Components.classes['@mozilla.org/preferences-service;1'] + .getService(Components.interfaces.nsIPrefBranch2); + var filename = prefs.getCharPref('talos.logfile'); + MozillaFileLogger.init(filename); + } catch (ex) {} //pref does not exist, return empty string +} + +
--- a/chrome/pageloader.js Fri Sep 17 11:34:40 2010 -0400 +++ b/chrome/pageloader.js Tue Oct 05 17:01:29 2010 -0400 @@ -37,8 +37,12 @@ * * ***** END LICENSE BLOCK ***** */ -const Cc = Components.classes; -const Ci = Components.interfaces; +try { + if (Cc === undefined) { + var Cc = Components.classes; + var Ci = Components.interfaces; + } +} catch (ex) {} var NUM_CYCLES = 5; @@ -371,6 +375,9 @@ if (content) content.removeEventListener('load', plLoadHandler, true); + if (MozillaFileLogger) + MozillaFileLogger.close(); + goQuitApplication(); } @@ -448,6 +455,8 @@ } function dumpLine(str) { + if (MozillaFileLogger) + MozillaFileLogger.log(str + "\n"); dump(str); dump("\n"); }
--- a/chrome/pageloader.xul Fri Sep 17 11:34:40 2010 -0400 +++ b/chrome/pageloader.xul Tue Oct 05 17:01:29 2010 -0400 @@ -48,6 +48,7 @@ <script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/> + <script type="application/x-javascript" src="MozillaFileLogger.js"></script> <script type="application/x-javascript" src="report.js"></script> <script type="application/x-javascript" src="pageloader.js"></script> <script type="application/x-javascript" src="quit.js"></script>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install.rdf Tue Oct 05 17:01:29 2010 -0400 @@ -0,0 +1,20 @@ +<?xml version="1.0"?> + +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> + <Description about="urn:mozilla:install-manifest"> + <em:id>pageloader@mozilla.org</em:id> + <em:version>1.0</em:version> + <em:targetApplication> + <Description> + <em:id>toolkit@mozilla.org</em:id> + <em:minVersion>2.0b3pre</em:minVersion> + <em:maxVersion>9.0</em:maxVersion> + </Description> + </em:targetApplication> + <!-- Front End MetaData --> + <em:name>PageLoader extension</em:name> + <em:description>Cycles through pages and measures load times</em:description> + <em:creator>Vladimir Vukicevic</em:creator> + </Description> +</RDF>