OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "net/base/load_log_util.h" | 5 #include "net/base/load_log_util.h" |
6 | 6 |
| 7 #include "base/format_macros.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 | 9 |
9 namespace net { | 10 namespace net { |
10 namespace { | 11 namespace { |
11 | 12 |
12 class FormatHelper { | 13 class FormatHelper { |
13 public: | 14 public: |
14 std::string ToString(const LoadLog* log) { | 15 std::string ToString(const LoadLog* log) { |
15 entries_.clear(); | 16 entries_.clear(); |
16 | 17 |
17 // Pass 1: Match the start/end of indentation blocks. Fills |entries_| | 18 // Pass 1: Match the start/end of indentation blocks. Fills |entries_| |
18 // with the results. | 19 // with the results. |
19 PopulateEntries(log); | 20 PopulateEntries(log); |
20 | 21 |
21 // Pass 2: Figure out the maximum width of each column. This allows us | 22 // Pass 2: Figure out the maximum width of each column. This allows us |
22 // to right-justify text within each column. | 23 // to right-justify text within each column. |
23 size_t max_time_width, max_indentation, max_type_width, max_dt_width; | 24 size_t max_time_width, max_indentation, max_type_width, max_dt_width; |
24 GetMaxExtent( | 25 GetMaxExtent( |
25 &max_time_width, &max_indentation, &max_type_width, &max_dt_width); | 26 &max_time_width, &max_indentation, &max_type_width, &max_dt_width); |
26 | 27 |
27 // Pass 3: Assemble the string. | 28 // Pass 3: Assemble the string. |
28 std::string result; | 29 std::string result; |
29 | 30 |
30 const int kSpacesPerIndentation = 2; | 31 const int kSpacesPerIndentation = 2; |
31 | 32 |
32 for (size_t i = 0; i < entries_.size(); ++i) { | 33 for (size_t i = 0; i < entries_.size(); ++i) { |
33 if (log->num_entries_truncated() > 0 && i + 1 == entries_.size()) { | 34 if (log->num_entries_truncated() > 0 && i + 1 == entries_.size()) { |
34 result += StringPrintf(" ... Truncated %d entries ...\n", | 35 result += StringPrintf(" ... Truncated %" PRIuS " entries ...\n", |
35 log->num_entries_truncated()); | 36 log->num_entries_truncated()); |
36 } | 37 } |
37 | 38 |
38 if (entries_[i].block_index != -1 && | 39 if (entries_[i].block_index != -1 && |
39 static_cast<size_t>(entries_[i].block_index + 1) == i) { | 40 static_cast<size_t>(entries_[i].block_index + 1) == i) { |
40 // If there were no entries in between the START/END block then don't | 41 // If there were no entries in between the START/END block then don't |
41 // bother printing a line for END (it just adds noise, and we already | 42 // bother printing a line for END (it just adds noise, and we already |
42 // show the time delta besides START anyway). | 43 // show the time delta besides START anyway). |
43 continue; | 44 continue; |
44 } | 45 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 194 |
194 } // namespace | 195 } // namespace |
195 | 196 |
196 // static | 197 // static |
197 std::string LoadLogUtil::PrettyPrintAsEventTree(const LoadLog* log) { | 198 std::string LoadLogUtil::PrettyPrintAsEventTree(const LoadLog* log) { |
198 FormatHelper helper; | 199 FormatHelper helper; |
199 return helper.ToString(log); | 200 return helper.ToString(log); |
200 } | 201 } |
201 | 202 |
202 } // namespace net | 203 } // namespace net |
OLD | NEW |