Index: third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js |
index 0a7872fdc5c15b98863135737d5ba1b67cfa9fe5..5b10201d7a0dce0b6f5a469bb372c9cac98ccfbf 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js |
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js |
@@ -16,6 +16,7 @@ WebInspector.CPUProfileDataModel = function(profile) |
this.profileEndTime = profile.endTime * 1000; |
this._assignParentsInProfile(); |
if (this.samples) { |
+ this._sortSamples(); |
this._normalizeTimestamps(); |
this._buildIdToNodeMap(); |
this._fixMissingSamples(); |
@@ -156,6 +157,34 @@ WebInspector.CPUProfileDataModel.prototype = { |
} |
}, |
+ _sortSamples: function() |
+ { |
+ var timestamps = this.timestamps; |
+ if (!timestamps) |
+ return; |
+ var samples = this.samples; |
+ var indices = timestamps.map((x, index) => index); |
+ indices.sort((a, b) => timestamps[a] - timestamps[b]); |
+ for (var i = 0; i < timestamps.length; ++i) { |
+ var index = indices[i]; |
+ if (index === i) |
+ continue; |
+ // Move items in a cycle. |
+ var savedTimestamp = timestamps[i]; |
+ var savedSample = samples[i]; |
+ var currentIndex = i; |
+ while (index !== i) { |
+ samples[currentIndex] = samples[index]; |
+ timestamps[currentIndex] = timestamps[index]; |
+ currentIndex = index; |
+ index = indices[index]; |
+ indices[currentIndex] = currentIndex; |
+ } |
+ samples[currentIndex] = savedSample; |
+ timestamps[currentIndex] = savedTimestamp; |
+ } |
+ }, |
+ |
_normalizeTimestamps: function() |
{ |
var timestamps = this.timestamps; |