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

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

Issue 6997006: iwyu: Include stringprintf.h where appropriate, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
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"
11 #include "base/time.h" 11 #include "base/time.h"
12 12
13 #define USE_UNRELIABLE_NOW 13 #define USE_UNRELIABLE_NOW
14 14
15 using namespace base;
16
17 namespace gpu { 15 namespace gpu {
18 16
19 // Controls the number of trace events we will buffer in-memory 17 // Controls the number of trace events we will buffer in-memory
20 // before throwing them away. 18 // before throwing them away.
21 #define TRACE_EVENT_BUFFER_SIZE 500000 19 #define TRACE_EVENT_BUFFER_SIZE 500000
22 #define TRACE_EVENT_BATCH_SIZE 1000 20 #define TRACE_EVENT_BATCH_SIZE 1000
23 21
24 #define TRACE_EVENT_MAX_CATEGORIES 42 22 #define TRACE_EVENT_MAX_CATEGORIES 42
25 23
26 static TraceCategory g_categories[TRACE_EVENT_MAX_CATEGORIES]; 24 static TraceCategory g_categories[TRACE_EVENT_MAX_CATEGORIES];
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 void TraceEvent::AppendAsJSON(std::string* out) const { 168 void TraceEvent::AppendAsJSON(std::string* out) const {
171 int nargs = 0; 169 int nargs = 0;
172 for (int i = 0; i < TRACE_MAX_NUM_ARGS; ++i) { 170 for (int i = 0; i < TRACE_MAX_NUM_ARGS; ++i) {
173 if (argNames[i] == NULL) 171 if (argNames[i] == NULL)
174 break; 172 break;
175 nargs += 1; 173 nargs += 1;
176 } 174 }
177 175
178 const char* phaseStr = GetPhaseStr(phase); 176 const char* phaseStr = GetPhaseStr(phase);
179 int64 time_int64 = timestamp.ToInternalValue(); 177 int64 time_int64 = timestamp.ToInternalValue();
180 StringAppendF(out, 178 base::StringAppendF(
179 out,
181 "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld," 180 "{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld,"
182 "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{", 181 "\"ph\":\"%s\",\"name\":\"%s\",\"args\":{",
183 category->name(), 182 category->name(),
184 static_cast<int>(processId), 183 static_cast<int>(processId),
185 static_cast<int>(threadId), 184 static_cast<int>(threadId),
186 static_cast<long long>(time_int64), 185 static_cast<long long>(time_int64),
187 phaseStr, 186 phaseStr,
188 name); 187 name);
189 for (int i = 0; i < nargs; ++i) { 188 for (int i = 0; i < nargs; ++i) {
190 if (i > 0) 189 if (i > 0)
(...skipping 21 matching lines...) Expand all
212 TraceLog::TraceLog() 211 TraceLog::TraceLog()
213 : enabled_(false) 212 : enabled_(false)
214 { 213 {
215 logged_events_.reserve(1024); 214 logged_events_.reserve(1024);
216 } 215 }
217 216
218 TraceLog::~TraceLog() { 217 TraceLog::~TraceLog() {
219 } 218 }
220 219
221 TraceCategory* TraceLog::GetCategory(const char* name) { 220 TraceCategory* TraceLog::GetCategory(const char* name) {
222 AutoLock lock(lock_); 221 base::AutoLock lock(lock_);
223 for (int i = 0; i < g_category_index; i++) { 222 for (int i = 0; i < g_category_index; i++) {
224 if (strcmp(g_categories[i].name(), name) == 0) 223 if (strcmp(g_categories[i].name(), name) == 0)
225 return &g_categories[i]; 224 return &g_categories[i];
226 } 225 }
227 CHECK(g_category_index < TRACE_EVENT_MAX_CATEGORIES) << 226 CHECK(g_category_index < TRACE_EVENT_MAX_CATEGORIES) <<
228 "must increase TRACE_EVENT_MAX_CATEGORIES"; 227 "must increase TRACE_EVENT_MAX_CATEGORIES";
229 int new_index = g_category_index++; 228 int new_index = g_category_index++;
230 g_categories[new_index].set(name, enabled_); 229 g_categories[new_index].set(name, enabled_);
231 return &g_categories[new_index]; 230 return &g_categories[new_index];
232 } 231 }
233 232
234 void TraceLog::SetEnabled(bool enabled) { 233 void TraceLog::SetEnabled(bool enabled) {
235 AutoLock lock(lock_); 234 base::AutoLock lock(lock_);
236 if (enabled == enabled_) 235 if (enabled == enabled_)
237 return; 236 return;
238 if (enabled) { 237 if (enabled) {
239 // Enable all categories. 238 // Enable all categories.
240 enabled_ = true; 239 enabled_ = true;
241 for (int i = 0; i < g_category_index; i++) { 240 for (int i = 0; i < g_category_index; i++) {
242 base::subtle::NoBarrier_Store(&g_categories[i].enabled_, 241 base::subtle::NoBarrier_Store(&g_categories[i].enabled_,
243 static_cast<base::subtle::Atomic32>(1)); 242 static_cast<base::subtle::Atomic32>(1));
244 } 243 }
245 } else { 244 } else {
246 // Disable all categories. 245 // Disable all categories.
247 for (int i = 0; i < g_category_index; i++) { 246 for (int i = 0; i < g_category_index; i++) {
248 base::subtle::NoBarrier_Store(&g_categories[i].enabled_, 247 base::subtle::NoBarrier_Store(&g_categories[i].enabled_,
249 static_cast<base::subtle::Atomic32>(0)); 248 static_cast<base::subtle::Atomic32>(0));
250 } 249 }
251 enabled_ = false; 250 enabled_ = false;
252 FlushWithLockAlreadyHeld(); 251 FlushWithLockAlreadyHeld();
253 } 252 }
254 } 253 }
255 254
256 float TraceLog::GetBufferPercentFull() const { 255 float TraceLog::GetBufferPercentFull() const {
257 return (float)((double)logged_events_.size()/(double)TRACE_EVENT_BUFFER_SIZE); 256 return (float)((double)logged_events_.size()/(double)TRACE_EVENT_BUFFER_SIZE);
258 } 257 }
259 258
260 void TraceLog::SetOutputCallback(TraceLog::OutputCallback* cb) { 259 void TraceLog::SetOutputCallback(TraceLog::OutputCallback* cb) {
261 AutoLock lock(lock_); 260 base::AutoLock lock(lock_);
262 if (enabled_) { 261 if (enabled_) {
263 FlushWithLockAlreadyHeld(); 262 FlushWithLockAlreadyHeld();
264 } 263 }
265 output_callback_.reset(cb); 264 output_callback_.reset(cb);
266 } 265 }
267 266
268 void TraceLog::SetBufferFullCallback(TraceLog::BufferFullCallback* cb) { 267 void TraceLog::SetBufferFullCallback(TraceLog::BufferFullCallback* cb) {
269 AutoLock lock(lock_); 268 base::AutoLock lock(lock_);
270 buffer_full_callback_.reset(cb); 269 buffer_full_callback_.reset(cb);
271 } 270 }
272 271
273 void TraceLog::AddRemotelyCollectedData(const std::string& json_events) { 272 void TraceLog::AddRemotelyCollectedData(const std::string& json_events) {
274 AutoLock lock(lock_); 273 base::AutoLock lock(lock_);
275 if (output_callback_.get()) 274 if (output_callback_.get())
276 output_callback_->Run(json_events); 275 output_callback_->Run(json_events);
277 } 276 }
278 277
279 void TraceLog::Flush() { 278 void TraceLog::Flush() {
280 AutoLock lock(lock_); 279 base::AutoLock lock(lock_);
281 FlushWithLockAlreadyHeld(); 280 FlushWithLockAlreadyHeld();
282 } 281 }
283 282
284 void TraceLog::FlushWithLockAlreadyHeld() { 283 void TraceLog::FlushWithLockAlreadyHeld() {
285 if (output_callback_.get() && logged_events_.size()) { 284 if (output_callback_.get() && logged_events_.size()) {
286 for (size_t i = 0; i < logged_events_.size(); i += TRACE_EVENT_BATCH_SIZE) { 285 for (size_t i = 0; i < logged_events_.size(); i += TRACE_EVENT_BATCH_SIZE) {
287 std::string json_events; 286 std::string json_events;
288 TraceEvent::AppendAsJSON(&json_events, logged_events_, 287 TraceEvent::AppendAsJSON(&json_events, logged_events_,
289 i, TRACE_EVENT_BATCH_SIZE); 288 i, TRACE_EVENT_BATCH_SIZE);
290 output_callback_->Run(json_events); 289 output_callback_->Run(json_events);
291 } 290 }
292 } 291 }
293 logged_events_.erase(logged_events_.begin(), logged_events_.end()); 292 logged_events_.erase(logged_events_.begin(), logged_events_.end());
294 } 293 }
295 294
296 void TraceLog::AddTraceEvent(TraceEventPhase phase, 295 void TraceLog::AddTraceEvent(TraceEventPhase phase,
297 const char* file, int line, 296 const char* file, int line,
298 TraceCategory* category, 297 TraceCategory* category,
299 const char* name, 298 const char* name,
300 const char* arg1name, TraceValue arg1val, 299 const char* arg1name, TraceValue arg1val,
301 const char* arg2name, TraceValue arg2val) { 300 const char* arg2name, TraceValue arg2val) {
302 DCHECK(file && name); 301 DCHECK(file && name);
303 #ifdef USE_UNRELIABLE_NOW 302 #ifdef USE_UNRELIABLE_NOW
304 TimeTicks now = TimeTicks::HighResNow(); 303 base::TimeTicks now = base::TimeTicks::HighResNow();
305 #else 304 #else
306 TimeTicks now = TimeTicks::Now(); 305 base::TimeTicks now = base::TimeTicks::Now();
307 #endif 306 #endif
308 //static_cast<unsigned long>(base::GetCurrentProcId()), 307 //static_cast<unsigned long>(base::GetCurrentProcId()),
309 AutoLock lock(lock_); 308 base::AutoLock lock(lock_);
310 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE) 309 if (logged_events_.size() >= TRACE_EVENT_BUFFER_SIZE)
311 return; 310 return;
312 logged_events_.push_back(TraceEvent()); 311 logged_events_.push_back(TraceEvent());
313 TraceEvent& event = logged_events_.back(); 312 TraceEvent& event = logged_events_.back();
314 event.processId = static_cast<unsigned long>(base::GetCurrentProcId()); 313 event.processId = static_cast<unsigned long>(base::GetCurrentProcId());
315 event.threadId = PlatformThread::CurrentId(); 314 event.threadId = base::PlatformThread::CurrentId();
316 event.timestamp = now; 315 event.timestamp = now;
317 event.phase = phase; 316 event.phase = phase;
318 event.category = category; 317 event.category = category;
319 event.name = name; 318 event.name = name;
320 event.argNames[0] = arg1name; 319 event.argNames[0] = arg1name;
321 event.argValues[0] = arg1val; 320 event.argValues[0] = arg1val;
322 event.argNames[1] = arg2name; 321 event.argNames[1] = arg2name;
323 event.argValues[1] = arg2val; 322 event.argValues[1] = arg2val;
324 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync); 323 COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync);
325 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE && 324 if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE &&
326 buffer_full_callback_.get()) 325 buffer_full_callback_.get())
327 buffer_full_callback_->Run(); 326 buffer_full_callback_->Run();
328 } 327 }
329 328
330 } // namespace gpu 329 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698