Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Side by Side Diff: net/base/load_log.cc

Issue 363025: Improve the display of LoadLogs when truncation occurs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Change -1 to be a constant instead Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/load_log.h ('k') | net/base/load_log_event_type_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "net/base/load_log.h"
6 #include "base/logging.h"
6 7
7 namespace net { 8 namespace net {
8 9
9 LoadLog::LoadLog() { 10 LoadLog::LoadLog(size_t max_num_entries)
11 : num_entries_truncated_(0), max_num_entries_(max_num_entries) {
12 DCHECK_GT(max_num_entries, 0u);
10 } 13 }
11 14
12 // static 15 // static
13 const char* LoadLog::EventTypeToString(EventType event) { 16 const char* LoadLog::EventTypeToString(EventType event) {
14 switch (event) { 17 switch (event) {
15 #define EVENT_TYPE(label) case TYPE_ ## label: return #label; 18 #define EVENT_TYPE(label) case TYPE_ ## label: return #label;
16 #include "net/base/load_log_event_type_list.h" 19 #include "net/base/load_log_event_type_list.h"
17 #undef EVENT_TYPE 20 #undef EVENT_TYPE
18 } 21 }
19 return NULL; 22 return NULL;
20 } 23 }
21 24
22 void LoadLog::Add(const Event& event) { 25 void LoadLog::Add(const Event& event) {
23 // Minor optimization. TODO(eroman): use StackVector instead. 26 // Minor optimization. TODO(eroman): use StackVector instead.
24 if (events_.empty()) 27 if (events_.empty())
25 events_.reserve(kMaxNumEntries / 2); 28 events_.reserve(10); // It is likely we will have at least 10 entries.
26 29
27 // Enforce a bound of kMaxNumEntries -- when we reach it, make it so the 30 // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting
28 // final entry in the list is |TYPE_LOG_TRUNCATED|. 31 // the final entry in the log.
29 32
30 if (events_.size() + 1 == kMaxNumEntries) 33 if (events_.size() + 1 <= max_num_entries_ ||
31 events_.push_back(Event(event.time, TYPE_LOG_TRUNCATED, PHASE_NONE)); 34 max_num_entries_ == kUnbounded) {
32 else if (events_.size() < kMaxNumEntries)
33 events_.push_back(event); 35 events_.push_back(event);
36 } else {
37 num_entries_truncated_ += 1;
38 events_[max_num_entries_ - 1] = event;
39 }
34 } 40 }
35 41
36 void LoadLog::Append(const LoadLog* log) { 42 void LoadLog::Append(const LoadLog* log) {
37 for (size_t i = 0; i < log->events().size(); ++i) 43 for (size_t i = 0; i < log->events().size(); ++i)
38 Add(log->events()[i]); 44 Add(log->events()[i]);
45 num_entries_truncated_ += log->num_entries_truncated();
39 } 46 }
40 47
41 } // namespace net 48 } // namespace net
OLDNEW
« no previous file with comments | « net/base/load_log.h ('k') | net/base/load_log_event_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698