Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Unified Diff: third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js

Issue 2729793003: DevTools: Support reading CPU profile format on Performance panel (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js
diff --git a/third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js b/third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js
index 3769b458206fb47843b5be5d5f012f2853414874..bf9149848bc6857c882d4557b03f1e292fef0d9b 100644
--- a/third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js
+++ b/third_party/WebKit/Source/devtools/front_end/timeline_model/TimelineJSProfile.js
@@ -231,6 +231,93 @@ TimelineModel.TimelineJSProfileProcessor = class {
}
return map.get(nativeName) || null;
}
+
+ /**
+ * @param {*} profile
caseq 2017/03/02 19:00:40 ?Object
alph 2017/03/02 19:20:00 This actually could be anything, as it comes out o
+ * @return {!Array<!SDK.TracingManager.EventPayload>}
+ */
+ static buildTraceProfileFromCpuProfile(profile) {
+ if (!profile)
+ return [];
+ var start = profile.startTime;
+ var events = [];
+ appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M');
+ var idToNode = new Map();
+ for (var i = 0; i < profile.nodes.length; ++i)
caseq 2017/03/02 19:00:40 profile['nodes']...
alph 2017/03/02 19:20:00 Done.
+ idToNode.set(profile.nodes[i].id, profile.nodes[i]);
+ var stateProgram = '(program)';
+ var stateIdle = '(idle)';
+ var stateFunction = '(function)';
+ var state = stateIdle;
+ var programEvent = null;
+ var functionEvent = null;
+ var nextTime = start;
+ for (var i = 0; i < profile.samples.length; ++i) {
+ var currentTime = nextTime;
+ nextTime += profile.timeDeltas[i];
+ var id = profile.samples[i];
+ var node = idToNode.get(id);
+ var name = node.callFrame.functionName;
+ if (state === name)
caseq 2017/03/02 19:00:40 Let's keep the state space separate from names spa
alph 2017/03/02 19:20:00 Done.
+ continue;
+ if (state === stateIdle) {
+ programEvent = appendEvent('MessageLoop::RunTask', {}, currentTime, 0, 'X', 'toplevel');
+ state = stateProgram;
+ if (name !== '(program)') {
+ functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentTime, 0);
+ state = stateFunction;
+ }
+ continue;
+ }
+ if (name === stateIdle) {
+ if (programEvent)
+ programEvent.dur = currentTime - programEvent.ts;
+ if (functionEvent)
+ functionEvent.dur = currentTime - functionEvent.ts;
+ programEvent = null;
+ functionEvent = null;
+ state = stateIdle;
+ continue;
+ }
+ // Remaining cases program->function and function->program.
+ if (name === stateProgram) {
+ functionEvent.dur = currentTime - functionEvent.ts;
+ functionEvent = null;
+ state = stateProgram;
+ } else if (state === stateProgram) {
+ functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentTime, 0);
+ state = stateFunction;
+ }
+ }
+ appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I');
+ events.sort((a, b) => a.startTime - b.startTime);
+ return events;
+
+ /**
+ * @param {string} name
+ * @param {*} data
+ * @param {number} ts
+ * @param {number=} dur
+ * @param {string=} ph
+ * @param {string=} cat
+ * @return {!SDK.TracingManager.EventPayload}
+ */
+ function appendEvent(name, data, ts, dur, ph, cat) {
+ var event = /** @type {!SDK.TracingManager.EventPayload} */ ({
+ cat: cat || 'disabled-by-default-devtools.timeline',
+ name: name,
+ ph: ph || 'X',
+ pid: 1,
+ tid: 1,
+ ts: ts,
+ args: {data: data}
+ });
+ if (dur)
+ event.dur = dur;
+ events.push(event);
+ return event;
+ }
+ }
};
/** @enum {string} */

Powered by Google App Engine
This is Rietveld 408576698