mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
The Tracing format documentation does not make it clear if cat and args fields are mandatory. There are writers in the wild that do not generate these fields. Also trace viewer is capable of reading files with the fields omitted. Drive-by: do not spam user console with missing CPU profile samples. Change-Id: I7ab58fc132c2abc565296465924edb8a4fd07d07 Reviewed-on: https://chromium-review.googlesource.com/1022183 Commit-Queue: Alexei Filippov <alph@chromium.org> Reviewed-by: Andrey Kosyakov <caseq@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#552913} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 7f5762dbc3302d9a982c55ab5e8d2b4302233849
163 lines
3.9 KiB
JavaScript
163 lines
3.9 KiB
JavaScript
/*
|
|
* Copyright 2014 The Chromium Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
/**
|
|
* @interface
|
|
*/
|
|
SDK.TracingManagerClient = function() {};
|
|
|
|
SDK.TracingManagerClient.prototype = {
|
|
/**
|
|
* @param {!Array.<!SDK.TracingManager.EventPayload>} events
|
|
*/
|
|
traceEventsCollected(events) {},
|
|
tracingComplete() {},
|
|
/**
|
|
* @param {number} usage
|
|
*/
|
|
tracingBufferUsage(usage) {},
|
|
/**
|
|
* @param {number} progress
|
|
*/
|
|
eventsRetrievalProgress(progress) {}
|
|
};
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
SDK.TracingManager = class extends SDK.SDKModel {
|
|
/**
|
|
* @param {!SDK.Target} target
|
|
*/
|
|
constructor(target) {
|
|
super(target);
|
|
this._tracingAgent = target.tracingAgent();
|
|
target.registerTracingDispatcher(new SDK.TracingDispatcher(this));
|
|
|
|
/** @type {?SDK.TracingManagerClient} */
|
|
this._activeClient = null;
|
|
this._eventBufferSize = 0;
|
|
this._eventsRetrieved = 0;
|
|
}
|
|
|
|
/**
|
|
* @param {number=} usage
|
|
* @param {number=} eventCount
|
|
* @param {number=} percentFull
|
|
*/
|
|
_bufferUsage(usage, eventCount, percentFull) {
|
|
this._eventBufferSize = eventCount;
|
|
this._activeClient.tracingBufferUsage(usage || percentFull || 0);
|
|
}
|
|
|
|
/**
|
|
* @param {!Array.<!SDK.TracingManager.EventPayload>} events
|
|
*/
|
|
_eventsCollected(events) {
|
|
this._activeClient.traceEventsCollected(events);
|
|
this._eventsRetrieved += events.length;
|
|
if (!this._eventBufferSize)
|
|
return;
|
|
if (this._eventsRetrieved > this._eventBufferSize)
|
|
this._eventsRetrieved = this._eventBufferSize;
|
|
this._activeClient.eventsRetrievalProgress(this._eventsRetrieved / this._eventBufferSize);
|
|
}
|
|
|
|
_tracingComplete() {
|
|
this._eventBufferSize = 0;
|
|
this._eventsRetrieved = 0;
|
|
this._activeClient.tracingComplete();
|
|
this._activeClient = null;
|
|
this._finishing = false;
|
|
}
|
|
|
|
/**
|
|
* @param {!SDK.TracingManagerClient} client
|
|
* @param {string} categoryFilter
|
|
* @param {string} options
|
|
* @return {!Promise}
|
|
*/
|
|
start(client, categoryFilter, options) {
|
|
if (this._activeClient)
|
|
throw new Error('Tracing is already started');
|
|
const bufferUsageReportingIntervalMs = 500;
|
|
this._activeClient = client;
|
|
return this._tracingAgent.start(
|
|
categoryFilter, options, bufferUsageReportingIntervalMs, SDK.TracingManager.TransferMode.ReportEvents);
|
|
}
|
|
|
|
stop() {
|
|
if (!this._activeClient)
|
|
throw new Error('Tracing is not started');
|
|
if (this._finishing)
|
|
throw new Error('Tracing is already being stopped');
|
|
this._finishing = true;
|
|
this._tracingAgent.end();
|
|
}
|
|
};
|
|
|
|
SDK.SDKModel.register(SDK.TracingManager, SDK.Target.Capability.Tracing, false);
|
|
|
|
/** @typedef {!{
|
|
cat: (string|undefined),
|
|
pid: number,
|
|
tid: number,
|
|
ts: number,
|
|
ph: string,
|
|
name: string,
|
|
args: !Object,
|
|
dur: number,
|
|
id: string,
|
|
id2: (!{global: (string|undefined), local: (string|undefined)}|undefined),
|
|
scope: string,
|
|
bind_id: string,
|
|
s: string
|
|
}}
|
|
*/
|
|
SDK.TracingManager.EventPayload;
|
|
|
|
SDK.TracingManager.TransferMode = {
|
|
ReportEvents: 'ReportEvents',
|
|
ReturnAsStream: 'ReturnAsStream'
|
|
};
|
|
|
|
/**
|
|
* @implements {Protocol.TracingDispatcher}
|
|
* @unrestricted
|
|
*/
|
|
SDK.TracingDispatcher = class {
|
|
/**
|
|
* @param {!SDK.TracingManager} tracingManager
|
|
*/
|
|
constructor(tracingManager) {
|
|
this._tracingManager = tracingManager;
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {number=} usage
|
|
* @param {number=} eventCount
|
|
* @param {number=} percentFull
|
|
*/
|
|
bufferUsage(usage, eventCount, percentFull) {
|
|
this._tracingManager._bufferUsage(usage, eventCount, percentFull);
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {!Array.<!SDK.TracingManager.EventPayload>} data
|
|
*/
|
|
dataCollected(data) {
|
|
this._tracingManager._eventsCollected(data);
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
tracingComplete() {
|
|
this._tracingManager._tracingComplete();
|
|
}
|
|
};
|