OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "content/public/test/render_view_test.h" | 8 #include "content/public/test/render_view_test.h" |
9 #include "content/renderer/devtools/v8_sampling_profiler.h" | 9 #include "content/renderer/devtools/v8_sampling_profiler.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 while (root_list->GetSize()) { | 70 while (root_list->GetSize()) { |
71 scoped_ptr<Value> item; | 71 scoped_ptr<Value> item; |
72 root_list->Remove(0, &item); | 72 root_list->Remove(0, &item); |
73 trace_parsed_.Append(item.release()); | 73 trace_parsed_.Append(item.release()); |
74 } | 74 } |
75 | 75 |
76 if (!has_more_events) | 76 if (!has_more_events) |
77 flush_complete_event->Signal(); | 77 flush_complete_event->Signal(); |
78 } | 78 } |
79 | 79 |
80 void CollectTrace() { | 80 void CollectTrace(int code_added_events, int sample_events) { |
81 TraceLog* trace_log = TraceLog::GetInstance(); | 81 TraceLog* trace_log = TraceLog::GetInstance(); |
82 sampling_profiler_->EnableSamplingEventForTesting(); | 82 sampling_profiler_->EnableSamplingEventForTesting(code_added_events, |
| 83 sample_events); |
83 trace_log->SetEnabled( | 84 trace_log->SetEnabled( |
84 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), | 85 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), |
85 TraceLog::RECORDING_MODE, TraceOptions()); | 86 TraceLog::RECORDING_MODE, TraceOptions()); |
86 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
87 KickV8(); // Make a call to V8 so it can invoke interrupt request | 88 KickV8(); // Make a call to V8 so it can invoke interrupt request |
88 // callbacks. | 89 // callbacks. |
89 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
90 sampling_profiler_->WaitSamplingEventForTesting(); | 91 sampling_profiler_->WaitSamplingEventForTesting(); |
91 trace_log->SetDisabled(); | 92 trace_log->SetDisabled(); |
92 SyncFlush(trace_log); | 93 SyncFlush(trace_log); |
(...skipping 29 matching lines...) Expand all Loading... |
122 // The SamplingEventForTesting is fired when the framework collected at | 123 // The SamplingEventForTesting is fired when the framework collected at |
123 // least one JitCodeAdded event and one sample event. | 124 // least one JitCodeAdded event and one sample event. |
124 | 125 |
125 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
126 #define MAYBE(x) DISABLED_##x | 127 #define MAYBE(x) DISABLED_##x |
127 #else | 128 #else |
128 #define MAYBE(x) x | 129 #define MAYBE(x) x |
129 #endif | 130 #endif |
130 | 131 |
131 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingEventFired)) { | 132 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingEventFired)) { |
132 sampling_profiler_->EnableSamplingEventForTesting(); | 133 sampling_profiler_->EnableSamplingEventForTesting(0, 0); |
133 TraceLog::GetInstance()->SetEnabled( | 134 TraceLog::GetInstance()->SetEnabled( |
134 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), | 135 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), |
135 TraceLog::RECORDING_MODE, TraceOptions()); | 136 TraceLog::RECORDING_MODE, TraceOptions()); |
136 base::RunLoop().RunUntilIdle(); | 137 base::RunLoop().RunUntilIdle(); |
137 sampling_profiler_->WaitSamplingEventForTesting(); | 138 sampling_profiler_->WaitSamplingEventForTesting(); |
138 TraceLog::GetInstance()->SetDisabled(); | 139 TraceLog::GetInstance()->SetDisabled(); |
139 } | 140 } |
140 | 141 |
141 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingJitCodeEventsCollected)) { | 142 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingJitCodeEventsCollected)) { |
142 CollectTrace(); | 143 CollectTrace(1, 0); |
143 int jit_code_added_events_count = CountEvents("JitCodeAdded"); | 144 int jit_code_added_events_count = CountEvents("JitCodeAdded"); |
144 CHECK_LT(0, jit_code_added_events_count); | 145 CHECK_LT(0, jit_code_added_events_count); |
145 base::RunLoop().RunUntilIdle(); | 146 base::RunLoop().RunUntilIdle(); |
146 } | 147 } |
147 | 148 |
148 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingSamplesCollected)) { | 149 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingSamplesCollected)) { |
149 CollectTrace(); | 150 CollectTrace(0, 1); |
150 int sample_events_count = CountEvents("V8Sample"); | 151 int sample_events_count = CountEvents("V8Sample"); |
151 CHECK_LT(0, sample_events_count); | 152 CHECK_LT(0, sample_events_count); |
152 base::RunLoop().RunUntilIdle(); | 153 base::RunLoop().RunUntilIdle(); |
153 } | 154 } |
154 | 155 |
155 } // namespace content | 156 } // namespace content |
OLD | NEW |