OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/trace_event/trace_event.h" | 5 #include "base/trace_event/trace_event.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 BeginSpecificTrace("*"); | 89 BeginSpecificTrace("*"); |
90 } | 90 } |
91 | 91 |
92 void BeginSpecificTrace(const std::string& filter) { | 92 void BeginSpecificTrace(const std::string& filter) { |
93 event_watch_notification_ = 0; | 93 event_watch_notification_ = 0; |
94 TraceLog::GetInstance()->SetEnabled(TraceConfig(filter, ""), | 94 TraceLog::GetInstance()->SetEnabled(TraceConfig(filter, ""), |
95 TraceLog::RECORDING_MODE); | 95 TraceLog::RECORDING_MODE); |
96 } | 96 } |
97 | 97 |
98 void CancelTrace() { | 98 void CancelTrace() { |
99 WaitableEvent flush_complete_event(false, false); | 99 WaitableEvent flush_complete_event( |
| 100 WaitableEvent::ResetPolicy::AUTOMATIC, |
| 101 WaitableEvent::InitialState::NOT_SIGNALED); |
100 CancelTraceAsync(&flush_complete_event); | 102 CancelTraceAsync(&flush_complete_event); |
101 flush_complete_event.Wait(); | 103 flush_complete_event.Wait(); |
102 } | 104 } |
103 | 105 |
104 void EndTraceAndFlush() { | 106 void EndTraceAndFlush() { |
105 num_flush_callbacks_ = 0; | 107 num_flush_callbacks_ = 0; |
106 WaitableEvent flush_complete_event(false, false); | 108 WaitableEvent flush_complete_event( |
| 109 WaitableEvent::ResetPolicy::AUTOMATIC, |
| 110 WaitableEvent::InitialState::NOT_SIGNALED); |
107 EndTraceAndFlushAsync(&flush_complete_event); | 111 EndTraceAndFlushAsync(&flush_complete_event); |
108 flush_complete_event.Wait(); | 112 flush_complete_event.Wait(); |
109 } | 113 } |
110 | 114 |
111 // Used when testing thread-local buffers which requires the thread initiating | 115 // Used when testing thread-local buffers which requires the thread initiating |
112 // flush to have a message loop. | 116 // flush to have a message loop. |
113 void EndTraceAndFlushInThreadWithMessageLoop() { | 117 void EndTraceAndFlushInThreadWithMessageLoop() { |
114 WaitableEvent flush_complete_event(false, false); | 118 WaitableEvent flush_complete_event( |
| 119 WaitableEvent::ResetPolicy::AUTOMATIC, |
| 120 WaitableEvent::InitialState::NOT_SIGNALED); |
115 Thread flush_thread("flush"); | 121 Thread flush_thread("flush"); |
116 flush_thread.Start(); | 122 flush_thread.Start(); |
117 flush_thread.task_runner()->PostTask( | 123 flush_thread.task_runner()->PostTask( |
118 FROM_HERE, base::Bind(&TraceEventTestFixture::EndTraceAndFlushAsync, | 124 FROM_HERE, base::Bind(&TraceEventTestFixture::EndTraceAndFlushAsync, |
119 base::Unretained(this), &flush_complete_event)); | 125 base::Unretained(this), &flush_complete_event)); |
120 flush_complete_event.Wait(); | 126 flush_complete_event.Wait(); |
121 } | 127 } |
122 | 128 |
123 void CancelTraceAsync(WaitableEvent* flush_complete_event) { | 129 void CancelTraceAsync(WaitableEvent* flush_complete_event) { |
124 TraceLog::GetInstance()->CancelTracing( | 130 TraceLog::GetInstance()->CancelTracing( |
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 EXPECT_TRUE(event2->parameter_copy_storage() == NULL); | 1608 EXPECT_TRUE(event2->parameter_copy_storage() == NULL); |
1603 EndTraceAndFlush(); | 1609 EndTraceAndFlush(); |
1604 } | 1610 } |
1605 } | 1611 } |
1606 | 1612 |
1607 // Test that data sent from other threads is gathered | 1613 // Test that data sent from other threads is gathered |
1608 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { | 1614 TEST_F(TraceEventTestFixture, DataCapturedOnThread) { |
1609 BeginTrace(); | 1615 BeginTrace(); |
1610 | 1616 |
1611 Thread thread("1"); | 1617 Thread thread("1"); |
1612 WaitableEvent task_complete_event(false, false); | 1618 WaitableEvent task_complete_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1619 WaitableEvent::InitialState::NOT_SIGNALED); |
1613 thread.Start(); | 1620 thread.Start(); |
1614 | 1621 |
1615 thread.task_runner()->PostTask( | 1622 thread.task_runner()->PostTask( |
1616 FROM_HERE, base::Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 1623 FROM_HERE, base::Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
1617 task_complete_event.Wait(); | 1624 task_complete_event.Wait(); |
1618 thread.Stop(); | 1625 thread.Stop(); |
1619 | 1626 |
1620 EndTraceAndFlush(); | 1627 EndTraceAndFlush(); |
1621 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 1628 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
1622 } | 1629 } |
1623 | 1630 |
1624 // Test that data sent from multiple threads is gathered | 1631 // Test that data sent from multiple threads is gathered |
1625 TEST_F(TraceEventTestFixture, DataCapturedManyThreads) { | 1632 TEST_F(TraceEventTestFixture, DataCapturedManyThreads) { |
1626 BeginTrace(); | 1633 BeginTrace(); |
1627 | 1634 |
1628 const int num_threads = 4; | 1635 const int num_threads = 4; |
1629 const int num_events = 4000; | 1636 const int num_events = 4000; |
1630 Thread* threads[num_threads]; | 1637 Thread* threads[num_threads]; |
1631 WaitableEvent* task_complete_events[num_threads]; | 1638 WaitableEvent* task_complete_events[num_threads]; |
1632 for (int i = 0; i < num_threads; i++) { | 1639 for (int i = 0; i < num_threads; i++) { |
1633 threads[i] = new Thread(StringPrintf("Thread %d", i)); | 1640 threads[i] = new Thread(StringPrintf("Thread %d", i)); |
1634 task_complete_events[i] = new WaitableEvent(false, false); | 1641 task_complete_events[i] = |
| 1642 new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1643 WaitableEvent::InitialState::NOT_SIGNALED); |
1635 threads[i]->Start(); | 1644 threads[i]->Start(); |
1636 threads[i]->task_runner()->PostTask( | 1645 threads[i]->task_runner()->PostTask( |
1637 FROM_HERE, base::Bind(&TraceManyInstantEvents, i, num_events, | 1646 FROM_HERE, base::Bind(&TraceManyInstantEvents, i, num_events, |
1638 task_complete_events[i])); | 1647 task_complete_events[i])); |
1639 } | 1648 } |
1640 | 1649 |
1641 for (int i = 0; i < num_threads; i++) { | 1650 for (int i = 0; i < num_threads; i++) { |
1642 task_complete_events[i]->Wait(); | 1651 task_complete_events[i]->Wait(); |
1643 } | 1652 } |
1644 | 1653 |
(...skipping 26 matching lines...) Expand all Loading... |
1671 PlatformThreadId thread_ids[kNumThreads]; | 1680 PlatformThreadId thread_ids[kNumThreads]; |
1672 for (int i = 0; i < kNumThreads; i++) | 1681 for (int i = 0; i < kNumThreads; i++) |
1673 threads[i] = new Thread(StringPrintf("Thread %d", i)); | 1682 threads[i] = new Thread(StringPrintf("Thread %d", i)); |
1674 | 1683 |
1675 // Enable tracing. | 1684 // Enable tracing. |
1676 BeginTrace(); | 1685 BeginTrace(); |
1677 | 1686 |
1678 // Now run some trace code on these threads. | 1687 // Now run some trace code on these threads. |
1679 WaitableEvent* task_complete_events[kNumThreads]; | 1688 WaitableEvent* task_complete_events[kNumThreads]; |
1680 for (int i = 0; i < kNumThreads; i++) { | 1689 for (int i = 0; i < kNumThreads; i++) { |
1681 task_complete_events[i] = new WaitableEvent(false, false); | 1690 task_complete_events[i] = |
| 1691 new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1692 WaitableEvent::InitialState::NOT_SIGNALED); |
1682 threads[i]->Start(); | 1693 threads[i]->Start(); |
1683 thread_ids[i] = threads[i]->GetThreadId(); | 1694 thread_ids[i] = threads[i]->GetThreadId(); |
1684 threads[i]->task_runner()->PostTask( | 1695 threads[i]->task_runner()->PostTask( |
1685 FROM_HERE, base::Bind(&TraceManyInstantEvents, i, kNumEvents, | 1696 FROM_HERE, base::Bind(&TraceManyInstantEvents, i, kNumEvents, |
1686 task_complete_events[i])); | 1697 task_complete_events[i])); |
1687 } | 1698 } |
1688 for (int i = 0; i < kNumThreads; i++) { | 1699 for (int i = 0; i < kNumThreads; i++) { |
1689 task_complete_events[i]->Wait(); | 1700 task_complete_events[i]->Wait(); |
1690 } | 1701 } |
1691 | 1702 |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2816 void BlockUntilStopped(WaitableEvent* task_start_event, | 2827 void BlockUntilStopped(WaitableEvent* task_start_event, |
2817 WaitableEvent* task_stop_event) { | 2828 WaitableEvent* task_stop_event) { |
2818 task_start_event->Signal(); | 2829 task_start_event->Signal(); |
2819 task_stop_event->Wait(); | 2830 task_stop_event->Wait(); |
2820 } | 2831 } |
2821 | 2832 |
2822 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopBeforeTracing) { | 2833 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopBeforeTracing) { |
2823 BeginTrace(); | 2834 BeginTrace(); |
2824 | 2835 |
2825 Thread thread("1"); | 2836 Thread thread("1"); |
2826 WaitableEvent task_complete_event(false, false); | 2837 WaitableEvent task_complete_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2838 WaitableEvent::InitialState::NOT_SIGNALED); |
2827 thread.Start(); | 2839 thread.Start(); |
2828 thread.task_runner()->PostTask( | 2840 thread.task_runner()->PostTask( |
2829 FROM_HERE, Bind(&TraceLog::SetCurrentThreadBlocksMessageLoop, | 2841 FROM_HERE, Bind(&TraceLog::SetCurrentThreadBlocksMessageLoop, |
2830 Unretained(TraceLog::GetInstance()))); | 2842 Unretained(TraceLog::GetInstance()))); |
2831 | 2843 |
2832 thread.task_runner()->PostTask( | 2844 thread.task_runner()->PostTask( |
2833 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 2845 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
2834 task_complete_event.Wait(); | 2846 task_complete_event.Wait(); |
2835 | 2847 |
2836 WaitableEvent task_start_event(false, false); | 2848 WaitableEvent task_start_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
2837 WaitableEvent task_stop_event(false, false); | 2849 WaitableEvent::InitialState::NOT_SIGNALED); |
| 2850 WaitableEvent task_stop_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2851 WaitableEvent::InitialState::NOT_SIGNALED); |
2838 thread.task_runner()->PostTask( | 2852 thread.task_runner()->PostTask( |
2839 FROM_HERE, Bind(&BlockUntilStopped, &task_start_event, &task_stop_event)); | 2853 FROM_HERE, Bind(&BlockUntilStopped, &task_start_event, &task_stop_event)); |
2840 task_start_event.Wait(); | 2854 task_start_event.Wait(); |
2841 | 2855 |
2842 EndTraceAndFlush(); | 2856 EndTraceAndFlush(); |
2843 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 2857 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
2844 | 2858 |
2845 task_stop_event.Signal(); | 2859 task_stop_event.Signal(); |
2846 thread.Stop(); | 2860 thread.Stop(); |
2847 } | 2861 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2888 void SetBlockingFlagAndBlockUntilStopped(WaitableEvent* task_start_event, | 2902 void SetBlockingFlagAndBlockUntilStopped(WaitableEvent* task_start_event, |
2889 WaitableEvent* task_stop_event) { | 2903 WaitableEvent* task_stop_event) { |
2890 TraceLog::GetInstance()->SetCurrentThreadBlocksMessageLoop(); | 2904 TraceLog::GetInstance()->SetCurrentThreadBlocksMessageLoop(); |
2891 BlockUntilStopped(task_start_event, task_stop_event); | 2905 BlockUntilStopped(task_start_event, task_stop_event); |
2892 } | 2906 } |
2893 | 2907 |
2894 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopAfterTracing) { | 2908 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopAfterTracing) { |
2895 BeginTrace(); | 2909 BeginTrace(); |
2896 | 2910 |
2897 Thread thread("1"); | 2911 Thread thread("1"); |
2898 WaitableEvent task_complete_event(false, false); | 2912 WaitableEvent task_complete_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2913 WaitableEvent::InitialState::NOT_SIGNALED); |
2899 thread.Start(); | 2914 thread.Start(); |
2900 | 2915 |
2901 thread.task_runner()->PostTask( | 2916 thread.task_runner()->PostTask( |
2902 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 2917 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
2903 task_complete_event.Wait(); | 2918 task_complete_event.Wait(); |
2904 | 2919 |
2905 WaitableEvent task_start_event(false, false); | 2920 WaitableEvent task_start_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
2906 WaitableEvent task_stop_event(false, false); | 2921 WaitableEvent::InitialState::NOT_SIGNALED); |
| 2922 WaitableEvent task_stop_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2923 WaitableEvent::InitialState::NOT_SIGNALED); |
2907 thread.task_runner()->PostTask( | 2924 thread.task_runner()->PostTask( |
2908 FROM_HERE, Bind(&SetBlockingFlagAndBlockUntilStopped, &task_start_event, | 2925 FROM_HERE, Bind(&SetBlockingFlagAndBlockUntilStopped, &task_start_event, |
2909 &task_stop_event)); | 2926 &task_stop_event)); |
2910 task_start_event.Wait(); | 2927 task_start_event.Wait(); |
2911 | 2928 |
2912 EndTraceAndFlush(); | 2929 EndTraceAndFlush(); |
2913 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 2930 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
2914 | 2931 |
2915 task_stop_event.Signal(); | 2932 task_stop_event.Signal(); |
2916 thread.Stop(); | 2933 thread.Stop(); |
2917 } | 2934 } |
2918 | 2935 |
2919 TEST_F(TraceEventTestFixture, ThreadOnceBlocking) { | 2936 TEST_F(TraceEventTestFixture, ThreadOnceBlocking) { |
2920 BeginTrace(); | 2937 BeginTrace(); |
2921 | 2938 |
2922 Thread thread("1"); | 2939 Thread thread("1"); |
2923 WaitableEvent task_complete_event(false, false); | 2940 WaitableEvent task_complete_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2941 WaitableEvent::InitialState::NOT_SIGNALED); |
2924 thread.Start(); | 2942 thread.Start(); |
2925 | 2943 |
2926 thread.task_runner()->PostTask( | 2944 thread.task_runner()->PostTask( |
2927 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 2945 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
2928 task_complete_event.Wait(); | 2946 task_complete_event.Wait(); |
2929 task_complete_event.Reset(); | 2947 task_complete_event.Reset(); |
2930 | 2948 |
2931 WaitableEvent task_start_event(false, false); | 2949 WaitableEvent task_start_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
2932 WaitableEvent task_stop_event(false, false); | 2950 WaitableEvent::InitialState::NOT_SIGNALED); |
| 2951 WaitableEvent task_stop_event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 2952 WaitableEvent::InitialState::NOT_SIGNALED); |
2933 thread.task_runner()->PostTask( | 2953 thread.task_runner()->PostTask( |
2934 FROM_HERE, Bind(&BlockUntilStopped, &task_start_event, &task_stop_event)); | 2954 FROM_HERE, Bind(&BlockUntilStopped, &task_start_event, &task_stop_event)); |
2935 task_start_event.Wait(); | 2955 task_start_event.Wait(); |
2936 | 2956 |
2937 // The thread will timeout in this flush. | 2957 // The thread will timeout in this flush. |
2938 EndTraceAndFlushInThreadWithMessageLoop(); | 2958 EndTraceAndFlushInThreadWithMessageLoop(); |
2939 Clear(); | 2959 Clear(); |
2940 | 2960 |
2941 // Let the thread's message loop continue to spin. | 2961 // Let the thread's message loop continue to spin. |
2942 task_stop_event.Signal(); | 2962 task_stop_event.Signal(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 } | 3114 } |
3095 | 3115 |
3096 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { | 3116 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { |
3097 const char filter[] = "DELAY(test.Delay;16;oneshot)"; | 3117 const char filter[] = "DELAY(test.Delay;16;oneshot)"; |
3098 TraceConfig config(filter, ""); | 3118 TraceConfig config(filter, ""); |
3099 EXPECT_EQ(filter, config.ToCategoryFilterString()); | 3119 EXPECT_EQ(filter, config.ToCategoryFilterString()); |
3100 } | 3120 } |
3101 | 3121 |
3102 } // namespace trace_event | 3122 } // namespace trace_event |
3103 } // namespace base | 3123 } // namespace base |
OLD | NEW |