Bug 828049 - Remote profiling, r=past

This commit is contained in:
Anton Kovalyov 2013-02-06 12:10:30 -08:00
Родитель 50668ccc45
Коммит 99b56ebf7b
6 изменённых файлов: 97 добавлений и 11 удалений

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

@ -153,7 +153,7 @@ let profilerDefinition = {
tooltip: l10n("profiler.tooltip", profilerStrings),
isTargetSupported: function (target) {
return !target.isRemote;
return true;
},
build: function (frame, target) {

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

@ -22,14 +22,21 @@ XPCOMUtils.defineLazyGetter(this, "DebuggerServer", function () {
* Object acting as a mediator between the ProfilerController and
* DebuggerServer.
*/
function ProfilerConnection() {
function ProfilerConnection(client) {
if (!DebuggerServer.initialized) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
}
let transport = DebuggerServer.connectPipe();
this.client = new DebuggerClient(transport);
this.isRemote = true;
if (!client) {
let transport = DebuggerServer.connectPipe();
client = new DebuggerClient(transport);
this.isRemote = false;
}
this.client = client;
}
ProfilerConnection.prototype = {
@ -44,12 +51,20 @@ ProfilerConnection.prototype = {
connect: function PCn_connect(aCallback) {
let client = this.client;
client.connect(function (aType, aTraits) {
let listTabs = function () {
client.listTabs(function (aResponse) {
this.actor = aResponse.profilerActor;
aCallback();
}.bind(this));
}.bind(this));
}.bind(this);
if (this.isRemote) {
return void listTabs();
}
client.connect(function (aType, aTraits) {
listTabs();
});
},
/**
@ -123,8 +138,14 @@ ProfilerConnection.prototype = {
/**
* Object defining the profiler controller components.
*/
function ProfilerController() {
this.profiler = new ProfilerConnection();
function ProfilerController(target) {
let client;
if (target.isRemote) {
client = target.client;
}
this.profiler = new ProfilerConnection(client);
this._connected = false;
}

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

@ -179,7 +179,7 @@ function ProfilerPanel(frame, toolbox) {
this.window = frame.window;
this.document = frame.document;
this.target = toolbox.target;
this.controller = new ProfilerController();
this.controller = new ProfilerController(this.target);
this.profiles = new Map();
this._uid = 0;

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

@ -14,6 +14,7 @@ MOCHITEST_BROWSER_FILES = \
browser_profiler_run.js \
browser_profiler_controller.js \
browser_profiler_profiles.js \
browser_profiler_remote.js \
head.js \
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,55 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const URL = "data:text/html;charset=utf8,<p>JavaScript Profiler test</p>";
let temp = {};
Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp);
let DebuggerServer = temp.DebuggerServer;
Cu.import("resource://gre/modules/devtools/dbg-client.jsm", temp);
let DebuggerClient = temp.DebuggerClient;
let debuggerSocketConnect = temp.debuggerSocketConnect;
Cu.import("resource:///modules/devtools/ProfilerController.jsm", temp);
let ProfilerController = temp.ProfilerController;
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref(REMOTE_ENABLED, true);
loadTab(URL, function onTabLoad(tab, browser) {
DebuggerServer.init(function () true);
DebuggerServer.addBrowserActors();
is(DebuggerServer._socketConnections, 0);
DebuggerServer.openListener(2929);
is(DebuggerServer._socketConnections, 1);
let transport = debuggerSocketConnect("127.0.0.1", 2929);
let client = new DebuggerClient(transport);
client.connect(function onClientConnect() {
let target = { isRemote: true, client: client };
let controller = new ProfilerController(target);
controller.connect(function onControllerConnect() {
// If this callback is called, this means listTabs call worked.
// Which means that the transport worked. Time to finish up this
// test.
function onShutdown() {
window.removeEventListener("Debugger:Shutdown", onShutdown, true);
transport = client = null;
finish();
}
window.addEventListener("Debugger:Shutdown", onShutdown, true);
client.close(function () {
gBrowser.removeTab(tab);
});
});
});
});
}

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

@ -3,6 +3,7 @@
let temp = {};
const PROFILER_ENABLED = "devtools.profiler.enabled";
const REMOTE_ENABLED = "devtools.debugger.remote-enabled";
Cu.import("resource:///modules/devtools/Target.jsm", temp);
let TargetFactory = temp.TargetFactory;
@ -10,6 +11,15 @@ let TargetFactory = temp.TargetFactory;
Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
let gDevTools = temp.gDevTools;
Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp);
let DebuggerServer = temp.DebuggerServer;
registerCleanupFunction(function () {
Services.prefs.clearUserPref(PROFILER_ENABLED);
Services.prefs.clearUserPref(REMOTE_ENABLED);
DebuggerServer.destroy();
});
function loadTab(url, callback) {
let tab = gBrowser.addTab();
gBrowser.selectedTab = tab;
@ -63,6 +73,5 @@ function tearDown(tab, callback=function(){}) {
}
finish();
Services.prefs.setBoolPref(PROFILER_ENABLED, false);
});
}
}