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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineModel.js

Issue 1748993002: DevTools: Initial implementation of line-level CPU profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments. Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 var events = thread.events(); 722 var events = thread.events();
723 var asyncEvents = thread.asyncEvents(); 723 var asyncEvents = thread.asyncEvents();
724 724
725 var jsSamples; 725 var jsSamples;
726 if (Runtime.experiments.isEnabled("timelineTracingJSProfile")) { 726 if (Runtime.experiments.isEnabled("timelineTracingJSProfile")) {
727 jsSamples = WebInspector.TimelineJSProfileProcessor.processRawV8Samp les(events); 727 jsSamples = WebInspector.TimelineJSProfileProcessor.processRawV8Samp les(events);
728 } else { 728 } else {
729 var cpuProfileEvent = events.peekLast(); 729 var cpuProfileEvent = events.peekLast();
730 if (cpuProfileEvent && cpuProfileEvent.name === WebInspector.Timelin eModel.RecordType.CpuProfile) { 730 if (cpuProfileEvent && cpuProfileEvent.name === WebInspector.Timelin eModel.RecordType.CpuProfile) {
731 var cpuProfile = cpuProfileEvent.args["data"]["cpuProfile"]; 731 var cpuProfile = cpuProfileEvent.args["data"]["cpuProfile"];
732 if (cpuProfile) 732 if (cpuProfile) {
733 jsSamples = WebInspector.TimelineJSProfileProcessor.generate TracingEventsFromCpuProfile(cpuProfile, thread); 733 var jsProfileModel = new WebInspector.CPUProfileDataModel(cp uProfile);
734 this._lineLevelCPUProfile.appendCPUProfile(jsProfileModel);
735 jsSamples = WebInspector.TimelineJSProfileProcessor.generate TracingEventsFromCpuProfile(jsProfileModel, thread);
736 }
734 } 737 }
735 } 738 }
736 739
737 if (jsSamples && jsSamples.length) 740 if (jsSamples && jsSamples.length)
738 events = events.mergeOrdered(jsSamples, WebInspector.TracingModel.Ev ent.orderedCompareStartTime); 741 events = events.mergeOrdered(jsSamples, WebInspector.TracingModel.Ev ent.orderedCompareStartTime);
739 if (jsSamples || events.some(function(e) { return e.name === WebInspecto r.TimelineModel.RecordType.JSSample; })) { 742 if (jsSamples || events.some(function(e) { return e.name === WebInspecto r.TimelineModel.RecordType.JSSample; })) {
740 var jsFrameEvents = WebInspector.TimelineJSProfileProcessor.generate JSFrameEvents(events); 743 var jsFrameEvents = WebInspector.TimelineJSProfileProcessor.generate JSFrameEvents(events);
741 if (jsFrameEvents && jsFrameEvents.length) 744 if (jsFrameEvents && jsFrameEvents.length)
742 events = jsFrameEvents.mergeOrdered(events, WebInspector.Tracing Model.Event.orderedCompareStartTime); 745 events = jsFrameEvents.mergeOrdered(events, WebInspector.Tracing Model.Event.orderedCompareStartTime);
743 } 746 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 { 1057 {
1055 for (var group of source.keys()) { 1058 for (var group of source.keys()) {
1056 var events = target.get(group) || []; 1059 var events = target.get(group) || [];
1057 events = events.mergeOrdered(source.get(group) || [], WebInspector.T racingModel.Event.compareStartAndEndTime); 1060 events = events.mergeOrdered(source.get(group) || [], WebInspector.T racingModel.Event.compareStartAndEndTime);
1058 target.set(group, events); 1061 target.set(group, events);
1059 } 1062 }
1060 }, 1063 },
1061 1064
1062 reset: function() 1065 reset: function()
1063 { 1066 {
1067 this._lineLevelCPUProfile = new WebInspector.TimelineModel.LineLevelProf ile();
1064 this._virtualThreads = []; 1068 this._virtualThreads = [];
1065 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ 1069 /** @type {!Array.<!WebInspector.TracingModel.Event>} */
1066 this._mainThreadEvents = []; 1070 this._mainThreadEvents = [];
1067 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac ingModel.AsyncEvent>>} */ 1071 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac ingModel.AsyncEvent>>} */
1068 this._mainThreadAsyncEventsByGroup = new Map(); 1072 this._mainThreadAsyncEventsByGroup = new Map();
1069 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ 1073 /** @type {!Array.<!WebInspector.TracingModel.Event>} */
1070 this._inspectedTargetEvents = []; 1074 this._inspectedTargetEvents = [];
1071 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ 1075 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */
1072 this._records = []; 1076 this._records = [];
1073 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ 1077 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */
1074 this._mainThreadTasks = []; 1078 this._mainThreadTasks = [];
1075 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ 1079 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */
1076 this._gpuTasks = []; 1080 this._gpuTasks = [];
1077 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ 1081 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */
1078 this._eventDividerRecords = []; 1082 this._eventDividerRecords = [];
1079 /** @type {?string} */ 1083 /** @type {?string} */
1080 this._sessionId = null; 1084 this._sessionId = null;
1081 /** @type {?number} */ 1085 /** @type {?number} */
1082 this._mainFrameNodeId = null; 1086 this._mainFrameNodeId = null;
1083 this._minimumRecordTime = 0; 1087 this._minimumRecordTime = 0;
1084 this._maximumRecordTime = 0; 1088 this._maximumRecordTime = 0;
1085 }, 1089 },
1086 1090
1087 /** 1091 /**
1092 * @return {!WebInspector.TimelineModel.LineLevelProfile}
1093 */
1094 lineLevelCPUProfile: function()
1095 {
1096 return this._lineLevelCPUProfile;
1097 },
1098
1099 /**
1088 * @return {number} 1100 * @return {number}
1089 */ 1101 */
1090 minimumRecordTime: function() 1102 minimumRecordTime: function()
1091 { 1103 {
1092 return this._minimumRecordTime; 1104 return this._minimumRecordTime;
1093 }, 1105 },
1094 1106
1095 /** 1107 /**
1096 * @return {number} 1108 * @return {number}
1097 */ 1109 */
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 if (!id) 1728 if (!id)
1717 return; 1729 return;
1718 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */ 1730 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */
1719 var initiatorMap = this._initiatorByType.get(initiatorType); 1731 var initiatorMap = this._initiatorByType.get(initiatorType);
1720 if (isInitiator) 1732 if (isInitiator)
1721 initiatorMap.set(id, event); 1733 initiatorMap.set(id, event);
1722 else 1734 else
1723 event.initiator = initiatorMap.get(id) || null; 1735 event.initiator = initiatorMap.get(id) || null;
1724 } 1736 }
1725 } 1737 }
1738
1739 /**
1740 * @constructor
1741 */
1742 WebInspector.TimelineModel.LineLevelProfile = function()
1743 {
1744 /** @type {!Map<string, !Map<number, number>>} */
1745 this._files = new Map();
1746 }
1747
1748 WebInspector.TimelineModel.LineLevelProfile.prototype = {
1749 /**
1750 * @param {!WebInspector.CPUProfileDataModel} profile
1751 */
1752 appendCPUProfile: function(profile)
1753 {
1754 var nodesToGo = [profile.profileHead];
1755 var sampleDuration = (profile.profileEndTime - profile.profileStartTime) / profile.totalHitCount;
1756 while (nodesToGo.length) {
1757 var nodes = nodesToGo.pop().children;
1758 for (var i = 0; i < nodes.length; ++i) {
1759 var node = nodes[i];
1760 nodesToGo.push(node);
1761 if (!node.url || !node.positionTicks)
1762 continue;
1763 var fileInfo = this._files.get(node.url);
1764 if (!fileInfo) {
1765 fileInfo = new Map();
1766 this._files.set(node.url, fileInfo);
1767 }
1768 for (var j = 0; j < node.positionTicks.length; ++j) {
1769 var lineInfo = node.positionTicks[j];
1770 var line = lineInfo.line - 1;
1771 var time = lineInfo.ticks * sampleDuration;
1772 fileInfo.set(line, (fileInfo.get(line) || 0) + time);
1773 }
1774 }
1775 }
1776 },
1777
1778 /**
1779 * @return {!Map<string, !Map<number, number>>}
1780 */
1781 files: function()
1782 {
1783 return this._files;
1784 }
1785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698