1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * @extends {WebInspector.Object}
8 * @param {!WebInspector.Target} target
10 WebInspector.PowerProfiler = function(target)
12 WebInspector.Object.call(this);
13 this._dispatcher = new WebInspector.PowerDispatcher(this);
14 this._target = target;
15 target.registerPowerDispatcher(this._dispatcher);
16 target.powerAgent().getAccuracyLevel(this._onAccuracyLevel.bind(this));
19 WebInspector.PowerProfiler.EventTypes = {
20 PowerEventRecorded: "PowerEventRecorded"
23 WebInspector.PowerProfiler.prototype = {
24 startProfile: function ()
26 this._target.powerAgent().start();
29 stopProfile: function ()
31 this._target.powerAgent().end();
37 getAccuracyLevel: function()
39 return this._accuracyLevel;
42 _onAccuracyLevel: function(error, result) {
43 this._accuracyLevel = "";
45 console.log("Unable to retrieve PowerProfiler accuracy level: " + error);
48 this._accuracyLevel = result;
51 __proto__: WebInspector.Object.prototype
56 * @implements {PowerAgent.Dispatcher}
58 WebInspector.PowerDispatcher = function(profiler)
60 this._profiler = profiler;
63 WebInspector.PowerDispatcher.prototype = {
64 dataAvailable: function(events)
66 for (var i = 0; i < events.length; ++i)
67 this._profiler.dispatchEventToListeners(WebInspector.PowerProfiler.EventTypes.PowerEventRecorded, events[i]);
72 * @type {!WebInspector.PowerProfiler}
74 WebInspector.powerProfiler;