Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "gpu/common/gpu_trace_event.h" | 5 #include "gpu/common/gpu_trace_event.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 static_cast<base::subtle::Atomic32>(enabled)); | 32 static_cast<base::subtle::Atomic32>(enabled)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TraceCategory::~TraceCategory() { | 35 TraceCategory::~TraceCategory() { |
| 36 base::subtle::NoBarrier_Store(&enabled_, | 36 base::subtle::NoBarrier_Store(&enabled_, |
| 37 static_cast<base::subtle::Atomic32>(0)); | 37 static_cast<base::subtle::Atomic32>(0)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 41 // | 41 // |
| 42 // TraceAnyType | |
| 43 // | |
| 44 //////////////////////////////////////////////////////////////////////////////// | |
| 45 | |
| 46 void TraceAnyType::Destroy() { | |
| 47 if (type_ == STRING) { | |
| 48 free(value_.as_string); | |
| 49 value_.as_string = NULL; | |
| 50 } | |
| 51 type_ = NONE; | |
| 52 } | |
| 53 | |
| 54 TraceAnyType& TraceAnyType::operator=(const TraceAnyType& rhs) { | |
| 55 DCHECK(sizeof(value_) == sizeof(uint64)); | |
| 56 Destroy(); | |
| 57 type_ = rhs.type_; | |
| 58 if (rhs.type_ == STRING) { | |
| 59 value_.as_string = strdup(rhs.value_.as_string); | |
| 60 } else { | |
| 61 // Copy all 64 bits for all other types. | |
| 62 value_.as_uint = rhs.value_.as_uint; | |
| 63 } | |
| 64 return *this; | |
| 65 } | |
| 66 | |
| 67 bool TraceAnyType::operator==(const TraceAnyType& rhs) const { | |
| 68 if (type_ != rhs.type()) | |
| 69 return false; | |
| 70 if (rhs.type_ == STRING) { | |
| 71 return (strcmp(value_.as_string, rhs.value_.as_string) == 0); | |
| 72 } else { | |
| 73 // Compare all 64 bits for all other types. Unused bits are set to zero | |
| 74 // by the constructors of types that may be less than 64 bits. | |
| 75 return (value_.as_uint == rhs.value_.as_uint); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void TraceAnyType::AppendAsJSON(std::string* out) const { | |
| 80 char temp_string[128]; | |
| 81 switch (type_) { | |
| 82 case BOOLEAN: | |
| 83 *out += as_bool()? "true" : "false"; | |
| 84 break; | |
| 85 case UINT: | |
| 86 snprintf(temp_string, sizeof(temp_string), "%llu", | |
| 87 (unsigned long long)as_uint()); | |
| 88 *out += temp_string; | |
| 89 break; | |
| 90 case INT: | |
| 91 snprintf(temp_string, sizeof(temp_string), "%lld", (long long)as_int()); | |
| 92 *out += temp_string; | |
| 93 break; | |
| 94 case DOUBLE: | |
| 95 snprintf(temp_string, sizeof(temp_string), "%f", as_double()); | |
| 96 *out += temp_string; | |
| 97 break; | |
| 98 case POINTER: | |
| 99 snprintf(temp_string, sizeof(temp_string), "%p", as_pointer()); | |
| 100 *out += temp_string; | |
| 101 break; | |
| 102 case STRING: | |
| 103 *out += "'"; | |
|
scheib
2011/04/21 16:44:35
Should check for ' characters in the string and es
jbates
2011/04/21 21:11:51
Done.
| |
| 104 *out += as_string(); | |
| 105 *out += "'"; | |
| 106 break; | |
| 107 default: | |
| 108 *out += "''"; | |
| 109 break; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 //////////////////////////////////////////////////////////////////////////////// | |
| 114 // | |
| 42 // TraceEvent | 115 // TraceEvent |
| 43 // | 116 // |
| 44 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
| 45 | 118 |
| 46 namespace { | 119 namespace { |
| 47 const char* GetPhaseStr(TraceEventPhase phase) { | 120 const char* GetPhaseStr(TraceEventPhase phase) { |
| 48 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) { | 121 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) { |
| 49 return "B"; | 122 return "B"; |
| 50 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) { | 123 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) { |
| 51 return "I"; | 124 return "I"; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 category->name(), | 174 category->name(), |
| 102 static_cast<int>(processId), | 175 static_cast<int>(processId), |
| 103 static_cast<int>(threadId), | 176 static_cast<int>(threadId), |
| 104 time_llui, | 177 time_llui, |
| 105 phaseStr, | 178 phaseStr, |
| 106 name); | 179 name); |
| 107 for (int i = 0; i < nargs; ++i) { | 180 for (int i = 0; i < nargs; ++i) { |
| 108 if (i > 0) | 181 if (i > 0) |
| 109 *out += ","; | 182 *out += ","; |
| 110 *out += argNames[i]; | 183 *out += argNames[i]; |
| 111 *out += ":'"; | 184 *out += ":"; |
| 112 *out += argValues[i]; | 185 argValues[i].AppendAsJSON(out); |
| 113 *out += "'"; | |
| 114 } | 186 } |
| 115 *out += "}}"; | 187 *out += "}}"; |
| 116 } | 188 } |
| 117 | 189 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
| 119 // | 191 // |
| 120 // TraceLog | 192 // TraceLog |
| 121 // | 193 // |
| 122 //////////////////////////////////////////////////////////////////////////////// | 194 //////////////////////////////////////////////////////////////////////////////// |
| 123 | 195 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 output_callback_->Run(json_events); | 278 output_callback_->Run(json_events); |
| 207 } | 279 } |
| 208 } | 280 } |
| 209 logged_events_.erase(logged_events_.begin(), logged_events_.end()); | 281 logged_events_.erase(logged_events_.begin(), logged_events_.end()); |
| 210 } | 282 } |
| 211 | 283 |
| 212 void TraceLog::AddTraceEvent(TraceEventPhase phase, | 284 void TraceLog::AddTraceEvent(TraceEventPhase phase, |
| 213 const char* file, int line, | 285 const char* file, int line, |
| 214 TraceCategory* category, | 286 TraceCategory* category, |
| 215 const char* name, | 287 const char* name, |
| 216 const char* arg1name, const char* arg1val, | 288 const char* arg1name, TraceAnyType arg1val, |
| 217 const char* arg2name, const char* arg2val) { | 289 const char* arg2name, TraceAnyType arg2val) { |
| 218 DCHECK(file && name); | 290 DCHECK(file && name); |
| 219 #ifdef USE_UNRELIABLE_NOW | 291 #ifdef USE_UNRELIABLE_NOW |
| 220 TimeTicks now = TimeTicks::HighResNow(); | 292 TimeTicks now = TimeTicks::HighResNow(); |
| 221 #else | 293 #else |
| 222 TimeTicks now = TimeTicks::Now(); | 294 TimeTicks now = TimeTicks::Now(); |
| 223 #endif | 295 #endif |
| 224 //static_cast<unsigned long>(base::GetCurrentProcId()), | 296 //static_cast<unsigned long>(base::GetCurrentProcId()), |
| 225 AutoLock lock(lock_); | 297 AutoLock lock(lock_); |
| 226 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) | 298 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) |
| 227 return; | 299 return; |
| 228 logged_events_.push_back(TraceEvent()); | 300 logged_events_.push_back(TraceEvent()); |
| 229 TraceEvent& event = logged_events_.back(); | 301 TraceEvent& event = logged_events_.back(); |
| 230 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); | 302 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); |
| 231 event.threadId = PlatformThread::CurrentId(); | 303 event.threadId = PlatformThread::CurrentId(); |
| 232 event.timestamp = now; | 304 event.timestamp = now; |
| 233 event.phase = phase; | 305 event.phase = phase; |
| 234 event.category = category; | 306 event.category = category; |
| 235 event.name = name; | 307 event.name = name; |
| 236 event.argNames[0] = arg1name; | 308 event.argNames[0] = arg1name; |
| 237 event.argValues[0] = arg1name ? arg1val : ""; | 309 event.argValues[0] = arg1val; |
| 238 event.argNames[1] = arg2name; | 310 event.argNames[1] = arg2name; |
| 239 event.argValues[1] = arg2name ? arg2val : ""; | 311 event.argValues[1] = arg2val; |
| 240 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); | 312 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); |
| 241 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && | 313 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && |
| 242 buffer_full_callback_.get()) | 314 buffer_full_callback_.get()) |
| 243 buffer_full_callback_->Run(); | 315 buffer_full_callback_->Run(); |
| 244 } | 316 } |
| 245 | 317 |
| 246 } // namespace gpu | 318 } // namespace gpu |
| OLD | NEW |