| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // This header file defines implementation details of how the trace macros in | 26 // This header file defines implementation details of how the trace macros in |
| 27 // TraceEventCommon.h collect and store trace events. Anything not | 27 // TraceEventCommon.h collect and store trace events. Anything not |
| 28 // implementation-specific should go in TraceEventCommon.h instead of here. | 28 // implementation-specific should go in TraceEventCommon.h instead of here. |
| 29 | 29 |
| 30 #ifndef TraceEvent_h | 30 #ifndef TraceEvent_h |
| 31 #define TraceEvent_h | 31 #define TraceEvent_h |
| 32 | 32 |
| 33 #include "platform/EventTracer.h" | 33 #include "platform/EventTracer.h" |
| 34 #include "platform/TraceEventCommon.h" | 34 #include "platform/TraceEventCommon.h" |
| 35 | 35 |
| 36 #include "platform/TracedValue.h" |
| 36 #include "wtf/Allocator.h" | 37 #include "wtf/Allocator.h" |
| 37 #include "wtf/DynamicAnnotations.h" | 38 #include "wtf/DynamicAnnotations.h" |
| 38 #include "wtf/Noncopyable.h" | 39 #include "wtf/Noncopyable.h" |
| 39 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
| 40 #include "wtf/text/CString.h" | 41 #include "wtf/text/CString.h" |
| 41 | 42 |
| 42 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 43 // Implementation specific tracing API definitions. | 44 // Implementation specific tracing API definitions. |
| 44 | 45 |
| 45 // By default, const char* argument values are assumed to have long-lived scope | 46 // By default, const char* argument values are assumed to have long-lived scope |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 104 |
| 104 // Add a trace event to the platform tracing system. | 105 // Add a trace event to the platform tracing system. |
| 105 // blink::TraceEvent::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( | 106 // blink::TraceEvent::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 106 // const char* name, | 107 // const char* name, |
| 107 // unsigned long long id, | 108 // unsigned long long id, |
| 108 // double timestamp, | 109 // double timestamp, |
| 109 // int num_args, | 110 // int num_args, |
| 110 // const char** arg_names, | 111 // const char** arg_names, |
| 111 // const unsigned char* arg_types, | 112 // const unsigned char* arg_types, |
| 112 // const unsigned long long* arg_values, | 113 // const unsigned long long* arg_values, |
| 113 // PassRefPtr<ConvertableToTraceFormat> convertableValues[], | 114 // PassRefPtr<TracedValue> convertableValues[], |
| 114 // unsigned char flags) | 115 // unsigned char flags) |
| 115 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | 116 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ |
| 116 blink::EventTracer::addTraceEvent | 117 blink::EventTracer::addTraceEvent |
| 117 | 118 |
| 118 // Set the duration field of a COMPLETE trace event. | 119 // Set the duration field of a COMPLETE trace event. |
| 119 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 120 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
| 120 // blink::TraceEvent::TraceEventHandle handle) | 121 // blink::TraceEvent::TraceEventHandle handle) |
| 121 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | 122 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ |
| 122 blink::EventTracer::updateTraceEventDuration | 123 blink::EventTracer::updateTraceEventDuration |
| 123 | 124 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 368 |
| 368 // WTF::String version of setTraceValue so that trace arguments can be strings. | 369 // WTF::String version of setTraceValue so that trace arguments can be strings. |
| 369 static inline void setTraceValue(const WTF::CString& arg, unsigned char* type, u
nsigned long long* value) | 370 static inline void setTraceValue(const WTF::CString& arg, unsigned char* type, u
nsigned long long* value) |
| 370 { | 371 { |
| 371 TraceValueUnion typeValue; | 372 TraceValueUnion typeValue; |
| 372 typeValue.m_string = arg.data(); | 373 typeValue.m_string = arg.data(); |
| 373 *type = TRACE_VALUE_TYPE_COPY_STRING; | 374 *type = TRACE_VALUE_TYPE_COPY_STRING; |
| 374 *value = typeValue.m_uint; | 375 *value = typeValue.m_uint; |
| 375 } | 376 } |
| 376 | 377 |
| 377 static inline void setTraceValue(ConvertableToTraceFormat*, unsigned char* type,
unsigned long long*) | 378 static inline void setTraceValue(TracedValue*, unsigned char* type, unsigned lon
g long*) |
| 378 { | 379 { |
| 379 *type = TRACE_VALUE_TYPE_CONVERTABLE; | 380 *type = TRACE_VALUE_TYPE_CONVERTABLE; |
| 380 } | 381 } |
| 381 | 382 |
| 382 template<typename T> static inline void setTraceValue(const PassRefPtr<T>& ptr,
unsigned char* type, unsigned long long* value) | 383 template<typename T> static inline void setTraceValue(const PassRefPtr<T>& ptr,
unsigned char* type, unsigned long long* value) |
| 383 { | 384 { |
| 384 setTraceValue(ptr.get(), type, value); | 385 setTraceValue(ptr.get(), type, value); |
| 385 } | 386 } |
| 386 | 387 |
| 387 template<typename T> struct ConvertableToTraceFormatTraits { | 388 template<typename T> struct TracedValueTraits { |
| 388 static const bool isConvertable = false; | 389 static const bool isTracedValue = false; |
| 389 static PassRefPtr<ConvertableToTraceFormat> moveFromIfConvertable(const T&) | 390 static PassRefPtr<TracedValue> moveFromIfConvertable(const T&) |
| 390 { | 391 { |
| 391 return nullptr; | 392 return nullptr; |
| 392 } | 393 } |
| 393 }; | 394 }; |
| 394 | 395 |
| 395 template<typename T> struct ConvertableToTraceFormatTraits<PassRefPtr<T>> { | 396 template<typename T> struct TracedValueTraits<PassRefPtr<T>> { |
| 396 static const bool isConvertable = std::is_convertible<T*, TraceEvent::Conver
tableToTraceFormat*>::value; | 397 static const bool isTracedValue = std::is_convertible<T*, TracedValue*>::val
ue; |
| 397 static PassRefPtr<ConvertableToTraceFormat> moveFromIfConvertable(const Pass
RefPtr<T>& convertableToTraceFormat) | 398 static PassRefPtr<TracedValue> moveFromIfConvertable(const PassRefPtr<T>& co
nvertableToTraceFormat) |
| 398 { | 399 { |
| 399 return convertableToTraceFormat; | 400 return convertableToTraceFormat; |
| 400 } | 401 } |
| 401 }; | 402 }; |
| 402 | 403 |
| 403 template<typename T> bool isConvertableToTraceFormat(const T&) | 404 template<typename T> bool isTracedValue(const T&) |
| 404 { | 405 { |
| 405 return ConvertableToTraceFormatTraits<T>::isConvertable; | 406 return TracedValueTraits<T>::isTracedValue; |
| 406 } | 407 } |
| 407 | 408 |
| 408 template<typename T> PassRefPtr<ConvertableToTraceFormat> moveFromIfConvertableT
oTraceFormat(const T& value) | 409 template<typename T> PassRefPtr<TracedValue> moveFromIfTracedValue(const T& valu
e) |
| 409 { | 410 { |
| 410 return ConvertableToTraceFormatTraits<T>::moveFromIfConvertable(value); | 411 return TracedValueTraits<T>::moveFromIfConvertable(value); |
| 411 } | 412 } |
| 412 | 413 |
| 413 // These addTraceEvent template functions are defined here instead of in the | 414 // These addTraceEvent template functions are defined here instead of in the |
| 414 // macro, because the arg values could be temporary string objects. In order to | 415 // macro, because the arg values could be temporary string objects. In order to |
| 415 // store pointers to the internal c_str and pass through to the tracing API, the | 416 // store pointers to the internal c_str and pass through to the tracing API, the |
| 416 // arg values must live throughout these procedures. | 417 // arg values must live throughout these procedures. |
| 417 | 418 |
| 418 static inline TraceEventHandle addTraceEvent( | 419 static inline TraceEventHandle addTraceEvent( |
| 419 char phase, | 420 char phase, |
| 420 const unsigned char* categoryEnabled, | 421 const unsigned char* categoryEnabled, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 439 unsigned long long bindId, | 440 unsigned long long bindId, |
| 440 double timestamp, | 441 double timestamp, |
| 441 unsigned flags, | 442 unsigned flags, |
| 442 const char* arg1Name, | 443 const char* arg1Name, |
| 443 const ARG1_TYPE& arg1Val) | 444 const ARG1_TYPE& arg1Val) |
| 444 { | 445 { |
| 445 const int numArgs = 1; | 446 const int numArgs = 1; |
| 446 unsigned char argTypes[1]; | 447 unsigned char argTypes[1]; |
| 447 unsigned long long argValues[1]; | 448 unsigned long long argValues[1]; |
| 448 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); | 449 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); |
| 449 if (isConvertableToTraceFormat(arg1Val)) { | 450 if (isTracedValue(arg1Val)) { |
| 450 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 451 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 451 phase, categoryEnabled, name, id, bindId, timestamp, | 452 phase, categoryEnabled, name, id, bindId, timestamp, |
| 452 numArgs, &arg1Name, argTypes, argValues, | 453 numArgs, &arg1Name, argTypes, argValues, |
| 453 moveFromIfConvertableToTraceFormat(arg1Val), | 454 moveFromIfTracedValue(arg1Val), |
| 454 nullptr, | 455 nullptr, |
| 455 flags); | 456 flags); |
| 456 } | 457 } |
| 457 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 458 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 458 phase, categoryEnabled, name, id, bindId, timestamp, | 459 phase, categoryEnabled, name, id, bindId, timestamp, |
| 459 numArgs, &arg1Name, argTypes, argValues, | 460 numArgs, &arg1Name, argTypes, argValues, |
| 460 flags); | 461 flags); |
| 461 } | 462 } |
| 462 | 463 |
| 463 template<typename ARG1_TYPE, typename ARG2_TYPE> | 464 template<typename ARG1_TYPE, typename ARG2_TYPE> |
| 464 static inline TraceEventHandle addTraceEvent( | 465 static inline TraceEventHandle addTraceEvent( |
| 465 char phase, | 466 char phase, |
| 466 const unsigned char* categoryEnabled, | 467 const unsigned char* categoryEnabled, |
| 467 const char* name, | 468 const char* name, |
| 468 unsigned long long id, | 469 unsigned long long id, |
| 469 unsigned long long bindId, | 470 unsigned long long bindId, |
| 470 double timestamp, | 471 double timestamp, |
| 471 unsigned flags, | 472 unsigned flags, |
| 472 const char* arg1Name, | 473 const char* arg1Name, |
| 473 const ARG1_TYPE& arg1Val, | 474 const ARG1_TYPE& arg1Val, |
| 474 const char* arg2Name, | 475 const char* arg2Name, |
| 475 const ARG2_TYPE& arg2Val) | 476 const ARG2_TYPE& arg2Val) |
| 476 { | 477 { |
| 477 const int numArgs = 2; | 478 const int numArgs = 2; |
| 478 const char* argNames[2] = { arg1Name, arg2Name }; | 479 const char* argNames[2] = { arg1Name, arg2Name }; |
| 479 unsigned char argTypes[2]; | 480 unsigned char argTypes[2]; |
| 480 unsigned long long argValues[2]; | 481 unsigned long long argValues[2]; |
| 481 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); | 482 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); |
| 482 setTraceValue(arg2Val, &argTypes[1], &argValues[1]); | 483 setTraceValue(arg2Val, &argTypes[1], &argValues[1]); |
| 483 if (isConvertableToTraceFormat(arg1Val) || isConvertableToTraceFormat(arg2Va
l)) { | 484 if (isTracedValue(arg1Val) || isTracedValue(arg2Val)) { |
| 484 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 485 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 485 phase, categoryEnabled, name, id, bindId, timestamp, | 486 phase, categoryEnabled, name, id, bindId, timestamp, |
| 486 numArgs, argNames, argTypes, argValues, | 487 numArgs, argNames, argTypes, argValues, |
| 487 moveFromIfConvertableToTraceFormat(arg1Val), | 488 moveFromIfTracedValue(arg1Val), |
| 488 moveFromIfConvertableToTraceFormat(arg2Val), | 489 moveFromIfTracedValue(arg2Val), |
| 489 flags); | 490 flags); |
| 490 } | 491 } |
| 491 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 492 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 492 phase, categoryEnabled, name, id, bindId, timestamp, | 493 phase, categoryEnabled, name, id, bindId, timestamp, |
| 493 numArgs, argNames, argTypes, argValues, | 494 numArgs, argNames, argTypes, argValues, |
| 494 flags); | 495 flags); |
| 495 } | 496 } |
| 496 | 497 |
| 497 static inline TraceEventHandle addTraceEvent( | 498 static inline TraceEventHandle addTraceEvent( |
| 498 char phase, | 499 char phase, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 const char* m_categoryGroup; | 651 const char* m_categoryGroup; |
| 651 const char* m_name; | 652 const char* m_name; |
| 652 TraceContext m_context; | 653 TraceContext m_context; |
| 653 }; | 654 }; |
| 654 | 655 |
| 655 } // namespace TraceEvent | 656 } // namespace TraceEvent |
| 656 | 657 |
| 657 } // namespace blink | 658 } // namespace blink |
| 658 | 659 |
| 659 #endif | 660 #endif |
| OLD | NEW |