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. 4 5/** 6 * @constructor 7 * @extends {WebInspector.Object} 8 * @param {!WebInspector.Target} target 9 */ 10WebInspector.PowerProfiler = function(target) 11{ 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)); 17} 18 19WebInspector.PowerProfiler.EventTypes = { 20 PowerEventRecorded: "PowerEventRecorded" 21} 22 23WebInspector.PowerProfiler.prototype = { 24 startProfile: function () 25 { 26 this._target.powerAgent().start(); 27 }, 28 29 stopProfile: function () 30 { 31 this._target.powerAgent().end(); 32 }, 33 34 /** 35 * @return {string} 36 */ 37 getAccuracyLevel: function() 38 { 39 return this._accuracyLevel; 40 }, 41 42 _onAccuracyLevel: function(error, result) { 43 this._accuracyLevel = ""; 44 if (error) { 45 console.log("Unable to retrieve PowerProfiler accuracy level: " + error); 46 return; 47 } 48 this._accuracyLevel = result; 49 }, 50 51 __proto__: WebInspector.Object.prototype 52} 53 54/** 55 * @constructor 56 * @implements {PowerAgent.Dispatcher} 57 */ 58WebInspector.PowerDispatcher = function(profiler) 59{ 60 this._profiler = profiler; 61} 62 63WebInspector.PowerDispatcher.prototype = { 64 dataAvailable: function(events) 65 { 66 for (var i = 0; i < events.length; ++i) 67 this._profiler.dispatchEventToListeners(WebInspector.PowerProfiler.EventTypes.PowerEventRecorded, events[i]); 68 } 69} 70 71/** 72 * @type {!WebInspector.PowerProfiler} 73 */ 74WebInspector.powerProfiler; 75