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

Unified Diff: net/base/load_log.h

Issue 165404: Implement LoadLog, and hook up HostResolverImpl to LoadLog.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Do an unsigned/signed thing for GCC compile Created 11 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | net/base/load_log.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/load_log.h
===================================================================
--- net/base/load_log.h (revision 23403)
+++ net/base/load_log.h (working copy)
@@ -5,7 +5,10 @@
#ifndef NET_BASE_LOAD_LOG_H_
#define NET_BASE_LOAD_LOG_H_
+#include <vector>
+
#include "base/ref_counted.h"
+#include "base/time.h"
namespace net {
@@ -13,10 +16,87 @@
// a request (waiting in queues, resolving hosts, resolving proxy, etc...).
class LoadLog : public base::RefCounted<LoadLog> {
public:
-// TODO(eroman): Add an API similar to:
-// void TrackEnterState(LoadState state);
-// void TrackLeaveState(LoadState state);
-// void Merge(const LoadLog* other);
+
+ enum EventType {
+#define EVENT_TYPE(label) TYPE_ ## label,
+#include "net/base/load_log_event_type_list.h"
+#undef EVENT_TYPE
+ };
+
+ // Whether this is the start/end of an event. Or in the case of EventTypes
+ // that are "instantaneous", kNone.
+ enum EventPhase {
+ PHASE_NONE,
+ PHASE_BEGIN,
+ PHASE_END,
+ };
+
+ // A logged event. Note that "phase" means if this is the start/end of a
+ // particular event type (in order to record a timestamp for both endpoints).
+ struct Event {
+ Event(base::TimeTicks time,
+ EventType type,
+ EventPhase phase)
+ : time(time), type(type), phase(phase) {
+ }
+
+ base::TimeTicks time;
+ EventType type;
+ EventPhase phase;
+ };
+
+ // The maximum size of |events_|.
+ enum { kMaxNumEntries = 25 };
+
+ // Ordered set of events that were logged.
+ // TODO(eroman): use a StackVector or array to avoid allocations.
+ typedef std::vector<Event> EventList;
+
+ // Create a log, which can hold up to |kMaxNumEntries| Events.
+ //
+ // If events are dropped because the log has grown too large, the final
+ // entry will be of type kLogTruncated.
+ LoadLog();
+
+ // --------------------------------------------------------------------------
+
+ // The public interface for adding events to the log are static methods.
+ // This makes it easier to deal with optionally NULL LoadLog.
+
+ // Adds an instantaneous event to the log.
+ static void AddEvent(LoadLog* log, EventType event) {
+ if (log)
+ log->Add(base::TimeTicks::Now(), event, PHASE_NONE);
+ }
+
+ // Adds the start of an event to the log. Presumably this event type measures
+ // a time duration, and will be matched by a call to EndEvent(event).
+ static void BeginEvent(LoadLog* log, EventType event) {
+ if (log)
+ log->Add(base::TimeTicks::Now(), event, PHASE_BEGIN);
+ }
+
+ // Adds the end of an event to the log. Presumably this event type measures
+ // a time duration, and we are matching an earlier call to BeginEvent(event).
+ static void EndEvent(LoadLog* log, EventType event) {
+ if (log)
+ log->Add(base::TimeTicks::Now(), event, PHASE_END);
+ }
+
+ // --------------------------------------------------------------------------
+
+ // Returns the list of all events in the log.
+ const EventList& events() const {
+ return events_;
+ }
+
+ // Returns a C-String symbolic name for |event|.
+ static const char* EventTypeToString(EventType event);
+
+ void Add(base::TimeTicks t, EventType event, EventPhase phase);
+
+ private:
+ EventList events_;
};
} // namespace net
« no previous file with comments | « net/base/host_resolver_impl_unittest.cc ('k') | net/base/load_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698