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 std::string::size_type start_pos; | |
82 switch (type_) { | |
83 case BOOLEAN: | |
84 *out += as_bool()? "true" : "false"; | |
85 break; | |
86 case UINT: | |
87 snprintf(temp_string, sizeof(temp_string), "%llu", | |
88 (unsigned long long)as_uint()); | |
89 *out += temp_string; | |
90 break; | |
91 case INT: | |
92 snprintf(temp_string, sizeof(temp_string), "%lld", (long long)as_int()); | |
93 *out += temp_string; | |
94 break; | |
95 case DOUBLE: | |
96 snprintf(temp_string, sizeof(temp_string), "%f", as_double()); | |
97 *out += temp_string; | |
98 break; | |
99 case POINTER: | |
100 snprintf(temp_string, sizeof(temp_string), "%p", as_pointer()); | |
101 *out += temp_string; | |
102 break; | |
103 case STRING: | |
104 *out += "'"; | |
nduca
2011/04/21 22:15:44
double quotes
jbates
2011/04/21 23:57:53
Done.
| |
105 start_pos = out->size(); | |
106 *out += as_string(); | |
107 // replace ' character with ` to avoid javascript errors | |
108 std::replace(out->begin() + start_pos, out->end(), '\'', '`'); | |
109 *out += "'"; | |
110 break; | |
111 default: | |
112 *out += "''"; | |
nduca
2011/04/21 22:15:44
double quotes
jbates
2011/04/21 23:57:53
Done.
| |
113 break; | |
114 } | |
115 } | |
116 | |
117 //////////////////////////////////////////////////////////////////////////////// | |
118 // | |
42 // TraceEvent | 119 // TraceEvent |
43 // | 120 // |
44 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
45 | 122 |
46 namespace { | 123 namespace { |
47 const char* GetPhaseStr(TraceEventPhase phase) { | 124 const char* GetPhaseStr(TraceEventPhase phase) { |
48 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) { | 125 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) { |
49 return "B"; | 126 return "B"; |
50 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) { | 127 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) { |
51 return "I"; | 128 return "I"; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 "{cat:'%s',pid:%i,tid:%i,ts:0x%llx,ph:'%s',name:'%s',args:{", | 177 "{cat:'%s',pid:%i,tid:%i,ts:0x%llx,ph:'%s',name:'%s',args:{", |
101 category->name(), | 178 category->name(), |
102 static_cast<int>(processId), | 179 static_cast<int>(processId), |
103 static_cast<int>(threadId), | 180 static_cast<int>(threadId), |
104 time_llui, | 181 time_llui, |
105 phaseStr, | 182 phaseStr, |
106 name); | 183 name); |
107 for (int i = 0; i < nargs; ++i) { | 184 for (int i = 0; i < nargs; ++i) { |
108 if (i > 0) | 185 if (i > 0) |
109 *out += ","; | 186 *out += ","; |
110 *out += argNames[i]; | 187 *out += argNames[i]; |
nduca
2011/04/21 22:15:44
check with @scheib/bauman --- might need to quote
jbates
2011/04/21 23:57:53
Done.
| |
111 *out += ":'"; | 188 *out += ":"; |
112 *out += argValues[i]; | 189 argValues[i].AppendAsJSON(out); |
113 *out += "'"; | |
114 } | 190 } |
115 *out += "}}"; | 191 *out += "}}"; |
116 } | 192 } |
117 | 193 |
118 //////////////////////////////////////////////////////////////////////////////// | 194 //////////////////////////////////////////////////////////////////////////////// |
119 // | 195 // |
120 // TraceLog | 196 // TraceLog |
121 // | 197 // |
122 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
123 | 199 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 output_callback_->Run(json_events); | 282 output_callback_->Run(json_events); |
207 } | 283 } |
208 } | 284 } |
209 logged_events_.erase(logged_events_.begin(), logged_events_.end()); | 285 logged_events_.erase(logged_events_.begin(), logged_events_.end()); |
210 } | 286 } |
211 | 287 |
212 void TraceLog::AddTraceEvent(TraceEventPhase phase, | 288 void TraceLog::AddTraceEvent(TraceEventPhase phase, |
213 const char* file, int line, | 289 const char* file, int line, |
214 TraceCategory* category, | 290 TraceCategory* category, |
215 const char* name, | 291 const char* name, |
216 const char* arg1name, const char* arg1val, | 292 const char* arg1name, TraceAnyType arg1val, |
217 const char* arg2name, const char* arg2val) { | 293 const char* arg2name, TraceAnyType arg2val) { |
218 DCHECK(file && name); | 294 DCHECK(file && name); |
219 #ifdef USE_UNRELIABLE_NOW | 295 #ifdef USE_UNRELIABLE_NOW |
220 TimeTicks now = TimeTicks::HighResNow(); | 296 TimeTicks now = TimeTicks::HighResNow(); |
221 #else | 297 #else |
222 TimeTicks now = TimeTicks::Now(); | 298 TimeTicks now = TimeTicks::Now(); |
223 #endif | 299 #endif |
224 //static_cast<unsigned long>(base::GetCurrentProcId()), | 300 //static_cast<unsigned long>(base::GetCurrentProcId()), |
225 AutoLock lock(lock_); | 301 AutoLock lock(lock_); |
226 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) | 302 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) |
227 return; | 303 return; |
228 logged_events_.push_back(TraceEvent()); | 304 logged_events_.push_back(TraceEvent()); |
229 TraceEvent& event = logged_events_.back(); | 305 TraceEvent& event = logged_events_.back(); |
230 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); | 306 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); |
231 event.threadId = PlatformThread::CurrentId(); | 307 event.threadId = PlatformThread::CurrentId(); |
232 event.timestamp = now; | 308 event.timestamp = now; |
233 event.phase = phase; | 309 event.phase = phase; |
234 event.category = category; | 310 event.category = category; |
235 event.name = name; | 311 event.name = name; |
236 event.argNames[0] = arg1name; | 312 event.argNames[0] = arg1name; |
237 event.argValues[0] = arg1name ? arg1val : ""; | 313 event.argValues[0] = arg1val; |
238 event.argNames[1] = arg2name; | 314 event.argNames[1] = arg2name; |
239 event.argValues[1] = arg2name ? arg2val : ""; | 315 event.argValues[1] = arg2val; |
240 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); | 316 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); |
241 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && | 317 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && |
242 buffer_full_callback_.get()) | 318 buffer_full_callback_.get()) |
243 buffer_full_callback_->Run(); | 319 buffer_full_callback_->Run(); |
244 } | 320 } |
245 | 321 |
246 } // namespace gpu | 322 } // namespace gpu |
OLD | NEW |