Commit 79ad7ecc authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

DevTools: make timeline respect main target that does not have tracing capability.

Change-Id: I724548b02b574864c482b900376d5a25ba1dab7c
Reviewed-on: https://chromium-review.googlesource.com/1159986Reviewed-by: default avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580414}
parent 54dd68c0
...@@ -971,7 +971,10 @@ Runtime.ExperimentsSupport = class { ...@@ -971,7 +971,10 @@ Runtime.ExperimentsSupport = class {
*/ */
isEnabled(experimentName) { isEnabled(experimentName) {
this._checkExperiment(experimentName); this._checkExperiment(experimentName);
// Check for explicitly disabled experiments first - the code could call setEnable(false) on the experiment enabled
// by default and we should respect that.
if (Runtime._experimentsSetting()[experimentName] === false)
return false;
if (this._enabledTransiently[experimentName]) if (this._enabledTransiently[experimentName])
return true; return true;
if (!this.supportEnabled()) if (!this.supportEnabled())
......
...@@ -13,6 +13,7 @@ Timeline.TimelineController = class { ...@@ -13,6 +13,7 @@ Timeline.TimelineController = class {
* @param {!Timeline.TimelineController.Client} client * @param {!Timeline.TimelineController.Client} client
*/ */
constructor(target, client) { constructor(target, client) {
this._target = target;
this._tracingManager = target.model(SDK.TracingManager); this._tracingManager = target.model(SDK.TracingManager);
this._performanceModel = new Timeline.PerformanceModel(); this._performanceModel = new Timeline.PerformanceModel();
this._performanceModel.setMainTarget(target); this._performanceModel.setMainTarget(target);
...@@ -34,7 +35,7 @@ Timeline.TimelineController = class { ...@@ -34,7 +35,7 @@ Timeline.TimelineController = class {
* @return {!SDK.Target} * @return {!SDK.Target}
*/ */
mainTarget() { mainTarget() {
return this._tracingManager.target(); return this._target;
} }
/** /**
...@@ -93,9 +94,11 @@ Timeline.TimelineController = class { ...@@ -93,9 +94,11 @@ Timeline.TimelineController = class {
*/ */
async stopRecording() { async stopRecording() {
const tracingStoppedPromises = []; const tracingStoppedPromises = [];
tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve)); if (this._tracingManager)
tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve));
tracingStoppedPromises.push(this._stopProfilingOnAllModels()); tracingStoppedPromises.push(this._stopProfilingOnAllModels());
this._tracingManager.stop(); if (this._tracingManager)
this._tracingManager.stop();
tracingStoppedPromises.push(SDK.targetManager.resumeAllTargets()); tracingStoppedPromises.push(SDK.targetManager.resumeAllTargets());
this._client.loadingStarted(); this._client.loadingStarted();
...@@ -171,14 +174,16 @@ Timeline.TimelineController = class { ...@@ -171,14 +174,16 @@ Timeline.TimelineController = class {
* @param {boolean=} enableJSSampling * @param {boolean=} enableJSSampling
* @return {!Promise} * @return {!Promise}
*/ */
_startRecordingWithCategories(categories, enableJSSampling) { async _startRecordingWithCategories(categories, enableJSSampling) {
SDK.targetManager.suspendAllTargets(); SDK.targetManager.suspendAllTargets();
const profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEnabled('timelineTracingJSProfile') ? if (enableJSSampling && !Runtime.experiments.isEnabled('timelineTracingJSProfile'))
this._startProfilingOnAllModels() : await this._startProfilingOnAllModels();
Promise.resolve(); if (!this._tracingManager)
return;
const samplingFrequencyHz = Common.moduleSetting('highResolutionCpuProfiling').get() ? 10000 : 1000; const samplingFrequencyHz = Common.moduleSetting('highResolutionCpuProfiling').get() ? 10000 : 1000;
const options = 'sampling-frequency=' + samplingFrequencyHz; const options = 'sampling-frequency=' + samplingFrequencyHz;
return profilingStartedPromise.then(() => this._tracingManager.start(this, categories, options)); return this._tracingManager.start(this, categories, options);
} }
/** /**
...@@ -294,6 +299,20 @@ Timeline.TimelineController = class { ...@@ -294,6 +299,20 @@ Timeline.TimelineController = class {
const pid = mainMetaEvent.thread.process().id(); const pid = mainMetaEvent.thread.process().id();
const mainCpuProfile = this._cpuProfiles.get(this._tracingManager.target().id()); const mainCpuProfile = this._cpuProfiles.get(this._tracingManager.target().id());
this._injectCpuProfileEvent(pid, mainMetaEvent.thread.id(), mainCpuProfile); this._injectCpuProfileEvent(pid, mainMetaEvent.thread.id(), mainCpuProfile);
} else {
// Or there was no tracing manager in the main target at all, in this case build the model full
// of cpu profiles.
// Assign tids equal to the target ordinals for the thread name lookup.
// This is a little shaky because targets can disappear, but we will read these tids sooner than
// that.
// TODO(pfeldman): resolve this.
let counter = 1000;
for (const pair of this._cpuProfiles) {
const target = SDK.targetManager.targetById(pair[0]);
const tid = target ? SDK.targetManager.targets().indexOf(target) : ++counter;
this._tracingModel.addEvents(
TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(pair[1], tid));
}
} }
} }
......
...@@ -221,7 +221,7 @@ Timeline.TimelineLoader = class { ...@@ -221,7 +221,7 @@ Timeline.TimelineLoader = class {
let traceEvents; let traceEvents;
try { try {
const profile = JSON.parse(text); const profile = JSON.parse(text);
traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile); traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile, 1);
} catch (e) { } catch (e) {
this._reportErrorAndCancelLoading(Common.UIString('Malformed CPU profile format')); this._reportErrorAndCancelLoading(Common.UIString('Malformed CPU profile format'));
return; return;
......
...@@ -227,9 +227,10 @@ TimelineModel.TimelineJSProfileProcessor = class { ...@@ -227,9 +227,10 @@ TimelineModel.TimelineJSProfileProcessor = class {
/** /**
* @param {*} profile * @param {*} profile
* @param {number} tid
* @return {!Array<!SDK.TracingManager.EventPayload>} * @return {!Array<!SDK.TracingManager.EventPayload>}
*/ */
static buildTraceProfileFromCpuProfile(profile) { static buildTraceProfileFromCpuProfile(profile, tid) {
if (!profile) if (!profile)
return []; return [];
const events = []; const events = [];
...@@ -294,7 +295,7 @@ TimelineModel.TimelineJSProfileProcessor = class { ...@@ -294,7 +295,7 @@ TimelineModel.TimelineJSProfileProcessor = class {
name: name, name: name,
ph: ph || 'X', ph: ph || 'X',
pid: 1, pid: 1,
tid: 1, tid,
ts: ts, ts: ts,
args: {data: data} args: {data: data}
}); });
......
...@@ -180,8 +180,9 @@ TimelineModel.TimelineModel = class { ...@@ -180,8 +180,9 @@ TimelineModel.TimelineModel = class {
* @param {!SDK.TracingModel} tracingModel * @param {!SDK.TracingModel} tracingModel
*/ */
_processGenericTrace(tracingModel) { _processGenericTrace(tracingModel) {
const browserMainThread = let browserMainThread = SDK.TracingModel.browserMainThread(tracingModel);
SDK.TracingModel.browserMainThread(tracingModel) || tracingModel.sortedProcesses()[0].sortedThreads()[0]; if (!browserMainThread && tracingModel.sortedProcesses().length)
browserMainThread = tracingModel.sortedProcesses()[0].sortedThreads()[0];
for (const process of tracingModel.sortedProcesses()) { for (const process of tracingModel.sortedProcesses()) {
for (const thread of process.sortedThreads()) { for (const thread of process.sortedThreads()) {
this._processThreadEvents( this._processThreadEvents(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment