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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 template<typename T> struct TracedValueTraits { | 435 template<typename T> struct TracedValueTraits { |
436 static const bool isTracedValue = false; | 436 static const bool isTracedValue = false; |
437 static PassOwnPtr<TracedValue> moveFromIfTracedValue(const T&) | 437 static PassOwnPtr<TracedValue> moveFromIfTracedValue(const T&) |
438 { | 438 { |
439 return nullptr; | 439 return nullptr; |
440 } | 440 } |
441 }; | 441 }; |
442 | 442 |
443 template<typename T> struct TracedValueTraits<PassOwnPtr<T>> { | 443 template<typename T> struct TracedValueTraits<PassOwnPtr<T>> { |
444 static const bool isTracedValue = std::is_convertible<T*, TracedValue*>::val
ue; | 444 static const bool isTracedValue = std::is_convertible<T*, TracedValue*>::val
ue; |
445 static PassOwnPtr<TracedValue> moveFromIfTracedValue(const PassOwnPtr<T>& tr
acedValue) | 445 static PassOwnPtr<TracedValue> moveFromIfTracedValue(PassOwnPtr<T>&& tracedV
alue) |
446 { | 446 { |
447 return tracedValue; | 447 return std::move(tracedValue); |
448 } | 448 } |
449 }; | 449 }; |
450 | 450 |
451 template<typename T> bool isTracedValue(const T&) | 451 template<typename T> bool isTracedValue(const T&) |
452 { | 452 { |
453 return TracedValueTraits<T>::isTracedValue; | 453 return TracedValueTraits<T>::isTracedValue; |
454 } | 454 } |
455 | 455 |
456 template<typename T> PassOwnPtr<TracedValue> moveFromIfTracedValue(const T& valu
e) | 456 template<typename T> PassOwnPtr<TracedValue> moveFromIfTracedValue(T&& value) |
457 { | 457 { |
458 return TracedValueTraits<T>::moveFromIfTracedValue(value); | 458 return TracedValueTraits<T>::moveFromIfTracedValue(std::forward<T>(value)); |
459 } | 459 } |
460 | 460 |
461 // These addTraceEvent template functions are defined here instead of in the | 461 // These addTraceEvent template functions are defined here instead of in the |
462 // macro, because the arg values could be temporary string objects. In order to | 462 // macro, because the arg values could be temporary string objects. In order to |
463 // store pointers to the internal c_str and pass through to the tracing API, the | 463 // store pointers to the internal c_str and pass through to the tracing API, the |
464 // arg values must live throughout these procedures. | 464 // arg values must live throughout these procedures. |
465 | 465 |
466 static inline TraceEventHandle addTraceEvent( | 466 static inline TraceEventHandle addTraceEvent( |
467 char phase, | 467 char phase, |
468 const unsigned char* categoryEnabled, | 468 const unsigned char* categoryEnabled, |
(...skipping 14 matching lines...) Expand all Loading... |
483 static inline TraceEventHandle addTraceEvent( | 483 static inline TraceEventHandle addTraceEvent( |
484 char phase, | 484 char phase, |
485 const unsigned char* categoryEnabled, | 485 const unsigned char* categoryEnabled, |
486 const char* name, | 486 const char* name, |
487 const char* scope, | 487 const char* scope, |
488 unsigned long long id, | 488 unsigned long long id, |
489 unsigned long long bindId, | 489 unsigned long long bindId, |
490 double timestamp, | 490 double timestamp, |
491 unsigned flags, | 491 unsigned flags, |
492 const char* arg1Name, | 492 const char* arg1Name, |
493 const ARG1_TYPE& arg1Val) | 493 ARG1_TYPE&& arg1Val) |
494 { | 494 { |
495 const int numArgs = 1; | 495 const int numArgs = 1; |
496 unsigned char argTypes[1]; | 496 unsigned char argTypes[1]; |
497 unsigned long long argValues[1]; | 497 unsigned long long argValues[1]; |
498 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); | 498 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); |
499 if (isTracedValue(arg1Val)) { | 499 if (isTracedValue(arg1Val)) { |
500 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 500 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
501 phase, categoryEnabled, name, scope, id, bindId, timestamp, | 501 phase, categoryEnabled, name, scope, id, bindId, timestamp, |
502 numArgs, &arg1Name, argTypes, argValues, | 502 numArgs, &arg1Name, argTypes, argValues, |
503 moveFromIfTracedValue(arg1Val), | 503 moveFromIfTracedValue(std::forward<ARG1_TYPE>(arg1Val)), |
504 nullptr, | 504 nullptr, |
505 flags); | 505 flags); |
506 } | 506 } |
507 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 507 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
508 phase, categoryEnabled, name, scope, id, bindId, timestamp, | 508 phase, categoryEnabled, name, scope, id, bindId, timestamp, |
509 numArgs, &arg1Name, argTypes, argValues, | 509 numArgs, &arg1Name, argTypes, argValues, |
510 flags); | 510 flags); |
511 } | 511 } |
512 | 512 |
513 template<typename ARG1_TYPE, typename ARG2_TYPE> | 513 template<typename ARG1_TYPE, typename ARG2_TYPE> |
514 static inline TraceEventHandle addTraceEvent( | 514 static inline TraceEventHandle addTraceEvent( |
515 char phase, | 515 char phase, |
516 const unsigned char* categoryEnabled, | 516 const unsigned char* categoryEnabled, |
517 const char* name, | 517 const char* name, |
518 const char* scope, | 518 const char* scope, |
519 unsigned long long id, | 519 unsigned long long id, |
520 unsigned long long bindId, | 520 unsigned long long bindId, |
521 double timestamp, | 521 double timestamp, |
522 unsigned flags, | 522 unsigned flags, |
523 const char* arg1Name, | 523 const char* arg1Name, |
524 const ARG1_TYPE& arg1Val, | 524 ARG1_TYPE&& arg1Val, |
525 const char* arg2Name, | 525 const char* arg2Name, |
526 const ARG2_TYPE& arg2Val) | 526 ARG2_TYPE&& arg2Val) |
527 { | 527 { |
528 const int numArgs = 2; | 528 const int numArgs = 2; |
529 const char* argNames[2] = { arg1Name, arg2Name }; | 529 const char* argNames[2] = { arg1Name, arg2Name }; |
530 unsigned char argTypes[2]; | 530 unsigned char argTypes[2]; |
531 unsigned long long argValues[2]; | 531 unsigned long long argValues[2]; |
532 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); | 532 setTraceValue(arg1Val, &argTypes[0], &argValues[0]); |
533 setTraceValue(arg2Val, &argTypes[1], &argValues[1]); | 533 setTraceValue(arg2Val, &argTypes[1], &argValues[1]); |
534 if (isTracedValue(arg1Val) || isTracedValue(arg2Val)) { | 534 if (isTracedValue(arg1Val) || isTracedValue(arg2Val)) { |
535 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 535 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
536 phase, categoryEnabled, name, scope, id, bindId, timestamp, | 536 phase, categoryEnabled, name, scope, id, bindId, timestamp, |
537 numArgs, argNames, argTypes, argValues, | 537 numArgs, argNames, argTypes, argValues, |
538 moveFromIfTracedValue(arg1Val), | 538 moveFromIfTracedValue(std::forward<ARG1_TYPE>(arg1Val)), |
539 moveFromIfTracedValue(arg2Val), | 539 moveFromIfTracedValue(std::forward<ARG2_TYPE>(arg2Val)), |
540 flags); | 540 flags); |
541 } | 541 } |
542 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 542 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
543 phase, categoryEnabled, name, scope, id, bindId, timestamp, | 543 phase, categoryEnabled, name, scope, id, bindId, timestamp, |
544 numArgs, argNames, argTypes, argValues, | 544 numArgs, argNames, argTypes, argValues, |
545 flags); | 545 flags); |
546 } | 546 } |
547 | 547 |
548 static inline TraceEventHandle addTraceEvent( | 548 static inline TraceEventHandle addTraceEvent( |
549 char phase, | 549 char phase, |
550 const unsigned char* categoryEnabled, | 550 const unsigned char* categoryEnabled, |
551 const char* name, | 551 const char* name, |
552 const char* scope, | 552 const char* scope, |
553 unsigned long long id, | 553 unsigned long long id, |
554 unsigned flags) | 554 unsigned flags) |
555 { | 555 { |
556 return addTraceEvent(phase, categoryEnabled, name, scope, id, | 556 return addTraceEvent(phase, categoryEnabled, name, scope, id, |
557 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags); | 557 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags); |
558 } | 558 } |
559 | 559 |
560 template<typename ARG1_TYPE> | 560 template<typename ARG1_TYPE> |
561 static inline TraceEventHandle addTraceEvent( | 561 static inline TraceEventHandle addTraceEvent( |
562 char phase, | 562 char phase, |
563 const unsigned char* categoryEnabled, | 563 const unsigned char* categoryEnabled, |
564 const char* name, | 564 const char* name, |
565 const char* scope, | 565 const char* scope, |
566 unsigned long long id, | 566 unsigned long long id, |
567 unsigned flags, | 567 unsigned flags, |
568 const char* arg1Name, | 568 const char* arg1Name, |
569 const ARG1_TYPE& arg1Val) | 569 ARG1_TYPE&& arg1Val) |
570 { | 570 { |
571 return addTraceEvent(phase, categoryEnabled, name, scope, id, | 571 return addTraceEvent(phase, categoryEnabled, name, scope, id, |
572 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, | 572 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, |
573 arg1Name, arg1Val); | 573 arg1Name, std::forward<ARG1_TYPE>(arg1Val)); |
574 } | 574 } |
575 | 575 |
576 | 576 |
577 template<typename ARG1_TYPE, typename ARG2_TYPE> | 577 template<typename ARG1_TYPE, typename ARG2_TYPE> |
578 static inline TraceEventHandle addTraceEvent( | 578 static inline TraceEventHandle addTraceEvent( |
579 char phase, | 579 char phase, |
580 const unsigned char* categoryEnabled, | 580 const unsigned char* categoryEnabled, |
581 const char* name, | 581 const char* name, |
582 const char* scope, | 582 const char* scope, |
583 unsigned long long id, | 583 unsigned long long id, |
584 unsigned flags, | 584 unsigned flags, |
585 const char* arg1Name, | 585 const char* arg1Name, |
586 const ARG1_TYPE& arg1Val, | 586 ARG1_TYPE&& arg1Val, |
587 const char* arg2Name, | 587 const char* arg2Name, |
588 const ARG2_TYPE& arg2Val) | 588 ARG2_TYPE&& arg2Val) |
589 { | 589 { |
590 return addTraceEvent(phase, categoryEnabled, name, scope, id, | 590 return addTraceEvent(phase, categoryEnabled, name, scope, id, |
591 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, | 591 blink::TraceEvent::noBindId, EventTracer::systemTraceTime(), flags, |
592 arg1Name, arg1Val, arg2Name, arg2Val); | 592 arg1Name, std::forward<ARG1_TYPE>(arg1Val), |
| 593 arg2Name, std::forward<ARG2_TYPE>(arg2Val)); |
593 } | 594 } |
594 | 595 |
595 // Used by TRACE_EVENTx macro. Do not use directly. | 596 // Used by TRACE_EVENTx macro. Do not use directly. |
596 class ScopedTracer final { | 597 class ScopedTracer final { |
597 STACK_ALLOCATED(); | 598 STACK_ALLOCATED(); |
598 WTF_MAKE_NONCOPYABLE(ScopedTracer); | 599 WTF_MAKE_NONCOPYABLE(ScopedTracer); |
599 public: | 600 public: |
600 // Note: members of m_data intentionally left uninitialized. See initialize. | 601 // Note: members of m_data intentionally left uninitialized. See initialize. |
601 ScopedTracer() : m_pdata(0) { } | 602 ScopedTracer() : m_pdata(0) { } |
602 ~ScopedTracer() | 603 ~ScopedTracer() |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 const char* m_categoryGroup; | 682 const char* m_categoryGroup; |
682 const char* m_name; | 683 const char* m_name; |
683 IDType m_id; | 684 IDType m_id; |
684 }; | 685 }; |
685 | 686 |
686 } // namespace TraceEvent | 687 } // namespace TraceEvent |
687 | 688 |
688 } // namespace blink | 689 } // namespace blink |
689 | 690 |
690 #endif | 691 #endif |
OLD | NEW |