diff options
Diffstat (limited to 'gpu/common/gpu_trace_event.cc')
-rw-r--r-- | gpu/common/gpu_trace_event.cc | 100 |
1 files changed, 11 insertions, 89 deletions
diff --git a/gpu/common/gpu_trace_event.cc b/gpu/common/gpu_trace_event.cc index 241ca4e..882b0b8 100644 --- a/gpu/common/gpu_trace_event.cc +++ b/gpu/common/gpu_trace_event.cc @@ -39,84 +39,6 @@ TraceCategory::~TraceCategory() { //////////////////////////////////////////////////////////////////////////////// // -// TraceValue -// -//////////////////////////////////////////////////////////////////////////////// - -void TraceValue::Destroy() { - if (type_ == TRACE_TYPE_STRING) { - free(value_.as_string); - value_.as_string = NULL; - } - type_ = TRACE_TYPE_UNDEFINED; - value_.as_uint = 0ull; -} - -TraceValue& TraceValue::operator=(const TraceValue& rhs) { - DCHECK(sizeof(value_) == sizeof(uint64)); - Destroy(); - type_ = rhs.type_; - if (rhs.type_ == TRACE_TYPE_STRING) { - value_.as_string = base::strdup(rhs.value_.as_string); - } else { - // Copy all 64 bits for all other types. - value_.as_uint = rhs.value_.as_uint; - } - return *this; -} - -bool TraceValue::operator==(const TraceValue& rhs) const { - if (type_ != rhs.type()) - return false; - if (rhs.type_ == TRACE_TYPE_STRING) { - return (strcmp(value_.as_string, rhs.value_.as_string) == 0); - } else { - // Compare all 64 bits for all other types. Unused bits are set to zero - // by the constructors of types that may be less than 64 bits. - return (value_.as_uint == rhs.value_.as_uint); - } -} - -void TraceValue::AppendAsJSON(std::string* out) const { - char temp_string[128]; - std::string::size_type start_pos; - switch (type_) { - case TRACE_TYPE_BOOL: - *out += as_bool()? "true" : "false"; - break; - case TRACE_TYPE_UINT: - base::snprintf(temp_string, sizeof(temp_string), "%llu", - static_cast<unsigned long long>(as_uint())); - *out += temp_string; - break; - case TRACE_TYPE_INT: - base::snprintf(temp_string, sizeof(temp_string), "%lld", - static_cast<long long>(as_int())); - *out += temp_string; - break; - case TRACE_TYPE_DOUBLE: - base::snprintf(temp_string, sizeof(temp_string), "%f", as_double()); - *out += temp_string; - break; - case TRACE_TYPE_POINTER: - base::snprintf(temp_string, sizeof(temp_string), "%p", as_pointer()); - *out += temp_string; - break; - case TRACE_TYPE_STRING: - start_pos = out->size(); - *out += as_string(); - // replace " character with ' - while ((start_pos = out->find_first_of('\"', start_pos)) != - std::string::npos) - (*out)[start_pos] = '\''; - break; - default: - break; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// // TraceEvent // //////////////////////////////////////////////////////////////////////////////// @@ -172,23 +94,23 @@ void TraceEvent::AppendAsJSON(std::string* out) const { const char* phaseStr = GetPhaseStr(phase); int64 time_int64 = timestamp.ToInternalValue(); + long long unsigned int time_llui = + static_cast<long long unsigned int>(time_int64); StringAppendF(out, - "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld," - "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{", + "{cat:'%s',pid:%i,tid:%i,ts:0x%llx,ph:'%s',name:'%s',args:{", category->name(), static_cast<int>(processId), static_cast<int>(threadId), - static_cast<long long>(time_int64), + time_llui, phaseStr, name); for (int i = 0; i < nargs; ++i) { if (i > 0) *out += ","; - *out += "\""; *out += argNames[i]; - *out += "\":\""; - argValues[i].AppendAsJSON(out); - *out += "\""; + *out += ":'"; + *out += argValues[i]; + *out += "'"; } *out += "}}"; } @@ -291,8 +213,8 @@ void TraceLog::AddTraceEvent(TraceEventPhase phase, const char* file, int line, TraceCategory* category, const char* name, - const char* arg1name, TraceValue arg1val, - const char* arg2name, TraceValue arg2val) { + const char* arg1name, const char* arg1val, + const char* arg2name, const char* arg2val) { DCHECK(file && name); #ifdef USE_UNRELIABLE_NOW TimeTicks now = TimeTicks::HighResNow(); @@ -312,9 +234,9 @@ void TraceLog::AddTraceEvent(TraceEventPhase phase, event.category = category; event.name = name; event.argNames[0] = arg1name; - event.argValues[0] = arg1val; + event.argValues[0] = arg1name ? arg1val : ""; event.argNames[1] = arg2name; - event.argValues[1] = arg2val; + event.argValues[1] = arg2name ? arg2val : ""; COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && buffer_full_callback_.get()) |