summaryrefslogtreecommitdiffstats
path: root/net/base/load_log.h
diff options
context:
space:
mode:
Diffstat (limited to 'net/base/load_log.h')
-rw-r--r--net/base/load_log.h116
1 files changed, 81 insertions, 35 deletions
diff --git a/net/base/load_log.h b/net/base/load_log.h
index 3f433ac..8553f8b 100644
--- a/net/base/load_log.h
+++ b/net/base/load_log.h
@@ -5,6 +5,7 @@
#ifndef NET_BASE_LOAD_LOG_H_
#define NET_BASE_LOAD_LOG_H_
+#include <string>
#include <vector>
#include "base/ref_counted.h"
@@ -12,53 +13,94 @@
namespace net {
-// LoadLog stores profiling information on where time was spent while servicing
-// a request (waiting in queues, resolving hosts, resolving proxy, etc...).
+// LoadLog stores information associated with an individual request. This
+// includes event traces (used to build up profiling information), error
+// return codes from network modules, and arbitrary text messages.
//
// Note that LoadLog is NOT THREADSAFE, however it is RefCountedThreadSafe so
// that it can be AddRef() / Release() across threads.
class LoadLog : public base::RefCountedThreadSafe<LoadLog> {
public:
+ // TODO(eroman): Really, EventType and EventPhase should be
+ // Event::Type and Event::Phase, to be consisent with Entry.
+ // But there lots of consumers to change!
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.
+ // The 'phase' of an event trace (whether it marks the beginning or end
+ // of an event.).
enum EventPhase {
PHASE_NONE,
PHASE_BEGIN,
+ // TODO(eroman): DEPRECATED: Use TYPE_STRING_LITERAL instead.
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) {
- }
+ Event(EventType type, EventPhase phase) : type(type), phase(phase) {}
+ Event() {}
- base::TimeTicks time;
EventType type;
EventPhase phase;
};
- // Ordered set of events that were logged.
+ struct Entry {
+ enum Type {
+ // This entry describes an event trace.
+ TYPE_EVENT,
+
+ // This entry describes a network error code that was returned.
+ TYPE_ERROR_CODE,
+
+ // This entry is a free-form std::string.
+ TYPE_STRING,
+
+ // This entry is a C-string literal.
+ TYPE_STRING_LITERAL,
+ };
+
+ Entry(base::TimeTicks time, int error_code)
+ : type(TYPE_ERROR_CODE), time(time), error_code(error_code) {
+ }
+
+ Entry(base::TimeTicks time, const Event& event)
+ : type(TYPE_EVENT), time(time), event(event) {
+ }
+
+ Entry(base::TimeTicks time, const std::string& string)
+ : type(TYPE_STRING), time(time), string(string) {
+ }
+
+ Entry(base::TimeTicks time, const char* literal)
+ : type(TYPE_STRING_LITERAL), time(time), literal(literal) {
+ }
+
+ Type type;
+ base::TimeTicks time;
+
+ // The following is basically a union, only one of them should be
+ // used depending on what |type| is.
+ Event event; // valid when (type == TYPE_EVENT).
+ int error_code; // valid when (type == TYPE_ERROR_CODE).
+ std::string string; // valid when (type == TYPE_STRING).
+ const char* literal; // valid when (type == TYPE_STRING_LITERAL).
+ };
+
+ // Ordered set of entries that were logged.
// TODO(eroman): use a StackVector or array to avoid allocations.
- typedef std::vector<Event> EventList;
+ typedef std::vector<Entry> EntryList;
// Value for max_num_entries to indicate the LoadLog has no size limit.
static const size_t kUnbounded = static_cast<size_t>(-1);
- // Creates a log, which can hold up to |max_num_entries| Events.
+ // Creates a log, which can hold up to |max_num_entries| entries.
// If |max_num_entries| is |kUnbounded|, then the log can grow arbitrarily
// large.
//
- // If events are dropped because the log has grown too large, the final entry
+ // If entries are dropped because the log has grown too large, the final entry
// will be overwritten.
explicit LoadLog(size_t max_num_entries);
@@ -68,30 +110,38 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> {
// This makes it easier to deal with optionally NULL LoadLog.
// Adds an instantaneous event to the log.
- static void AddEvent(LoadLog* log, EventType event) {
+ // TODO(eroman): DEPRECATED: use AddStringLiteral() instead.
+ static void AddEvent(LoadLog* log, EventType event_type) {
if (log)
- log->Add(base::TimeTicks::Now(), event, PHASE_NONE);
+ log->Add(Entry(base::TimeTicks::Now(), Event(event_type, 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) {
+ // a time duration, and will be matched by a call to EndEvent(event_type).
+ static void BeginEvent(LoadLog* log, EventType event_type) {
if (log)
- log->Add(base::TimeTicks::Now(), event, PHASE_BEGIN);
+ log->Add(Entry(base::TimeTicks::Now(), Event(event_type, 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) {
+ // a time duration, and we are matching an earlier call to
+ // BeginEvent(event_type).
+ static void EndEvent(LoadLog* log, EventType event_type) {
if (log)
- log->Add(base::TimeTicks::Now(), event, PHASE_END);
+ log->Add(Entry(base::TimeTicks::Now(), Event(event_type, PHASE_END)));
+ }
+
+ // |literal| should be a string literal (i.e. lives in static storage).
+ static void AddStringLiteral(LoadLog* log, const char* literal) {
+ if (log)
+ log->Add(Entry(base::TimeTicks::Now(), literal));
}
// --------------------------------------------------------------------------
- // Returns the list of all events in the log.
- const EventList& events() const {
- return events_;
+ // Returns the list of all entries in the log.
+ const EntryList& entries() const {
+ return entries_;
}
// Returns the number of entries that were dropped from the log because the
@@ -106,15 +156,11 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> {
}
// Returns a C-String symbolic name for |event|.
- static const char* EventTypeToString(EventType event);
+ static const char* EventTypeToString(EventType event_type);
- void Add(const Event& event);
-
- void Add(base::TimeTicks t, EventType event, EventPhase phase) {
- Add(Event(t, event, phase));
- }
+ void Add(const Entry& entry);
- // Copies all events from |log|, appending it to the end of |this|.
+ // Copies all entries from |log|, appending it to the end of |this|.
void Append(const LoadLog* log);
private:
@@ -122,7 +168,7 @@ class LoadLog : public base::RefCountedThreadSafe<LoadLog> {
~LoadLog() {}
- EventList events_;
+ EntryList entries_;
size_t num_entries_truncated_;
size_t max_num_entries_;;
};