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 {
*/
isEnabled(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])
return true;
if (!this.supportEnabled())
......
......@@ -13,6 +13,7 @@ Timeline.TimelineController = class {
* @param {!Timeline.TimelineController.Client} client
*/
constructor(target, client) {
this._target = target;
this._tracingManager = target.model(SDK.TracingManager);
this._performanceModel = new Timeline.PerformanceModel();
this._performanceModel.setMainTarget(target);
......@@ -34,7 +35,7 @@ Timeline.TimelineController = class {
* @return {!SDK.Target}
*/
mainTarget() {
return this._tracingManager.target();
return this._target;
}
/**
......@@ -93,8 +94,10 @@ Timeline.TimelineController = class {
*/
async stopRecording() {
const tracingStoppedPromises = [];
if (this._tracingManager)
tracingStoppedPromises.push(new Promise(resolve => this._tracingCompleteCallback = resolve));
tracingStoppedPromises.push(this._stopProfilingOnAllModels());
if (this._tracingManager)
this._tracingManager.stop();
tracingStoppedPromises.push(SDK.targetManager.resumeAllTargets());
......@@ -171,14 +174,16 @@ Timeline.TimelineController = class {
* @param {boolean=} enableJSSampling
* @return {!Promise}
*/
_startRecordingWithCategories(categories, enableJSSampling) {
async _startRecordingWithCategories(categories, enableJSSampling) {
SDK.targetManager.suspendAllTargets();
const profilingStartedPromise = enableJSSampling && !Runtime.experiments.isEnabled('timelineTracingJSProfile') ?
this._startProfilingOnAllModels() :
Promise.resolve();
if (enableJSSampling && !Runtime.experiments.isEnabled('timelineTracingJSProfile'))
await this._startProfilingOnAllModels();
if (!this._tracingManager)
return;
const samplingFrequencyHz = Common.moduleSetting('highResolutionCpuProfiling').get() ? 10000 : 1000;
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 {
const pid = mainMetaEvent.thread.process().id();
const mainCpuProfile = this._cpuProfiles.get(this._tracingManager.target().id());
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 {
let traceEvents;
try {
const profile = JSON.parse(text);
traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile);
traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile, 1);
} catch (e) {
this._reportErrorAndCancelLoading(Common.UIString('Malformed CPU profile format'));
return;
......
......@@ -227,9 +227,10 @@ TimelineModel.TimelineJSProfileProcessor = class {
/**
* @param {*} profile
* @param {number} tid
* @return {!Array<!SDK.TracingManager.EventPayload>}
*/
static buildTraceProfileFromCpuProfile(profile) {
static buildTraceProfileFromCpuProfile(profile, tid) {
if (!profile)
return [];
const events = [];
......@@ -294,7 +295,7 @@ TimelineModel.TimelineJSProfileProcessor = class {
name: name,
ph: ph || 'X',
pid: 1,
tid: 1,
tid,
ts: ts,
args: {data: data}
});
......
......@@ -180,8 +180,9 @@ TimelineModel.TimelineModel = class {
* @param {!SDK.TracingModel} tracingModel
*/
_processGenericTrace(tracingModel) {
const browserMainThread =
SDK.TracingModel.browserMainThread(tracingModel) || tracingModel.sortedProcesses()[0].sortedThreads()[0];
let browserMainThread = SDK.TracingModel.browserMainThread(tracingModel);
if (!browserMainThread && tracingModel.sortedProcesses().length)
browserMainThread = tracingModel.sortedProcesses()[0].sortedThreads()[0];
for (const process of tracingModel.sortedProcesses()) {
for (const thread of process.sortedThreads()) {
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