Bug 1131397 - Add missing functionality to the profiler actor. r=vporof

--HG--
rename : toolkit/devtools/server/tests/unit/test_profiler_close.js => toolkit/devtools/server/tests/unit/test_profiler_getfeatures.js
rename : toolkit/devtools/server/tests/unit/test_profiler_close.js => toolkit/devtools/server/tests/unit/test_profiler_getsharedlibraryinformation.js
This commit is contained in:
Markus Stange 2015-02-10 15:26:08 -05:00
parent 95dad56d90
commit 9c91e5412d
6 changed files with 138 additions and 3 deletions

View File

@ -379,7 +379,8 @@ PerformanceFront.prototype = {
_customProfilerOptions: {
entries: 1000000,
interval: 1,
features: ["js"]
features: ["js"],
threadFilters: ["GeckoMain"]
},
/**

View File

@ -431,7 +431,8 @@ ProfilerFront.prototype = {
_customProfilerOptions: {
entries: 1000000,
interval: 1,
features: ["js"]
features: ["js"],
threadFilters: ["GeckoMain"]
}
};

View File

@ -10,6 +10,7 @@ const DevToolsUtils = require("devtools/toolkit/DevToolsUtils.js");
let DEFAULT_PROFILER_ENTRIES = 1000000;
let DEFAULT_PROFILER_INTERVAL = 1;
let DEFAULT_PROFILER_FEATURES = ["js"];
let DEFAULT_PROFILER_THREADFILTERS = ["GeckoMain"];
/**
* The nsIProfiler is target agnostic and interacts with the whole platform.
@ -46,6 +47,15 @@ ProfilerActor.prototype = {
checkProfilerConsumers();
},
/**
* Returns an array of feature strings, describing the profiler features
* that are available on this platform. Can be called while the profiler
* is stopped.
*/
onGetFeatures: function() {
return { features: nsIProfilerModule.GetFeatures([]) };
},
/**
* Starts the nsIProfiler module. Doing so will discard any samples
* that might have been accumulated so far.
@ -53,13 +63,16 @@ ProfilerActor.prototype = {
* @param number entries [optional]
* @param number interval [optional]
* @param array:string features [optional]
* @param array:string threadFilters [description]
*/
onStartProfiler: function(request = {}) {
nsIProfilerModule.StartProfiler(
(request.entries || DEFAULT_PROFILER_ENTRIES),
(request.interval || DEFAULT_PROFILER_INTERVAL),
(request.features || DEFAULT_PROFILER_FEATURES),
(request.features || DEFAULT_PROFILER_FEATURES).length);
(request.features || DEFAULT_PROFILER_FEATURES).length,
(request.threadFilters || DEFAULT_PROFILER_THREADFILTERS),
(request.threadFilters || DEFAULT_PROFILER_THREADFILTERS).length);
return { started: true };
},
@ -88,6 +101,15 @@ ProfilerActor.prototype = {
return { isActive: isActive, currentTime: elapsedTime };
},
/**
* Returns a stringified JSON object that describes the shared libraries
* which are currently loaded into our process. Can be called while the
* profiler is stopped.
*/
onGetSharedLibraryInformation: function() {
return { sharedLibraryInformation: nsIProfilerModule.getSharedLibraryInformation() };
},
/**
* Returns all the samples accumulated since the profiler was started,
* along with the current time. The data has the following format:
@ -297,11 +319,16 @@ function checkProfilerConsumers() {
/**
* The request types this actor can handle.
* At the moment there are two known users of the Profiler actor:
* the devtools and the Gecko Profiler addon, which uses the debugger
* protocol to get profiles from Fennec.
*/
ProfilerActor.prototype.requestTypes = {
"getFeatures": ProfilerActor.prototype.onGetFeatures,
"startProfiler": ProfilerActor.prototype.onStartProfiler,
"stopProfiler": ProfilerActor.prototype.onStopProfiler,
"isActive": ProfilerActor.prototype.onIsActive,
"getSharedLibraryInformation": ProfilerActor.prototype.onGetSharedLibraryInformation,
"getProfile": ProfilerActor.prototype.onGetProfile,
"registerEventNotifications": ProfilerActor.prototype.onRegisterEventNotifications,
"unregisterEventNotifications": ProfilerActor.prototype.onUnregisterEventNotifications

View File

@ -0,0 +1,47 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests whether the profiler responds to "getFeatures" adequately.
*/
const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
function connect_client(callback)
{
let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect(() => {
client.listTabs(response => {
callback(client, response.profilerActor);
});
});
}
function run_test()
{
DebuggerServer.init();
DebuggerServer.addBrowserActors();
connect_client((client, actor) => {
test_getfeatures(client, actor, () => {
client.close(() => {
do_test_finished();
});
});
});
do_test_pending();
}
function test_getfeatures(client, actor, callback)
{
client.request({ to: actor, type: "getFeatures" }, response => {
do_check_eq(typeof response.features, "object");
do_check_true(response.features.length >= 1);
do_check_eq(typeof response.features[0], "string");
do_check_true(response.features.indexOf("js") != -1);
callback();
});
}

View File

@ -0,0 +1,57 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests whether the profiler responds to "getSharedLibraryInformation" adequately.
*/
const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
function connect_client(callback)
{
let client = new DebuggerClient(DebuggerServer.connectPipe());
client.connect(() => {
client.listTabs(response => {
callback(client, response.profilerActor);
});
});
}
function run_test()
{
DebuggerServer.init();
DebuggerServer.addBrowserActors();
connect_client((client, actor) => {
test_getsharedlibraryinformation(client, actor, () => {
client.close(() => {
do_test_finished();
});
});
});
do_test_pending();
}
function test_getsharedlibraryinformation(client, actor, callback)
{
client.request({ to: actor, type: "getSharedLibraryInformation" }, response => {
do_check_eq(typeof response.sharedLibraryInformation, "string");
let libs = [];
try {
libs = JSON.parse(response.sharedLibraryInformation);
} catch (e) {
do_check_true(false);
}
do_check_eq(typeof libs, "object");
do_check_true(libs.length >= 1);
do_check_eq(typeof libs[0], "object");
do_check_eq(typeof libs[0].name, "string");
do_check_eq(typeof libs[0].start, "number");
do_check_eq(typeof libs[0].end, "number");
do_check_true(libs[0].start <= libs[0].end);
callback();
});
}

View File

@ -201,6 +201,8 @@ reason = bug 820380
[test_profiler_data.js]
[test_profiler_events-01.js]
[test_profiler_events-02.js]
[test_profiler_getfeatures.js]
[test_profiler_getsharedlibraryinformation.js]
[test_unsafeDereference.js]
[test_add_actors.js]
[test_trace_actor-01.js]