Skip to content

Commit

Permalink
Add shutdown profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Girard committed Nov 25, 2012
1 parent 34fadfc commit 69d42a0
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions lib/main.js
Expand Up @@ -38,6 +38,9 @@ const {Cc,Ci,Cu} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/ChromeManifestParser.jsm");
Cu.import("resource://services-common/utils.js");
Cu.import("resource://gre/modules/commonjs/promise/core.js");
Cu.import("resource://gre/modules/osfile.jsm")

var FORCE_DEBUG = false;
//var FORCE_DEBUG = true;
Expand Down Expand Up @@ -209,6 +212,22 @@ GCStats.prototype = {
},
};

function ReadAsString(file) {
file = "file://" + file;
var ioService=Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var scriptableStream=Cc["@mozilla.org/scriptableinputstream;1"]
.getService(Ci.nsIScriptableInputStream);

var channel=ioService.newChannel(file,null,null);
var input=channel.open();
scriptableStream.init(input);
var str=scriptableStream.read(input.available());
scriptableStream.close();
input.close();
return str;
}

function Profiler(options, cb) {
this._profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
this._eventObservers = {};
Expand Down Expand Up @@ -568,29 +587,33 @@ function store_profile(callback) {
});
}

function get_profile(progress_callback, finish_callback) {
function get_profile(progress_callback, finish_callback, args) {
function send_profile(profile) {
if (FORCE_DEBUG || prefs.get_pref_bool("profiler.", "debug")) {
DEBUGLOG("PROFILERDEBUG: " + JSON.stringify(profile));
}
if (profile == null) {
progress_callback({progress: 1, action: "Empty profile"});
return;
}
profiler.getSharedLibraryInformation(function(sharedLibraries) {
symbolicateModule.symbolicate(profile, profiler.getPlatform(), sharedLibraries,
progress_callback,
finish_callback,
profiler.getHardwareID());
});
}

if (args.customProfile) {
send_profile(args.customProfile);
return;
}

if (progress_callback != null) {
progress_callback({progress: 0, action: "Retrieving profile"});
}
DEBUGLOG("Get profile");
timers.setTimeout(function() {
function send_profile(profile) {
if (FORCE_DEBUG || prefs.get_pref_bool("profiler.", "debug")) {
DEBUGLOG("PROFILERDEBUG: " + JSON.stringify(profile));
}
if (profile == null) {
progress_callback({progress: 1, action: "Empty profile"});
return;
}
profiler.getSharedLibraryInformation(function(sharedLibraries) {
symbolicateModule.symbolicate(profile, profiler.getPlatform(), sharedLibraries,
progress_callback,
finish_callback,
profiler.getHardwareID());
});
}

var profile;
if (profilerIsActive == false && savedProfileLastStop != null) {
DEBUGLOG("Using last profile");
Expand Down Expand Up @@ -1415,6 +1438,15 @@ let FirefoxAppWrapper = {
} else {
sps_startup();
}

var profilingShutdown = env.get("MOZ_PROFILER_SHUTDOWN") != null || env.get("MOZ_PROFILER_SHUTDOWN") !== "";
if (profilingShutdown) {
var shutdownLog = env.get("MOZ_PROFILER_SHUTDOWN");
var profile = ReadAsString(shutdownLog);
appWrapper.open_cleopatra("desktop", {customProfile:profile});
// TODO Delete the shutdown log?
}

});
});
});
Expand Down Expand Up @@ -1769,7 +1801,7 @@ let FirefoxAppWrapper = {
got_profile_callback(profile);
}
attach.port.emit("getprofile", profile);
});
}, args);
});
attach.port.emit("get_profile_" + profileType, args);
}
Expand Down

0 comments on commit 69d42a0

Please sign in to comment.