| 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 #ifndef NET_BASE_LOAD_LOG_H_ | 5 #ifndef NET_BASE_LOAD_LOG_H_ |
| 6 #define NET_BASE_LOAD_LOG_H_ | 6 #define NET_BASE_LOAD_LOG_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "base/time.h" |
| 9 | 12 |
| 10 namespace net { | 13 namespace net { |
| 11 | 14 |
| 12 // LoadLog stores profiling information on where time was spent while servicing | 15 // LoadLog stores profiling information on where time was spent while servicing |
| 13 // a request (waiting in queues, resolving hosts, resolving proxy, etc...). | 16 // a request (waiting in queues, resolving hosts, resolving proxy, etc...). |
| 14 class LoadLog : public base::RefCounted<LoadLog> { | 17 class LoadLog : public base::RefCounted<LoadLog> { |
| 15 public: | 18 public: |
| 16 // TODO(eroman): Add an API similar to: | 19 |
| 17 // void TrackEnterState(LoadState state); | 20 enum EventType { |
| 18 // void TrackLeaveState(LoadState state); | 21 #define EVENT_TYPE(label) TYPE_ ## label, |
| 19 // void Merge(const LoadLog* other); | 22 #include "net/base/load_log_event_type_list.h" |
| 23 #undef EVENT_TYPE |
| 24 }; |
| 25 |
| 26 // Whether this is the start/end of an event. Or in the case of EventTypes |
| 27 // that are "instantaneous", kNone. |
| 28 enum EventPhase { |
| 29 PHASE_NONE, |
| 30 PHASE_BEGIN, |
| 31 PHASE_END, |
| 32 }; |
| 33 |
| 34 // A logged event. Note that "phase" means if this is the start/end of a |
| 35 // particular event type (in order to record a timestamp for both endpoints). |
| 36 struct Event { |
| 37 Event(base::TimeTicks time, |
| 38 EventType type, |
| 39 EventPhase phase) |
| 40 : time(time), type(type), phase(phase) { |
| 41 } |
| 42 |
| 43 base::TimeTicks time; |
| 44 EventType type; |
| 45 EventPhase phase; |
| 46 }; |
| 47 |
| 48 // The maximum size of |events_|. |
| 49 enum { kMaxNumEntries = 25 }; |
| 50 |
| 51 // Ordered set of events that were logged. |
| 52 // TODO(eroman): use a StackVector or array to avoid allocations. |
| 53 typedef std::vector<Event> EventList; |
| 54 |
| 55 // Create a log, which can hold up to |kMaxNumEntries| Events. |
| 56 // |
| 57 // If events are dropped because the log has grown too large, the final |
| 58 // entry will be of type kLogTruncated. |
| 59 LoadLog(); |
| 60 |
| 61 // -------------------------------------------------------------------------- |
| 62 |
| 63 // The public interface for adding events to the log are static methods. |
| 64 // This makes it easier to deal with optionally NULL LoadLog. |
| 65 |
| 66 // Adds an instantaneous event to the log. |
| 67 static void AddEvent(LoadLog* log, EventType event) { |
| 68 if (log) |
| 69 log->Add(base::TimeTicks::Now(), event, PHASE_NONE); |
| 70 } |
| 71 |
| 72 // Adds the start of an event to the log. Presumably this event type measures |
| 73 // a time duration, and will be matched by a call to EndEvent(event). |
| 74 static void BeginEvent(LoadLog* log, EventType event) { |
| 75 if (log) |
| 76 log->Add(base::TimeTicks::Now(), event, PHASE_BEGIN); |
| 77 } |
| 78 |
| 79 // Adds the end of an event to the log. Presumably this event type measures |
| 80 // a time duration, and we are matching an earlier call to BeginEvent(event). |
| 81 static void EndEvent(LoadLog* log, EventType event) { |
| 82 if (log) |
| 83 log->Add(base::TimeTicks::Now(), event, PHASE_END); |
| 84 } |
| 85 |
| 86 // -------------------------------------------------------------------------- |
| 87 |
| 88 // Returns the list of all events in the log. |
| 89 const EventList& events() const { |
| 90 return events_; |
| 91 } |
| 92 |
| 93 // Returns a C-String symbolic name for |event|. |
| 94 static const char* EventTypeToString(EventType event); |
| 95 |
| 96 void Add(base::TimeTicks t, EventType event, EventPhase phase); |
| 97 |
| 98 private: |
| 99 EventList events_; |
| 20 }; | 100 }; |
| 21 | 101 |
| 22 } // namespace net | 102 } // namespace net |
| 23 | 103 |
| 24 #endif // NET_BASE_LOAD_LOG_H_ | 104 #endif // NET_BASE_LOAD_LOG_H_ |
| OLD | NEW |