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

Side by Side Diff: Source/devtools/front_end/CPUProfileView.js

Issue 185533004: FlameChart: convert colors magic into dataProvider.entryColor getter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: comments addressed Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1102
1103 /** 1103 /**
1104 * @return {?WebInspector.FlameChart.TimelineData} 1104 * @return {?WebInspector.FlameChart.TimelineData}
1105 */ 1105 */
1106 timelineData: function() 1106 timelineData: function()
1107 { 1107 {
1108 return this._timelineData || this._calculateTimelineData(); 1108 return this._timelineData || this._calculateTimelineData();
1109 }, 1109 },
1110 1110
1111 /** 1111 /**
1112 * @return {!WebInspector.FlameChart.ColorGenerator}
1113 */
1114 colorGenerator: function()
1115 {
1116 return this._colorGenerator;
1117 },
1118
1119 /**
1120 * @return {?WebInspector.FlameChart.TimelineData} 1112 * @return {?WebInspector.FlameChart.TimelineData}
1121 */ 1113 */
1122 _calculateTimelineData: function() 1114 _calculateTimelineData: function()
1123 { 1115 {
1124 if (!this._cpuProfileView.profileHead) 1116 if (!this._cpuProfileView.profileHead)
1125 return null; 1117 return null;
1126 1118
1127 var samples = this._cpuProfileView.samples; 1119 var samples = this._cpuProfileView.samples;
1128 var idToNode = this._cpuProfileView._idToNode; 1120 var idToNode = this._cpuProfileView._idToNode;
1129 var gcNode = this._cpuProfileView._gcNode; 1121 var gcNode = this._cpuProfileView._gcNode;
1130 var samplesCount = samples.length; 1122 var samplesCount = samples.length;
1131 var samplingInterval = this._cpuProfileView.samplingIntervalMs; 1123 var samplingInterval = this._cpuProfileView.samplingIntervalMs;
1132 1124
1133 var index = 0; 1125 var index = 0;
1134 1126
1135 var openIntervals = []; 1127 var openIntervals = [];
1136 var stackTrace = []; 1128 var stackTrace = [];
1137 var colorEntryIndexes = [];
1138 var maxDepth = 5; // minimum stack depth for the case when we see no act ivity. 1129 var maxDepth = 5; // minimum stack depth for the case when we see no act ivity.
1139 var depth = 0; 1130 var depth = 0;
1140 1131
1141 /** 1132 /**
1142 * @constructor 1133 * @constructor
1143 * @param {!Object} color 1134 * @param {string} color
1144 * @param {!number} depth 1135 * @param {number} depth
1145 * @param {!number} duration 1136 * @param {number} duration
1146 * @param {!number} startTime 1137 * @param {number} startTime
1147 * @param {!Object} node 1138 * @param {!Object} node
1148 */ 1139 */
1149 function ChartEntry(color, depth, duration, startTime, node) 1140 function ChartEntry(color, depth, duration, startTime, node)
1150 { 1141 {
1151 this.color = color; 1142 this.color = color;
1152 this.depth = depth; 1143 this.depth = depth;
1153 this.duration = duration; 1144 this.duration = duration;
1154 this.startTime = startTime; 1145 this.startTime = startTime;
1155 this.node = node; 1146 this.node = node;
1156 this.selfTime = 0; 1147 this.selfTime = 0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 ++depth; 1183 ++depth;
1193 } 1184 }
1194 if (depth < openIntervals.length) 1185 if (depth < openIntervals.length)
1195 openIntervals.length = depth; 1186 openIntervals.length = depth;
1196 if (!node) { 1187 if (!node) {
1197 entries[intervalIndex].selfTime += samplingInterval; 1188 entries[intervalIndex].selfTime += samplingInterval;
1198 continue; 1189 continue;
1199 } 1190 }
1200 1191
1201 var colorGenerator = this._colorGenerator; 1192 var colorGenerator = this._colorGenerator;
1193 var color = "";
1202 while (node) { 1194 while (node) {
1203 var color = colorGenerator.colorForID(node.functionName + ":" + node.url + ":" + node.lineNumber); 1195 color = colorGenerator.colorForID(node.functionName + ":" + node .url + ":" + node.lineNumber);
1204 var indexesForColor = colorEntryIndexes[color.index]; 1196 entries.push(new ChartEntry(color, depth, samplingInterval, samp leIndex * samplingInterval, node));
1205 if (!indexesForColor)
1206 indexesForColor = colorEntryIndexes[color.index] = [];
1207
1208 var entry = new ChartEntry(color, depth, samplingInterval, sampl eIndex * samplingInterval, node);
1209 indexesForColor.push(entries.length);
1210 entries.push(entry);
1211 openIntervals.push({node: node, index: index}); 1197 openIntervals.push({node: node, index: index});
1212 ++index; 1198 ++index;
1213 1199
1214 node = stackTrace.pop(); 1200 node = stackTrace.pop();
1215 ++depth; 1201 ++depth;
1216 } 1202 }
1217 entries[entries.length - 1].selfTime += samplingInterval; 1203 entries[entries.length - 1].selfTime += samplingInterval;
1218 } 1204 }
1219 1205
1206 var entryColors = new Array(entries.length);
1220 var entryNodes = new Array(entries.length); 1207 var entryNodes = new Array(entries.length);
1221 var entryColorIndexes = new Uint16Array(entries.length);
1222 var entryLevels = new Uint8Array(entries.length); 1208 var entryLevels = new Uint8Array(entries.length);
1223 var entryTotalTimes = new Float32Array(entries.length); 1209 var entryTotalTimes = new Float32Array(entries.length);
1224 var entrySelfTimes = new Float32Array(entries.length); 1210 var entrySelfTimes = new Float32Array(entries.length);
1225 var entryOffsets = new Float32Array(entries.length); 1211 var entryOffsets = new Float32Array(entries.length);
1226 var entryTitles = new Array(entries.length); 1212 var entryTitles = new Array(entries.length);
1227 var entryDeoptFlags = new Uint8Array(entries.length); 1213 var entryDeoptFlags = new Uint8Array(entries.length);
1228 1214
1229 for (var i = 0; i < entries.length; ++i) { 1215 for (var i = 0; i < entries.length; ++i) {
1230 var entry = entries[i]; 1216 var entry = entries[i];
1231 entryNodes[i] = entry.node; 1217 entryNodes[i] = entry.node;
1232 entryColorIndexes[i] = color.index; 1218 entryColors[i] = entry.color;
1233 entryLevels[i] = entry.depth; 1219 entryLevels[i] = entry.depth;
1234 entryTotalTimes[i] = entry.duration; 1220 entryTotalTimes[i] = entry.duration;
1235 entryOffsets[i] = entry.startTime; 1221 entryOffsets[i] = entry.startTime;
1236 entryTitles[i] = entry.node.functionName; 1222 entryTitles[i] = entry.node.functionName;
1237 var reason = entry.node.deoptReason; 1223 var reason = entry.node.deoptReason;
1238 entryDeoptFlags[i] = (reason && reason !== "no reason"); 1224 entryDeoptFlags[i] = (reason && reason !== "no reason");
1239 } 1225 }
1240 1226
1241 this._maxStackDepth = Math.max(maxDepth, depth); 1227 this._maxStackDepth = Math.max(maxDepth, depth);
1242 1228
1243 this._timelineData = { 1229 this._timelineData = {
1244 colorEntryIndexes: colorEntryIndexes,
1245 entryColorIndexes: entryColorIndexes,
1246 entryLevels: entryLevels, 1230 entryLevels: entryLevels,
1247 entryTotalTimes: entryTotalTimes, 1231 entryTotalTimes: entryTotalTimes,
1248 entryOffsets: entryOffsets, 1232 entryOffsets: entryOffsets,
1249 }; 1233 };
1250 1234
1251 this._entryTitles = entryTitles; 1235 this._entryTitles = entryTitles;
1252 this._entryNodes = entryNodes; 1236 this._entryNodes = entryNodes;
1253 this._entrySelfTimes = entrySelfTimes; 1237 this._entrySelfTimes = entrySelfTimes;
1254 this._entryDeoptFlags = entryDeoptFlags; 1238 this._entryDeoptFlags = entryDeoptFlags;
1239 this._entryColors = entryColors;
1255 1240
1256 return /** @type {!WebInspector.FlameChart.TimelineData} */ (this._timel ineData); 1241 return /** @type {!WebInspector.FlameChart.TimelineData} */ (this._timel ineData);
1257 }, 1242 },
1258 1243
1259 /** 1244 /**
1260 * @param {number} ms 1245 * @param {number} ms
1261 * @return {string} 1246 * @return {string}
1262 */ 1247 */
1263 _millisecondsToString: function(ms) 1248 _millisecondsToString: function(ms)
1264 { 1249 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 return this._entryDeoptFlags[entryIndex] ? this._boldFont : this._font; 1320 return this._entryDeoptFlags[entryIndex] ? this._boldFont : this._font;
1336 }, 1321 },
1337 1322
1338 /** 1323 /**
1339 * @param {number} entryIndex 1324 * @param {number} entryIndex
1340 * @return {!Object} 1325 * @return {!Object}
1341 */ 1326 */
1342 entryData: function(entryIndex) 1327 entryData: function(entryIndex)
1343 { 1328 {
1344 return this._entryNodes[entryIndex]; 1329 return this._entryNodes[entryIndex];
1345 } 1330 },
1331
1332 /**
1333 * @param {number} entryIndex
1334 * @return {!string}
1335 */
1336 entryColor: function(entryIndex)
1337 {
1338 return this._entryColors[entryIndex];
1339 },
1346 } 1340 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/FlameChart.js » ('j') | Source/devtools/front_end/FlameChart.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698