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

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: addressing comments 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0d15c5816f326dcd77c44b39c6f7aeefb43eafa3 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,86 @@ TimelineModel.TimelineJSProfileProcessor = class {
}
return map.get(nativeName) || null;
}
+
+ /**
+ * @param {*} profile
+ * @return {!Array<!SDK.TracingManager.EventPayload>}
+ */
+ static buildTraceProfileFromCpuProfile(profile) {
+ if (!profile)
+ return [];
+ var events = [];
+ appendEvent('TracingStartedInPage', {'sessionId': '1'}, 0, 0, 'M');
+ var idToNode = new Map();
+ var nodes = profile['nodes'];
+ for (var i = 0; i < nodes.length; ++i)
+ idToNode.set(nodes[i].id, nodes[i]);
+ var programEvent = null;
+ var functionEvent = null;
+ var nextTime = profile.startTime;
+ var currentTime;
+ var samples = profile['samples'];
+ var timeDeltas = profile['timeDeltas'];
+ for (var i = 0; i < samples.length; ++i) {
+ currentTime = nextTime;
+ nextTime += timeDeltas[i];
+ var node = idToNode.get(samples[i]);
+ var name = node.callFrame.functionName;
+ if (name === '(idle)') {
+ closeEvents();
+ continue;
+ }
+ if (!programEvent)
+ programEvent = appendEvent('MessageLoop::RunTask', {}, currentTime, 0, 'X', 'toplevel');
+ if (name === '(program)') {
+ if (functionEvent) {
+ functionEvent.dur = currentTime - functionEvent.ts;
+ functionEvent = null;
+ }
+ } else {
+ // A JS function.
+ if (!functionEvent)
+ functionEvent = appendEvent('FunctionCall', {'sessionId': '1'}, currentTime);
+ }
+ }
+ closeEvents();
+ appendEvent('CpuProfile', {'cpuProfile': profile}, profile.endTime, 0, 'I');
+ return events;
+
+ function closeEvents() {
+ if (programEvent)
+ programEvent.dur = currentTime - programEvent.ts;
+ if (functionEvent)
+ functionEvent.dur = currentTime - functionEvent.ts;
+ programEvent = null;
+ functionEvent = null;
+ }
+
+ /**
+ * @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} */
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698