Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @implements {WebInspector.TargetManager.Observer} | 5 * @implements {WebInspector.TargetManager.Observer} |
| 6 * @implements {WebInspector.TracingManagerClient} | 6 * @implements {WebInspector.TracingManagerClient} |
| 7 * @unrestricted | 7 * @unrestricted |
| 8 */ | 8 */ |
| 9 WebInspector.TimelineController = class { | 9 WebInspector.TimelineController = class { |
| 10 /** | 10 /** |
| 11 * @param {!WebInspector.Target} target | 11 * @param {!WebInspector.Target} target |
| 12 * @param {!WebInspector.TimelineLifecycleDelegate} delegate | 12 * @param {!WebInspector.TimelineLifecycleDelegate} delegate |
| 13 * @param {!WebInspector.TracingModel} tracingModel | 13 * @param {!WebInspector.TracingModel} tracingModel |
| 14 */ | 14 */ |
| 15 constructor(target, delegate, tracingModel) { | 15 constructor(target, delegate, tracingModel) { |
| 16 this._delegate = delegate; | 16 this._delegate = delegate; |
| 17 this._target = target; | 17 this._target = target; |
| 18 this._tracingModel = tracingModel; | 18 this._tracingModel = tracingModel; |
| 19 this._targets = []; | 19 this._targets = []; |
| 20 WebInspector.targetManager.observeTargets(this); | 20 WebInspector.targetManager.observeTargets(this); |
| 21 | |
| 22 if (Runtime.experiments.isEnabled('timelineRuleUsageRecording')) | |
| 23 this._markUnusedCSS = WebInspector.settings.createSetting('timelineMarkUnu sedCSS', false); | |
| 21 } | 24 } |
| 22 | 25 |
| 23 /** | 26 /** |
| 24 * @param {boolean} captureCauses | 27 * @param {boolean} captureCauses |
| 25 * @param {boolean} enableJSSampling | 28 * @param {boolean} enableJSSampling |
| 26 * @param {boolean} captureMemory | 29 * @param {boolean} captureMemory |
| 27 * @param {boolean} capturePictures | 30 * @param {boolean} capturePictures |
| 28 * @param {boolean} captureFilmStrip | 31 * @param {boolean} captureFilmStrip |
| 29 */ | 32 */ |
| 30 startRecording(captureCauses, enableJSSampling, captureMemory, capturePictures , captureFilmStrip) { | 33 startRecording(captureCauses, enableJSSampling, captureMemory, capturePictures , captureFilmStrip) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 70 |
| 68 var categories = categoriesArray.join(','); | 71 var categories = categoriesArray.join(','); |
| 69 this._startRecordingWithCategories(categories, enableJSSampling); | 72 this._startRecordingWithCategories(categories, enableJSSampling); |
| 70 } | 73 } |
| 71 | 74 |
| 72 stopRecording() { | 75 stopRecording() { |
| 73 var tracingStoppedPromises = []; | 76 var tracingStoppedPromises = []; |
| 74 tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCall back = resolve)); | 77 tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCall back = resolve)); |
| 75 tracingStoppedPromises.push(this._stopProfilingOnAllTargets()); | 78 tracingStoppedPromises.push(this._stopProfilingOnAllTargets()); |
| 76 this._target.tracingManager.stop(); | 79 this._target.tracingManager.stop(); |
| 77 tracingStoppedPromises.push(WebInspector.targetManager.resumeAllTargets()); | 80 |
| 81 if (!Runtime.experiments.isEnabled('timelineRuleUsageRecording') || !this._m arkUnusedCSS.get()) | |
| 82 tracingStoppedPromises.push(WebInspector.targetManager.resumeAllTargets()) ; | |
| 83 else | |
| 84 this._addUnusedRulesToCoverage(); | |
| 85 | |
| 78 Promise.all(tracingStoppedPromises).then(() => this._allSourcesFinished()); | 86 Promise.all(tracingStoppedPromises).then(() => this._allSourcesFinished()); |
| 79 | 87 |
| 80 this._delegate.loadingStarted(); | 88 this._delegate.loadingStarted(); |
| 81 | 89 |
| 82 for (var traceProvider of this._extensionTraceProviders) | 90 for (var traceProvider of this._extensionTraceProviders) |
| 83 traceProvider.stop(); | 91 traceProvider.stop(); |
| 84 } | 92 } |
| 85 | 93 |
| 86 /** | 94 /** |
| 87 * @override | 95 * @override |
| 88 * @param {!WebInspector.Target} target | 96 * @param {!WebInspector.Target} target |
| 89 */ | 97 */ |
| 90 targetAdded(target) { | 98 targetAdded(target) { |
| 91 this._targets.push(target); | 99 this._targets.push(target); |
| 92 if (this._profiling) | 100 if (this._profiling) |
| 93 this._startProfilingOnTarget(target); | 101 this._startProfilingOnTarget(target); |
| 94 } | 102 } |
| 95 | 103 |
| 96 /** | 104 /** |
| 97 * @override | 105 * @override |
| 98 * @param {!WebInspector.Target} target | 106 * @param {!WebInspector.Target} target |
| 99 */ | 107 */ |
| 100 targetRemoved(target) { | 108 targetRemoved(target) { |
| 101 this._targets.remove(target, true); | 109 this._targets.remove(target, true); |
| 102 // FIXME: We'd like to stop profiling on the target and retrieve a profile | 110 // FIXME: We'd like to stop profiling on the target and retrieve a profile |
| 103 // but it's too late. Backend connection is closed. | 111 // but it's too late. Backend connection is closed. |
| 104 } | 112 } |
| 105 | 113 |
| 114 _addUnusedRulesToCoverage() { | |
| 115 var mainTarget = WebInspector.targetManager.mainTarget(); | |
| 116 if (!mainTarget) | |
| 117 return; | |
| 118 var cssModel = WebInspector.CSSModel.fromTarget(mainTarget); | |
| 119 | |
| 120 function ruleListReceived(ruleUsageList) { | |
|
caseq
2016/11/09 18:25:30
please annotate ruleUsageList
| |
| 121 | |
| 122 for (var rule of ruleUsageList) { | |
| 123 if (rule.wasUsed) | |
| 124 continue; | |
| 125 | |
| 126 var styleSheetHeader = cssModel.styleSheetHeaderForId(rule.styleSheetId) ; | |
| 127 var url = styleSheetHeader.sourceURL; | |
| 128 | |
| 129 WebInspector.CoverageProfile.instance().appendUnusedRule(url, rule.range ); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 cssModel.ruleListPromise().then(ruleListReceived); | |
| 134 } | |
| 135 | |
| 106 /** | 136 /** |
| 107 * @param {!WebInspector.Target} target | 137 * @param {!WebInspector.Target} target |
| 108 * @return {!Promise} | 138 * @return {!Promise} |
| 109 */ | 139 */ |
| 110 _startProfilingOnTarget(target) { | 140 _startProfilingOnTarget(target) { |
| 111 return target.hasJSCapability() ? target.profilerAgent().start() : Promise.r esolve(); | 141 return target.hasJSCapability() ? target.profilerAgent().start() : Promise.r esolve(); |
| 112 } | 142 } |
| 113 | 143 |
| 114 /** | 144 /** |
| 115 * @return {!Promise} | 145 * @return {!Promise} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 this._profiling = false; | 183 this._profiling = false; |
| 154 return Promise.all(targets.map(this._stopProfilingOnTarget, this)); | 184 return Promise.all(targets.map(this._stopProfilingOnTarget, this)); |
| 155 } | 185 } |
| 156 | 186 |
| 157 /** | 187 /** |
| 158 * @param {string} categories | 188 * @param {string} categories |
| 159 * @param {boolean=} enableJSSampling | 189 * @param {boolean=} enableJSSampling |
| 160 * @param {function(?string)=} callback | 190 * @param {function(?string)=} callback |
| 161 */ | 191 */ |
| 162 _startRecordingWithCategories(categories, enableJSSampling, callback) { | 192 _startRecordingWithCategories(categories, enableJSSampling, callback) { |
| 163 WebInspector.targetManager.suspendAllTargets(); | 193 |
| 194 if (!Runtime.experiments.isEnabled('timelineRuleUsageRecording') || !this._m arkUnusedCSS.get()) | |
| 195 WebInspector.targetManager.suspendAllTargets(); | |
| 196 | |
| 164 var profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEna bled('timelineTracingJSProfile') ? | 197 var profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEna bled('timelineTracingJSProfile') ? |
| 165 this._startProfilingOnAllTargets() : | 198 this._startProfilingOnAllTargets() : |
| 166 Promise.resolve(); | 199 Promise.resolve(); |
| 167 var samplingFrequencyHz = WebInspector.moduleSetting('highResolutionCpuProfi ling').get() ? 10000 : 1000; | 200 var samplingFrequencyHz = WebInspector.moduleSetting('highResolutionCpuProfi ling').get() ? 10000 : 1000; |
| 168 var options = 'sampling-frequency=' + samplingFrequencyHz; | 201 var options = 'sampling-frequency=' + samplingFrequencyHz; |
| 169 var target = this._target; | 202 var target = this._target; |
| 170 var tracingManager = target.tracingManager; | 203 var tracingManager = target.tracingManager; |
| 171 WebInspector.targetManager.suspendReload(target); | 204 WebInspector.targetManager.suspendReload(target); |
| 172 profilingStartedPromise.then(tracingManager.start.bind(tracingManager, this, categories, options, onTraceStarted)); | 205 profilingStartedPromise.then(tracingManager.start.bind(tracingManager, this, categories, options, onTraceStarted)); |
| 173 /** | 206 /** |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 299 } |
| 267 | 300 |
| 268 /** | 301 /** |
| 269 * @param {number} progress | 302 * @param {number} progress |
| 270 * @override | 303 * @override |
| 271 */ | 304 */ |
| 272 eventsRetrievalProgress(progress) { | 305 eventsRetrievalProgress(progress) { |
| 273 this._delegate.loadingProgress(progress); | 306 this._delegate.loadingProgress(progress); |
| 274 } | 307 } |
| 275 }; | 308 }; |
| OLD | NEW |