diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 19:59:36 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 19:59:36 +0000 |
commit | 60c4c41ce3ed1fa0697daf274233d84febf6233c (patch) | |
tree | 7b6bfe29f7b6526b4c63ce49ab7a7ffcd20d3bbf /net/base/load_log.cc | |
parent | 3203c5e35bba5266fe1d149875c3a9815ee9c214 (diff) | |
download | chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.zip chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.tar.gz chromium_src-60c4c41ce3ed1fa0697daf274233d84febf6233c.tar.bz2 |
Improve the display of LoadLogs when truncation occurs.
Rather than drop all subsequent entries, we now preserve the final entry that was appended to the log.
This way, even if entries have been dropped, we can still infer what the total time was, and what the exit condition was.
Also makes LoadLog take the bound as a required parameter.
BUG=none
TEST=LoadLogUtilTest.DisplayOfTruncated
Review URL: http://codereview.chromium.org/363025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/load_log.cc')
-rw-r--r-- | net/base/load_log.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/net/base/load_log.cc b/net/base/load_log.cc index 42b1b85f..451d4e3 100644 --- a/net/base/load_log.cc +++ b/net/base/load_log.cc @@ -3,10 +3,13 @@ // found in the LICENSE file. #include "net/base/load_log.h" +#include "base/logging.h" namespace net { -LoadLog::LoadLog() { +LoadLog::LoadLog(size_t max_num_entries) + : num_entries_truncated_(0), max_num_entries_(max_num_entries) { + DCHECK_GT(max_num_entries, 0u); } // static @@ -22,20 +25,24 @@ const char* LoadLog::EventTypeToString(EventType event) { void LoadLog::Add(const Event& event) { // Minor optimization. TODO(eroman): use StackVector instead. if (events_.empty()) - events_.reserve(kMaxNumEntries / 2); + events_.reserve(10); // It is likely we will have at least 10 entries. - // Enforce a bound of kMaxNumEntries -- when we reach it, make it so the - // final entry in the list is |TYPE_LOG_TRUNCATED|. + // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting + // the final entry in the log. - if (events_.size() + 1 == kMaxNumEntries) - events_.push_back(Event(event.time, TYPE_LOG_TRUNCATED, PHASE_NONE)); - else if (events_.size() < kMaxNumEntries) + if (events_.size() + 1 <= max_num_entries_ || + max_num_entries_ == kUnbounded) { events_.push_back(event); + } else { + num_entries_truncated_ += 1; + events_[max_num_entries_ - 1] = event; + } } void LoadLog::Append(const LoadLog* log) { for (size_t i = 0; i < log->events().size(); ++i) Add(log->events()[i]); + num_entries_truncated_ += log->num_entries_truncated(); } } // namespace net |