OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(eroman): put these methods into a namespace. | 5 // TODO(eroman): put these methods into a namespace. |
6 | 6 |
7 var printLogEntriesAsText; | 7 var printLogEntriesAsText; |
8 var proxySettingsToString; | 8 var proxySettingsToString; |
9 var stripCookiesAndLoginInfo; | 9 var stripCookiesAndLoginInfo; |
10 | 10 |
11 // Start of anonymous namespace. | 11 // Start of anonymous namespace. |
12 (function() { | 12 (function() { |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 function canCollapseBeginWithEnd(beginEntry) { | 15 function canCollapseBeginWithEnd(beginEntry) { |
16 return beginEntry && | 16 return beginEntry && |
17 beginEntry.isBegin() && | 17 beginEntry.isBegin() && |
18 beginEntry.end && | 18 beginEntry.end && |
19 beginEntry.end.index == beginEntry.index + 1 && | 19 beginEntry.end.index == beginEntry.index + 1 && |
20 (!beginEntry.orig.params || !beginEntry.end.orig.params); | 20 (!beginEntry.orig.params || !beginEntry.end.orig.params); |
21 } | 21 } |
22 | 22 |
23 /** | 23 /** |
24 * Adds a child pre element to the end of |parent|, and writes the | 24 * Adds a child pre element to the end of |parent|, and writes the |
25 * formatted contents of |logEntries| to it. | 25 * formatted contents of |logEntries| to it. |
26 */ | 26 */ |
27 printLogEntriesAsText = function(logEntries, parent, enableSecurityStripping) { | 27 printLogEntriesAsText = function(logEntries, parent, enableSecurityStripping, |
| 28 logCreationTime) { |
28 var entries = LogGroupEntry.createArrayFrom(logEntries); | 29 var entries = LogGroupEntry.createArrayFrom(logEntries); |
29 var tablePrinter = new TablePrinter(); | 30 var tablePrinter = new TablePrinter(); |
30 var parameterOutputter = new ParameterOutputter(tablePrinter); | 31 var parameterOutputter = new ParameterOutputter(tablePrinter); |
31 | 32 |
32 if (entries.length == 0) | 33 if (entries.length == 0) |
33 return; | 34 return; |
34 | 35 |
35 var startDate = timeutil.convertTimeTicksToDate(entries[0].orig.time); | 36 var startTime = timeutil.convertTimeTicksToTime(entries[0].orig.time); |
36 var startTime = startDate.getTime(); | |
37 | 37 |
38 for (var i = 0; i < entries.length; ++i) { | 38 for (var i = 0; i < entries.length; ++i) { |
39 var entry = entries[i]; | 39 var entry = entries[i]; |
40 | 40 |
41 // Avoid printing the END for a BEGIN that was immediately before, unless | 41 // Avoid printing the END for a BEGIN that was immediately before, unless |
42 // both have extra parameters. | 42 // both have extra parameters. |
43 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { | 43 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { |
44 tablePrinter.addRow(); | 44 var entryTime = timeutil.convertTimeTicksToTime(entry.orig.time); |
45 | 45 addRowWithTime(tablePrinter, entryTime, startTime); |
46 tablePrinter.addCell('t='); | |
47 var date = timeutil.convertTimeTicksToDate(entry.orig.time); | |
48 var tCell = tablePrinter.addCell(date.getTime()); | |
49 tCell.alignRight = true; | |
50 tablePrinter.addCell(' [st='); | |
51 var stCell = tablePrinter.addCell(date.getTime() - startTime); | |
52 stCell.alignRight = true; | |
53 tablePrinter.addCell('] '); | |
54 | 46 |
55 for (var j = entry.getDepth(); j > 0; --j) | 47 for (var j = entry.getDepth(); j > 0; --j) |
56 tablePrinter.addCell(' '); | 48 tablePrinter.addCell(' '); |
57 | 49 |
58 var eventText = getTextForEvent(entry); | 50 var eventText = getTextForEvent(entry); |
59 // Get the elapsed time, and append it to the event text. | 51 // Get the elapsed time, and append it to the event text. |
60 if (entry.isBegin()) { | 52 if (entry.isBegin()) { |
61 var dt = '?'; | 53 var dt = '?'; |
62 // Definite time. | 54 // Definite time. |
63 if (entry.end) { | 55 if (entry.end) { |
64 dt = entry.end.orig.time - entry.orig.time; | 56 dt = entry.end.orig.time - entry.orig.time; |
| 57 } else if (logCreationTime != undefined) { |
| 58 dt = (logCreationTime - entryTime) + '+'; |
65 } | 59 } |
66 eventText += ' [dt=' + dt + ']'; | 60 eventText += ' [dt=' + dt + ']'; |
67 } | 61 } |
68 | 62 |
69 var mainCell = tablePrinter.addCell(eventText); | 63 var mainCell = tablePrinter.addCell(eventText); |
70 mainCell.allowOverflow = true; | 64 mainCell.allowOverflow = true; |
71 } | 65 } |
72 | 66 |
73 // Output the extra parameters. | 67 // Output the extra parameters. |
74 if (typeof entry.orig.params == 'object') { | 68 if (typeof entry.orig.params == 'object') { |
75 // Those 5 skipped cells are: two for "t=", and three for "st=". | 69 // Those 5 skipped cells are: two for "t=", and three for "st=". |
76 tablePrinter.setNewRowCellIndent(5 + entry.getDepth()); | 70 tablePrinter.setNewRowCellIndent(5 + entry.getDepth()); |
77 writeParameters(entry.orig, enableSecurityStripping, parameterOutputter); | 71 writeParameters(entry.orig, enableSecurityStripping, parameterOutputter); |
78 | 72 |
79 tablePrinter.setNewRowCellIndent(0); | 73 tablePrinter.setNewRowCellIndent(0); |
80 } | 74 } |
81 } | 75 } |
82 | 76 |
| 77 // If viewing a saved log file, add row with just the time the log was |
| 78 // created, if the event never completed. |
| 79 if (logCreationTime != undefined && |
| 80 entries[entries.length - 1].getDepth() > 0) { |
| 81 addRowWithTime(tablePrinter, logCreationTime, startTime); |
| 82 } |
| 83 |
83 // Format the table for fixed-width text. | 84 // Format the table for fixed-width text. |
84 tablePrinter.toText(0, parent); | 85 tablePrinter.toText(0, parent); |
85 } | 86 } |
86 | 87 |
87 /** | 88 /** |
| 89 * Adds a new row to the given TablePrinter, and adds five cells containing |
| 90 * information about the time an event occured. |
| 91 * Format is '[t=<UTC time in ms>] [st=<ms since the source started>]'. |
| 92 * @param {TablePrinter} tablePrinter The table printer to add the cells to. |
| 93 * @param {number} eventTime The time the event occured, as a UTC time in |
| 94 * milliseconds. |
| 95 * @param {number} startTime The time the first event for the source occured, |
| 96 * as a UTC time in milliseconds. |
| 97 */ |
| 98 function addRowWithTime(tablePrinter, eventTime, startTime) { |
| 99 tablePrinter.addRow(); |
| 100 tablePrinter.addCell('t='); |
| 101 var tCell = tablePrinter.addCell(eventTime); |
| 102 tCell.alignRight = true; |
| 103 tablePrinter.addCell(' [st='); |
| 104 var stCell = tablePrinter.addCell(eventTime - startTime); |
| 105 stCell.alignRight = true; |
| 106 tablePrinter.addCell('] '); |
| 107 } |
| 108 |
| 109 /** |
88 * |hexString| must be a string of hexadecimal characters with no whitespace, | 110 * |hexString| must be a string of hexadecimal characters with no whitespace, |
89 * whose length is a multiple of two. Writes multiple lines to |out| with | 111 * whose length is a multiple of two. Writes multiple lines to |out| with |
90 * the hexadecimal characters from |hexString| on the left, in groups of | 112 * the hexadecimal characters from |hexString| on the left, in groups of |
91 * two, and their corresponding ASCII characters on the right. | 113 * two, and their corresponding ASCII characters on the right. |
92 * | 114 * |
93 * |asciiCharsPerLine| specifies how many ASCII characters will be put on each | 115 * |asciiCharsPerLine| specifies how many ASCII characters will be put on each |
94 * line of the output string. | 116 * line of the output string. |
95 */ | 117 */ |
96 function writeHexString(hexString, asciiCharsPerLine, out) { | 118 function writeHexString(hexString, asciiCharsPerLine, out) { |
97 // Number of transferred bytes in a line of output. Length of a | 119 // Number of transferred bytes in a line of output. Length of a |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 628 |
607 if (config.source != undefined && config.source != 'UNKNOWN') | 629 if (config.source != undefined && config.source != 'UNKNOWN') |
608 result.push('Source: ' + config.source); | 630 result.push('Source: ' + config.source); |
609 | 631 |
610 return result.join('\n'); | 632 return result.join('\n'); |
611 }; | 633 }; |
612 | 634 |
613 // End of anonymous namespace. | 635 // End of anonymous namespace. |
614 })(); | 636 })(); |
615 | 637 |
OLD | NEW |