Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var g_browserBridge; | 5 var g_browserBridge; |
| 6 var g_mainView; | 6 var g_mainView; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Main entry point called once the page has loaded. | 9 * Main entry point called once the page has loaded. |
| 10 */ | 10 */ |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 KEY_BIRTH_THREAD, | 524 KEY_BIRTH_THREAD, |
| 525 KEY_DEATH_THREAD, | 525 KEY_DEATH_THREAD, |
| 526 KEY_PROCESS_TYPE, | 526 KEY_PROCESS_TYPE, |
| 527 KEY_PROCESS_ID, | 527 KEY_PROCESS_ID, |
| 528 KEY_FUNCTION_NAME, | 528 KEY_FUNCTION_NAME, |
| 529 KEY_SOURCE_LOCATION, | 529 KEY_SOURCE_LOCATION, |
| 530 KEY_FILE_NAME, | 530 KEY_FILE_NAME, |
| 531 KEY_LINE_NUMBER, | 531 KEY_LINE_NUMBER, |
| 532 ]; | 532 ]; |
| 533 | 533 |
| 534 /** | |
| 535 * The time (in milliseconds) to wait after receiving new data before | |
| 536 * re-drawing it to the screen. The reason we wait a bit is to avoid | |
| 537 * repainting repeatedly during the loading phase (which can slow things | |
| 538 * down). Note that this only slows down the addition of new data. It does | |
| 539 * not impact the latency of user-initiated operations like sorting or | |
| 540 * merging. | |
| 541 */ | |
| 542 var PROCESS_DATA_DELAY_MS = 500; | |
| 543 | |
| 534 // -------------------------------------------------------------------------- | 544 // -------------------------------------------------------------------------- |
| 535 // General utility functions | 545 // General utility functions |
| 536 // -------------------------------------------------------------------------- | 546 // -------------------------------------------------------------------------- |
| 537 | 547 |
| 538 /** | 548 /** |
| 539 * Returns a list of all the keys in |dict|. | 549 * Returns a list of all the keys in |dict|. |
| 540 */ | 550 */ |
| 541 function getDictionaryKeys(dict) { | 551 function getDictionaryKeys(dict) { |
| 542 var keys = []; | 552 var keys = []; |
| 543 for (var key in dict) { | 553 for (var key in dict) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 */ | 717 */ |
| 708 function getFilenameFromPath(path) { | 718 function getFilenameFromPath(path) { |
| 709 var lastSlash = Math.max(path.lastIndexOf('/'), | 719 var lastSlash = Math.max(path.lastIndexOf('/'), |
| 710 path.lastIndexOf('\\')); | 720 path.lastIndexOf('\\')); |
| 711 if (lastSlash == -1) | 721 if (lastSlash == -1) |
| 712 return path; | 722 return path; |
| 713 | 723 |
| 714 return path.substr(lastSlash + 1); | 724 return path.substr(lastSlash + 1); |
| 715 } | 725 } |
| 716 | 726 |
| 727 /** | |
| 728 * Returns the current time in milliseconds since unix epoch. | |
| 729 */ | |
| 730 function getTimeMillis() { | |
| 731 return (new Date()).getTime(); | |
| 732 } | |
| 733 | |
| 717 // -------------------------------------------------------------------------- | 734 // -------------------------------------------------------------------------- |
| 718 // Functions that augment, bucket, and compute aggregates for the input data. | 735 // Functions that augment, bucket, and compute aggregates for the input data. |
| 719 // -------------------------------------------------------------------------- | 736 // -------------------------------------------------------------------------- |
| 720 | 737 |
| 721 /** | 738 /** |
| 722 * Adds new derived properties to row. Mutates the provided dictionary |e|. | 739 * Adds new derived properties to row. Mutates the provided dictionary |e|. |
| 723 */ | 740 */ |
| 724 function augmentDataRow(e) { | 741 function augmentDataRow(e) { |
| 725 e[KEY_AVG_QUEUE_TIME] = e[KEY_QUEUE_TIME] / e[KEY_COUNT]; | 742 e[KEY_AVG_QUEUE_TIME] = e[KEY_QUEUE_TIME] / e[KEY_COUNT]; |
| 726 e[KEY_AVG_RUN_TIME] = e[KEY_RUN_TIME] / e[KEY_COUNT]; | 743 e[KEY_AVG_RUN_TIME] = e[KEY_RUN_TIME] / e[KEY_COUNT]; |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 // stuff), so we skip past them. | 1178 // stuff), so we skip past them. |
| 1162 continue; | 1179 continue; |
| 1163 } | 1180 } |
| 1164 | 1181 |
| 1165 // Add our computed properties. | 1182 // Add our computed properties. |
| 1166 augmentDataRow(newRow); | 1183 augmentDataRow(newRow); |
| 1167 | 1184 |
| 1168 this.flatData_.push(newRow); | 1185 this.flatData_.push(newRow); |
| 1169 } | 1186 } |
| 1170 | 1187 |
| 1171 // Recompute the merged data based on flatData_. | 1188 // We may end up calling addData() repeatedly (once for each process). |
| 1172 this.updateMergedData_(); | 1189 // To avoid this from slowing us down we do bulk updates on a timer. |
| 1190 this.updateMergedDataSoon_(); | |
| 1191 }, | |
| 1192 | |
| 1193 updateMergedDataSoon_: function() { | |
| 1194 if (this.updateMergedDataPending_) { | |
| 1195 // If a delayed task has already been posted to re-merge the data, | |
| 1196 // then we don't need to do anything extra. | |
| 1197 return; | |
| 1198 } | |
| 1199 | |
| 1200 // Otherwise schedule updateMergeData_() to be called later. We want it to | |
| 1201 // be called no more than once every PROCESS_DATA_DELAY_MS milliseconds. | |
| 1202 | |
| 1203 if (this.lastUpdateMergedDataTime_ == undefined) | |
| 1204 this.lastUpdateMergedDataTime_ = 0; | |
| 1205 | |
| 1206 var timeSinceLastMerge = getTimeMillis() - this.lastUpdateMergedDataTime_; | |
| 1207 var timeToWait = Math.max(0, PROCESS_DATA_DELAY_MS - timeSinceLastMerge); | |
| 1208 | |
| 1209 var functionToRun = function() { | |
| 1210 // Do the actual update. | |
| 1211 this.updateMergedData_(); | |
| 1212 // Keep track of when we last ran. | |
| 1213 this.lastUpdateMergedDataTime_ = getTimeMillis(); | |
| 1214 this.updateMergedDataPending_ = false; | |
| 1215 }.bind(this); | |
|
jar (doing other things)
2011/11/17 07:02:42
curious qusetion: Do you need the .bind(this)?
Wo
eroman
2011/11/17 07:06:55
|this| is a very weird beast in javascript. Wherea
| |
| 1216 | |
| 1217 this.updateMergedDataPending_ = true; | |
| 1218 window.setTimeout(functionToRun, timeToWait); | |
| 1173 }, | 1219 }, |
| 1174 | 1220 |
| 1175 updateMergedData_: function() { | 1221 updateMergedData_: function() { |
| 1176 // Recompute mergedData_. | 1222 // Recompute mergedData_. |
| 1177 this.mergedData_ = mergeRows(this.flatData_, | 1223 this.mergedData_ = mergeRows(this.flatData_, |
| 1178 this.getMergeColumns_(), | 1224 this.getMergeColumns_(), |
| 1179 this.shouldMergeSimilarThreads_()); | 1225 this.shouldMergeSimilarThreads_()); |
| 1180 | 1226 |
| 1181 // Recompute filteredData_ (since it is derived from mergedData_) | 1227 // Recompute filteredData_ (since it is derived from mergedData_) |
| 1182 this.updateFilteredData_(); | 1228 this.updateFilteredData_(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1589 groupKey.push(entry); | 1635 groupKey.push(entry); |
| 1590 } | 1636 } |
| 1591 | 1637 |
| 1592 return JSON.stringify(groupKey); | 1638 return JSON.stringify(groupKey); |
| 1593 }; | 1639 }; |
| 1594 }, | 1640 }, |
| 1595 }; | 1641 }; |
| 1596 | 1642 |
| 1597 return MainView; | 1643 return MainView; |
| 1598 })(); | 1644 })(); |
| OLD | NEW |