Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: gpu/common/gpu_trace_event.cc

Issue 6877101: Replaced std::string argument storage in gpu_trace_event with faster TraceAnyType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/common/gpu_trace_event.h ('k') | webkit/glue/webkitclient_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TraceValue
43 //
44 ////////////////////////////////////////////////////////////////////////////////
45
46 void TraceValue::Destroy() {
47 if (type_ == TRACE_TYPE_STRING) {
48 free(value_.as_string);
49 value_.as_string = NULL;
50 }
51 type_ = TRACE_TYPE_UNDEFINED;
52 value_.as_uint = 0ull;
53 }
54
55 TraceValue& TraceValue::operator=(const TraceValue& rhs) {
56 DCHECK(sizeof(value_) == sizeof(uint64));
57 Destroy();
58 type_ = rhs.type_;
59 if (rhs.type_ == TRACE_TYPE_STRING) {
60 value_.as_string = base::strdup(rhs.value_.as_string);
61 } else {
62 // Copy all 64 bits for all other types.
63 value_.as_uint = rhs.value_.as_uint;
64 }
65 return *this;
66 }
67
68 bool TraceValue::operator==(const TraceValue& rhs) const {
69 if (type_ != rhs.type())
70 return false;
71 if (rhs.type_ == TRACE_TYPE_STRING) {
72 return (strcmp(value_.as_string, rhs.value_.as_string) == 0);
73 } else {
74 // Compare all 64 bits for all other types. Unused bits are set to zero
75 // by the constructors of types that may be less than 64 bits.
76 return (value_.as_uint == rhs.value_.as_uint);
77 }
78 }
79
80 void TraceValue::AppendAsJSON(std::string* out) const {
81 char temp_string[128];
82 std::string::size_type start_pos;
83 switch (type_) {
84 case TRACE_TYPE_BOOL:
85 *out += as_bool()? "true" : "false";
86 break;
87 case TRACE_TYPE_UINT:
88 base::snprintf(temp_string, sizeof(temp_string), "%llu",
89 static_cast<unsigned long long>(as_uint()));
90 *out += temp_string;
91 break;
92 case TRACE_TYPE_INT:
93 base::snprintf(temp_string, sizeof(temp_string), "%lld",
94 static_cast<long long>(as_int()));
95 *out += temp_string;
96 break;
97 case TRACE_TYPE_DOUBLE:
98 base::snprintf(temp_string, sizeof(temp_string), "%f", as_double());
99 *out += temp_string;
100 break;
101 case TRACE_TYPE_POINTER:
102 base::snprintf(temp_string, sizeof(temp_string), "%p", as_pointer());
103 *out += temp_string;
104 break;
105 case TRACE_TYPE_STRING:
106 start_pos = out->size();
107 *out += as_string();
108 // replace " character with '
109 while ((start_pos = out->find_first_of('\"', start_pos)) !=
110 std::string::npos)
111 (*out)[start_pos] = '\'';
112 break;
113 default:
114 break;
115 }
116 }
117
118 ////////////////////////////////////////////////////////////////////////////////
119 //
42 // TraceEvent 120 // TraceEvent
43 // 121 //
44 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
45 123
46 namespace { 124 namespace {
47 const char* GetPhaseStr(TraceEventPhase phase) { 125 const char* GetPhaseStr(TraceEventPhase phase) {
48 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) { 126 if (phase == GPU_TRACE_EVENT_PHASE_BEGIN) {
49 return "B"; 127 return "B";
50 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) { 128 } else if (phase == GPU_TRACE_EVENT_PHASE_INSTANT) {
51 return "I"; 129 return "I";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void TraceEvent::AppendAsJSON(std::string* out) const { 165 void TraceEvent::AppendAsJSON(std::string* out) const {
88 int nargs = 0; 166 int nargs = 0;
89 for (int i = 0; i < TRACE_MAX_NUM_ARGS; ++i) { 167 for (int i = 0; i < TRACE_MAX_NUM_ARGS; ++i) {
90 if (argNames[i] == NULL) 168 if (argNames[i] == NULL)
91 break; 169 break;
92 nargs += 1; 170 nargs += 1;
93 } 171 }
94 172
95 const char* phaseStr = GetPhaseStr(phase); 173 const char* phaseStr = GetPhaseStr(phase);
96 int64 time_int64 = timestamp.ToInternalValue(); 174 int64 time_int64 = timestamp.ToInternalValue();
97 long long unsigned int time_llui =
98 static_cast<long long unsigned int>(time_int64);
99 StringAppendF(out, 175 StringAppendF(out,
100 "{cat:'%s',pid:%i,tid:%i,ts:0x%llx,ph:'%s',name:'%s',args:{", 176 "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld,"
177 "\"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 static_cast<long long>(time_int64),
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 += ",";
187 *out += "\"";
110 *out += argNames[i]; 188 *out += argNames[i];
111 *out += ":'"; 189 *out += "\":\"";
112 *out += argValues[i]; 190 argValues[i].AppendAsJSON(out);
113 *out += "'"; 191 *out += "\"";
114 } 192 }
115 *out += "}}"; 193 *out += "}}";
116 } 194 }
117 195
118 //////////////////////////////////////////////////////////////////////////////// 196 ////////////////////////////////////////////////////////////////////////////////
119 // 197 //
120 // TraceLog 198 // TraceLog
121 // 199 //
122 //////////////////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////////
123 201
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 output_callback_->Run(json_events); 284 output_callback_->Run(json_events);
207 } 285 }
208 } 286 }
209 logged_events_.erase(logged_events_.begin(), logged_events_.end()); 287 logged_events_.erase(logged_events_.begin(), logged_events_.end());
210 } 288 }
211 289
212 void TraceLog::AddTraceEvent(TraceEventPhase phase, 290 void TraceLog::AddTraceEvent(TraceEventPhase phase,
213 const char* file, int line, 291 const char* file, int line,
214 TraceCategory* category, 292 TraceCategory* category,
215 const char* name, 293 const char* name,
216 const char* arg1name, const char* arg1val, 294 const char* arg1name, TraceValue arg1val,
217 const char* arg2name, const char* arg2val) { 295 const char* arg2name, TraceValue arg2val) {
218 DCHECK(file && name); 296 DCHECK(file && name);
219 #ifdef USE_UNRELIABLE_NOW 297 #ifdef USE_UNRELIABLE_NOW
220 TimeTicks now = TimeTicks::HighResNow(); 298 TimeTicks now = TimeTicks::HighResNow();
221 #else 299 #else
222 TimeTicks now = TimeTicks::Now(); 300 TimeTicks now = TimeTicks::Now();
223 #endif 301 #endif
224 //static_cast<unsigned long>(base::GetCurrentProcId()), 302 //static_cast<unsigned long>(base::GetCurrentProcId()),
225 AutoLock lock(lock_); 303 AutoLock lock(lock_);
226 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) 304 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE)
227 return; 305 return;
228 logged_events_.push_back(TraceEvent()); 306 logged_events_.push_back(TraceEvent());
229 TraceEvent& event = logged_events_.back(); 307 TraceEvent& event = logged_events_.back();
230 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); 308 event.processId = static_cast<unsigned long>(base::GetCurrentProcId());
231 event.threadId = PlatformThread::CurrentId(); 309 event.threadId = PlatformThread::CurrentId();
232 event.timestamp = now; 310 event.timestamp = now;
233 event.phase = phase; 311 event.phase = phase;
234 event.category = category; 312 event.category = category;
235 event.name = name; 313 event.name = name;
236 event.argNames[0] = arg1name; 314 event.argNames[0] = arg1name;
237 event.argValues[0] = arg1name ? arg1val : ""; 315 event.argValues[0] = arg1val;
238 event.argNames[1] = arg2name; 316 event.argNames[1] = arg2name;
239 event.argValues[1] = arg2name ? arg2val : ""; 317 event.argValues[1] = arg2val;
240 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); 318 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync);
241 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && 319 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE &&
242 buffer_full_callback_.get()) 320 buffer_full_callback_.get())
243 buffer_full_callback_->Run(); 321 buffer_full_callback_->Run();
244 } 322 }
245 323
246 } // namespace gpu 324 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/common/gpu_trace_event.h ('k') | webkit/glue/webkitclient_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698