Chromium Code Reviews| Index: gpu/common/gpu_trace_event.h |
| diff --git a/gpu/common/gpu_trace_event.h b/gpu/common/gpu_trace_event.h |
| index 2ed9b9d09938fb75ab560ef81d3ff4907687f76d..654ab0ba4cbb7e74cb4c6d1f6d4e120e73012f73 100644 |
| --- a/gpu/common/gpu_trace_event.h |
| +++ b/gpu/common/gpu_trace_event.h |
| @@ -180,6 +180,116 @@ enum TraceEventPhase { |
| GPU_TRACE_EVENT_PHASE_INSTANT |
| }; |
| +// Simple union of values. This is much lighter weight than base::Value, which |
| +// requires dynamic allocation and a vtable. To keep the trace runtime overhead |
| +// low, we want constant size storage here. |
| +class TraceAnyType { |
|
nduca
2011/04/21 22:15:44
TraceVar or TraceVariadic?
Very similar to PP_Var
jbates
2011/04/21 23:57:53
Done.
|
| + public: |
| + enum Type { |
| + NONE, |
| + BOOLEAN, |
|
nduca
2011/04/21 22:15:44
/me wonders if we usually prefix with TYPE_? pp_va
jbates
2011/04/21 23:57:53
Done.
|
| + UINT, |
| + INT, |
| + DOUBLE, |
| + POINTER, |
| + STRING |
| + }; |
| + |
| + TraceAnyType() : type_(NONE) { |
| + value_.as_uint = 0ull; |
| + } |
| + TraceAnyType(bool rhs) : type_(BOOLEAN) { |
| + value_.as_uint = 0ull; // zero all bits |
| + value_.as_bool = rhs; |
| + } |
| + TraceAnyType(uint64 rhs) : type_(UINT) { |
| + value_.as_uint = rhs; |
| + } |
| + TraceAnyType(uint32 rhs) : type_(UINT) { |
| + value_.as_uint = rhs; |
| + } |
| + TraceAnyType(uint16 rhs) : type_(UINT) { |
| + value_.as_uint = rhs; |
| + } |
| + TraceAnyType(uint8 rhs) : type_(UINT) { |
| + value_.as_uint = rhs; |
| + } |
| + TraceAnyType(int64 rhs) : type_(INT) { |
| + value_.as_int = rhs; |
| + } |
| + TraceAnyType(int32 rhs) : type_(INT) { |
| + value_.as_int = rhs; |
| + } |
| + TraceAnyType(int16 rhs) : type_(INT) { |
| + value_.as_int = rhs; |
| + } |
| + TraceAnyType(int8 rhs) : type_(INT) { |
| + value_.as_int = rhs; |
| + } |
| + TraceAnyType(double rhs) : type_(DOUBLE) { |
| + value_.as_double = rhs; |
| + } |
| + TraceAnyType(void* rhs) : type_(POINTER) { |
| + value_.as_uint = 0ull; // zero all bits |
| + value_.as_pointer = rhs; |
| + } |
| + TraceAnyType(const char* rhs) : type_(STRING) { |
| + value_.as_uint = 0ull; // zero all bits |
| + value_.as_string = strdup(rhs); |
| + } |
| + TraceAnyType(const TraceAnyType& rhs) : type_(NONE) { |
| + operator=(rhs); |
| + } |
| + ~TraceAnyType() { |
| + Destroy(); |
| + } |
| + |
| + TraceAnyType& operator=(const TraceAnyType& rhs); |
| + bool operator==(const TraceAnyType& rhs) const; |
| + bool operator!=(const TraceAnyType& rhs) const { |
| + return !operator==(rhs); |
| + } |
| + |
| + void Destroy(); |
| + |
| + void AppendAsJSON(std::string* out) const; |
| + |
| + Type type() const { |
| + return type_; |
| + } |
| + uint64 as_uint() const { |
| + return value_.as_uint; |
| + } |
| + bool as_bool() const { |
| + return value_.as_bool; |
| + } |
| + int64 as_int() const { |
| + return value_.as_int; |
| + } |
| + double as_double() const { |
| + return value_.as_double; |
| + } |
| + void* as_pointer() const { |
| + return value_.as_pointer; |
| + } |
| + const char* as_string() const { |
| + return value_.as_string; |
| + } |
| + |
| + private: |
| + union Value { |
| + bool as_bool; |
| + uint64 as_uint; |
| + int64 as_int; |
| + double as_double; |
| + void* as_pointer; |
| + char* as_string; |
| + }; |
| + |
| + Type type_; |
| + Value value_; |
| +}; |
| + |
| // Output records are "Events" and can be obtained via the |
| // OutputCallback whenever the logging system decides to flush. This |
| // can happen at any time, on any thread, or you can programatically |
| @@ -201,7 +311,7 @@ struct TraceEvent { |
| TraceCategory* category; |
| const char* name; |
| const char* argNames[TRACE_MAX_NUM_ARGS]; |
| - std::string argValues[TRACE_MAX_NUM_ARGS]; |
| + TraceAnyType argValues[TRACE_MAX_NUM_ARGS]; |
| }; |
| @@ -243,8 +353,8 @@ class TraceLog { |
| const char* file, int line, |
| TraceCategory* category, |
| const char* name, |
| - const char* arg1name, const char* arg1val, |
| - const char* arg2name, const char* arg2val); |
| + const char* arg1name, TraceAnyType arg1val, |
| + const char* arg2name, TraceAnyType arg2val); |
| private: |
| // This allows constructor and destructor to be private and usable only |