| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Factory function to create a View for seeing profiling events as a flat list. | |
| 7 */ | |
| 8 var CreateListView; | |
| 9 | |
| 10 // ----------------------------------------------------------------------------- | |
| 11 // Private implementation | |
| 12 // ----------------------------------------------------------------------------- | |
| 13 | |
| 14 (function() { | |
| 15 | |
| 16 CreateListView = function(filters, entries) { | |
| 17 return new ListView(filters, entries); | |
| 18 }; | |
| 19 | |
| 20 function ListView(filters, entries) { | |
| 21 this.parent_ = document.getElementById("list_container"); | |
| 22 this.entries_ = entries; | |
| 23 this.filters_ = filters; | |
| 24 this.headers_ = [ | |
| 25 "timestamp", | |
| 26 "domain", | |
| 27 "executable", | |
| 28 "first_arg", | |
| 29 "platform", | |
| 30 "duration" | |
| 31 ]; | |
| 32 this.titles_ = [ | |
| 33 "Timestamp", | |
| 34 "Domain", | |
| 35 "Executable", | |
| 36 "First arg", | |
| 37 "Platform", | |
| 38 "Duration (s)" | |
| 39 ]; | |
| 40 this.Draw(this.headers_[0]); | |
| 41 } | |
| 42 | |
| 43 ListView.prototype.OnShow = function(visible) { | |
| 44 }; | |
| 45 | |
| 46 /** | |
| 47 * Sort by |viewName| to be the active view. | |
| 48 * @param {string} viewName | |
| 49 */ | |
| 50 ListView.prototype.SortBy = function(current_sort) { | |
| 51 ClassUtil.ResetClass("sortBadge", current_sort + "_badge", "Selected"); | |
| 52 this.Draw(current_sort); | |
| 53 }; | |
| 54 | |
| 55 ListView.prototype.Draw = function(current_sort) { | |
| 56 this.SortEntries(current_sort); | |
| 57 this.parent_.innerHTML = ""; | |
| 58 var table = DomUtil.AddNode(this.parent_, "table"); | |
| 59 table.className = "entriesList"; | |
| 60 var thead = DomUtil.AddNode(table, "thead"); | |
| 61 for (var i in this.headers_) { | |
| 62 var extra = ""; | |
| 63 var key = this.headers_[i]; | |
| 64 if (key == current_sort) { | |
| 65 extra = " Selected"; | |
| 66 } | |
| 67 var th = DomUtil.AddNode(thead, "th"); | |
| 68 th.className = "sortBadge" + extra; | |
| 69 th.id = key + "_badge"; | |
| 70 var a = DomUtil.AddNode(th, "a"); | |
| 71 a.onclick = this.SortBy.bind(this, key); | |
| 72 DomUtil.AddText(a, this.titles_[i]); | |
| 73 } | |
| 74 var tbody = DomUtil.AddNode(table, "tbody"); | |
| 75 if (!this.entries_) { | |
| 76 return; | |
| 77 } | |
| 78 for (var i = 0; i < this.entries_.length; ++i) { | |
| 79 var entry = this.entries_[i]; | |
| 80 var tr = DomUtil.AddNode(tbody, "tr"); | |
| 81 var tdTimestamp = DomUtil.AddNode(tr, "td"); | |
| 82 var tdDomain = DomUtil.AddNode(tr, "td"); | |
| 83 var tdExecutable = DomUtil.AddNode(tr, "td"); | |
| 84 var tdFirstArg = DomUtil.AddNode(tr, "td"); | |
| 85 var tdPlatform = DomUtil.AddNode(tr, "td"); | |
| 86 var tdDuration = DomUtil.AddNode(tr, "td"); | |
| 87 | |
| 88 DomUtil.AddText(tdTimestamp, DateUtil.FormatLocaleISO(entry.timestamp)); | |
| 89 DomUtil.AddText(tdDomain, entry.domain); | |
| 90 DomUtil.AddText(tdExecutable, entry.executable); | |
| 91 DomUtil.AddText(tdFirstArg, entry.first_arg); | |
| 92 DomUtil.AddText(tdPlatform, entry.platform); | |
| 93 DomUtil.AddText(tdDuration, entry.duration.toFixed(1)); | |
| 94 } | |
| 95 }; | |
| 96 | |
| 97 ListView.prototype.SortEntries = function (current_sort) { | |
| 98 if (this.entries_ != null) { | |
| 99 this.entries_.sort(function(a, b) { | |
| 100 var lhs = a[current_sort]; | |
| 101 var rhs = b[current_sort]; | |
| 102 if (typeof lhs != typeof rhs) { | |
| 103 throw typeof lhs + " != " + typeof rhs; | |
| 104 } | |
| 105 if (typeof lhs == "number") { | |
| 106 return lhs - rhs; | |
| 107 } | |
| 108 return lhs.toString().localeCompare(rhs.toString()); | |
| 109 }); | |
| 110 } | |
| 111 }; | |
| 112 | |
| 113 })(); // Private implementation. | |
| 114 | |
| 115 CreateListView.display_name = "List view"; | |
| OLD | NEW |