diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 03:03:35 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 03:03:35 +0000 |
commit | cb86d7621c5c56095cb851431c7a48178a1af0c7 (patch) | |
tree | fd4e20d71bf4f971f48e7048b3139377b752c38d | |
parent | 40982aac582184c7ccdd8f994cec5837fe6c0d84 (diff) | |
download | chromium_src-cb86d7621c5c56095cb851431c7a48178a1af0c7.zip chromium_src-cb86d7621c5c56095cb851431c7a48178a1af0c7.tar.gz chromium_src-cb86d7621c5c56095cb851431c7a48178a1af0c7.tar.bz2 |
Misc changes to about:tracking2.
- Remove the '?' link which explained search syntax.
- Simplified the search syntax to just be substrings (no longer supports arbitrary javascript expressions)
- Fixed the filter functionality to properly match numeric substrings (before it was matching the underlying decimal value so numeric matches could be weird; now it matches the same text as is being displayed).
- No longer displays PID numbers using comma separators.
- Removed the href=# from the "Edit columns" link as this was changing the page's location and causing issues with refresh.
Review URL: http://codereview.chromium.org/8511033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109375 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/resources/tracking.html | 33 | ||||
-rw-r--r-- | chrome/browser/resources/tracking.js | 164 |
2 files changed, 90 insertions, 107 deletions
diff --git a/chrome/browser/resources/tracking.html b/chrome/browser/resources/tracking.html index db05db3..20b338d 100644 --- a/chrome/browser/resources/tracking.html +++ b/chrome/browser/resources/tracking.html @@ -70,6 +70,13 @@ table.results-table, margin-bottom: 1ex; } +/* Pseudo-link which toggles display of columns checkboxes */ +#edit-columns-link { + color: blue; + cursor: pointer; + text-decoration: underline; +} + </style> </head> <body> @@ -80,37 +87,13 @@ table.results-table, <b>Sort by: </b> <span id=sort-by-container></span> </td> <td align=right> - <a href=# id=edit-columns-link>[Edit columns]</a> + <a id=edit-columns-link>[Edit columns]</a> <input type='search' incremental id='filter-search' /> - <a href='#' id=filter-help-link>?</a> </td> </tr> <tr id=edit-columns-row style='display:none'> <td colspan=2 id=column-toggles-container></td> </tr> - <tr id=filter-help-container style='display:none'> - <td colspan=2> - <div style='border: 1px dashed black; padding: 1em'> - <p>You can filter elements either by entering a case insensitive - substring to match, or by entering a javascript boolean expression - (solved using 'eval()').</p> - <u>Examples:</u> - <ul> - <li> - <pre style='display:inline'>BrowserWatchdog</pre> - </li> - <li> - <pre style='display:inline'>browser/net/sqlite</pre> - </li> - <li> - <pre style='display:inline'>(x.avg_queue_ms > 0.5 || x.death_data.count > 1000) && x.birth_thread == 'CrBrowserMain'</pre> - </li> - </ul> - <u>All property names:</u> - <ul id='filter-help-property-names-ul'></ul> - </div> - </td> - </tr> </table> <hr/> diff --git a/chrome/browser/resources/tracking.js b/chrome/browser/resources/tracking.js index 4412ddc..6b65e59 100644 --- a/chrome/browser/resources/tracking.js +++ b/chrome/browser/resources/tracking.js @@ -5,9 +5,6 @@ var g_browserBridge; var g_mainView; -// TODO(eroman): Don't comma-separate PID numbers (since they aren't -// really quantities). - /** * Main entry point called once the page has loaded. */ @@ -85,18 +82,6 @@ var MainView = (function() { // The container node to put all the column checkboxes into. var COLUMN_TOGGLES_CONTAINER_ID = 'column-toggles-container'; - // The anchor node that toggles the filter help. - var FILTER_HELP_LINK_ID = 'filter-help-link'; - - // The container node where the (initially hidden) filter help text is - // drawn into. - var FILTER_HELP_CONTAINER_ID = 'filter-help-container'; - - // The UL which should be filled with each of the key names. This is - // used by the filter help text to identify what value property names - // are. - var FILTER_HELP_PROPERTY_NAMES_UL = 'filter-help-property-names-ul'; - // The anchor which toggles visibility of column checkboxes. var EDIT_COLUMNS_LINK_ID = 'edit-columns-link'; @@ -276,24 +261,49 @@ var MainView = (function() { * expected to be numeric or is a string, a descriptive name (title) for the * property, and what function should be used to aggregate the property when * displayed in a column. + * + * -------------------------------------- + * The following properties are required: + * -------------------------------------- + * + * [name]: This is displayed as the column's label. + * [aggregator]: Aggregator factory that is used to compute an aggregate + * value for this column. + * + * -------------------------------------- + * The following properties are optional: + * -------------------------------------- + * + * [inputJsonKey]: The corresponding key for this property in the original + * JSON dictionary received from the browser. If this is + * present, values for this key will be automatically + * populated during import. + * [comparator]: A comparator function for sorting this column. + * [textPrinter]: A function that transforms values into the user-displayed + * text shown in the UI. If unspecified, will default to the + * "toString()" function. + * [cellAlignment]: The horizonal alignment to use for columns of this + * property (for instance 'right'). If unspecified will + * default to left alignment. + * [sortDescending]: When first clicking on this column, we will default to + * sorting by |comparator| in ascending order. If this + * property is true, we will reverse that to descending. */ var KEY_PROPERTIES = []; KEY_PROPERTIES[KEY_PROCESS_ID] = { name: 'PID', - type: 'number', + cellAlignment: 'right', aggregator: UniquifyAggregator, }; KEY_PROPERTIES[KEY_PROCESS_TYPE] = { name: 'Process type', - type: 'string', aggregator: UniquifyAggregator, }; KEY_PROPERTIES[KEY_BIRTH_THREAD] = { name: 'Birth thread', - type: 'string', inputJsonKey: 'birth_thread', aggregator: UniquifyAggregator, comparator: threadNameComparator, @@ -301,7 +311,6 @@ var MainView = (function() { KEY_PROPERTIES[KEY_DEATH_THREAD] = { name: 'Exec thread', - type: 'string', inputJsonKey: 'death_thread', aggregator: UniquifyAggregator, comparator: threadNameComparator, @@ -309,69 +318,81 @@ var MainView = (function() { KEY_PROPERTIES[KEY_FUNCTION_NAME] = { name: 'Function name', - type: 'string', inputJsonKey: 'location.function_name', aggregator: UniquifyAggregator, }; KEY_PROPERTIES[KEY_FILE_NAME] = { name: 'File name', - type: 'string', inputJsonKey: 'location.file_name', aggregator: UniquifyAggregator, }; KEY_PROPERTIES[KEY_LINE_NUMBER] = { name: 'Line number', - type: 'number', + cellAlignment: 'right', inputJsonKey: 'location.line_number', aggregator: UniquifyAggregator, }; KEY_PROPERTIES[KEY_COUNT] = { name: 'Count', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, inputJsonKey: 'death_data.count', aggregator: SumAggregator, }; KEY_PROPERTIES[KEY_QUEUE_TIME] = { name: 'Total queue time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, inputJsonKey: 'death_data.queue_ms', aggregator: SumAggregator, }; KEY_PROPERTIES[KEY_MAX_QUEUE_TIME] = { name: 'Max queue time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, inputJsonKey: 'death_data.queue_ms_max', aggregator: MaxAggregator, }; KEY_PROPERTIES[KEY_RUN_TIME] = { name: 'Total run time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, inputJsonKey: 'death_data.run_ms', aggregator: SumAggregator, }; KEY_PROPERTIES[KEY_AVG_RUN_TIME] = { name: 'Avg run time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, aggregator: AvgAggregator.create(KEY_RUN_TIME, KEY_COUNT), }; KEY_PROPERTIES[KEY_MAX_RUN_TIME] = { name: 'Max run time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, inputJsonKey: 'death_data.run_ms_max', aggregator: MaxAggregator, }; KEY_PROPERTIES[KEY_AVG_QUEUE_TIME] = { name: 'Avg queue time', - type: 'number', + cellAlignment: 'right', + sortDescending: true, + textPrinter: formatNumberAsText, aggregator: AvgAggregator.create(KEY_QUEUE_TIME, KEY_COUNT), }; @@ -795,24 +816,25 @@ var MainView = (function() { } } + function getTextValueForProperty(key, value) { + var textPrinter = KEY_PROPERTIES[key].textPrinter; + if (textPrinter) + return textPrinter(value); + return value.toString(); + } + /** * Renders the property value |value| into cell |td|. The name of this * property is |key|. */ function drawValueToCell(td, key, value) { - // Lookup the expected type of this property. - var isNumeric = KEY_PROPERTIES[key].type == 'number'; + // Get a text representation of the value. + var text = getTextValueForProperty(key, value); - if (isNumeric) { - // Numbers should be aligned to the right. - td.align = 'right'; - } - - // Truncate numbers to integers. Also add comma separators for readability. - if (isNumeric) { - td.innerText = formatNumberAsText(value); - return; - } + // Apply the desired cell alignment. + var cellAlignment = KEY_PROPERTIES[key].cellAlignment; + if (cellAlignment) + td.align = cellAlignment; // String values can get pretty long. If the string contains no spaces, then // CSS fails to wrap it, and it overflows the cell causing the table to get @@ -821,10 +843,10 @@ var MainView = (function() { // value, and hence avoid it overflowing! var kMinLengthBeforeWrap = 20; - addText(td, value.substr(0, kMinLengthBeforeWrap)); - for (var i = kMinLengthBeforeWrap; i < value.length; ++i) { + addText(td, text.substr(0, kMinLengthBeforeWrap)); + for (var i = kMinLengthBeforeWrap; i < text.length; ++i) { addNode(td, 'wbr'); - addText(td, value.substr(i, 1)); + addText(td, text.substr(i, 1)); } } @@ -1041,17 +1063,8 @@ var MainView = (function() { this.fillSortingDropdowns_(); $(EDIT_COLUMNS_LINK_ID).onclick = this.toggleEditColumns_.bind(this); - - // Hook up the filter help section. - $(FILTER_HELP_LINK_ID).onclick = this.toggleFilterHelp_.bind(this); - var propsUl = $(FILTER_HELP_PROPERTY_NAMES_UL); - propsUl = $(FILTER_HELP_PROPERTY_NAMES_UL); - for (var k = BEGIN_KEY; k < END_KEY; ++k) - addNode(propsUl, 'li', k); }, - // TODO(eroman): This is basically the same as toggleFilterHelp(); - // extract to helper. toggleEditColumns_: function() { var n = $(EDIT_COLUMNS_ROW); if (n.style.display == '') { @@ -1061,15 +1074,6 @@ var MainView = (function() { } }, - toggleFilterHelp_: function() { - var n = $(FILTER_HELP_CONTAINER_ID); - if (n.style.display == '') { - n.style.display = 'none'; - } else { - n.style.display = ''; - } - }, - fillSelectionCheckboxes_: function(parent) { this.selectionCheckboxes_ = {}; @@ -1153,9 +1157,9 @@ var MainView = (function() { * order. */ onClickColumn_: function(key, event) { - // For numeric properties default to a descending order, since that is - // generally more useful. - if (KEY_PROPERTIES[key].type == 'number') + // If this property wants to start off in descending order rather then + // ascending, flip it. + if (KEY_PROPERTIES[key].sortDescending) key = reverseSortKey(key); // Scan through our sort order and see if we are already sorted on this @@ -1244,29 +1248,25 @@ var MainView = (function() { }, getFilterFunction_: function() { - var text = $(FILTER_SEARCH_ID).value; - text = trimWhitespace(text); + var searchStr = $(FILTER_SEARCH_ID).value; + + // Normalize the search expression. + searchStr = trimWhitespace(searchStr); + searchStr = searchStr.toLowerCase(); return function(x) { - if (text == '') + // Match everything when there was no filter. + if (searchStr == '') return true; - if (text.indexOf('x.') != -1) { - // To be a javascript expression, it must have be testing something on - // |x|... - try { - var result = eval(text); - if (typeof result == 'boolean') - return result; - } catch (e) { - // Do nothing, we will fall back to substring search. - } + // Treat the search text as a LOWERCASE substring search. + for (var k = BEGIN_KEY; k < END_KEY; ++k) { + var propertyText = getTextValueForProperty(k, x[k]); + if (propertyText.toLowerCase().indexOf(searchStr) != -1) + return true; } - // Interpret the query as a substring search (case insensitive) - // TODO(eromn): Don't search through the JSON. - return JSON.stringify(x).toLowerCase().indexOf( - text.toLowerCase()) != -1; + return false; }; }, |