| 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() { |
| 81 TraceLog* trace_log = TraceLog::GetInstance(); |
| 82 sampling_profiler_->EnableSamplingEventForTesting(); |
| 83 trace_log->SetEnabled( |
| 84 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), |
| 85 TraceLog::RECORDING_MODE, TraceOptions()); |
| 86 base::RunLoop().RunUntilIdle(); |
| 87 KickV8(); // Make a call to V8 so it can invoke interrupt request |
| 88 // callbacks. |
| 89 base::RunLoop().RunUntilIdle(); |
| 90 sampling_profiler_->WaitSamplingEventForTesting(); |
| 91 trace_log->SetDisabled(); |
| 92 SyncFlush(trace_log); |
| 93 } |
| 94 |
| 95 int CountEvents(const std::string& name) const { |
| 96 size_t trace_parsed_count = trace_parsed_.GetSize(); |
| 97 int events_count = 0; |
| 98 for (size_t i = 0; i < trace_parsed_count; i++) { |
| 99 const DictionaryValue* dict; |
| 100 if (!trace_parsed_.GetDictionary(i, &dict)) |
| 101 continue; |
| 102 std::string value; |
| 103 if (!dict->GetString("cat", &value) || |
| 104 value != TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")) |
| 105 continue; |
| 106 if (!dict->GetString("name", &value) || value != name) |
| 107 continue; |
| 108 ++events_count; |
| 109 } |
| 110 return events_count; |
| 111 } |
| 112 |
| 80 scoped_ptr<V8SamplingProfiler> sampling_profiler_; | 113 scoped_ptr<V8SamplingProfiler> sampling_profiler_; |
| 81 base::Lock lock_; | 114 base::Lock lock_; |
| 82 | 115 |
| 83 ListValue trace_parsed_; | 116 ListValue trace_parsed_; |
| 84 TraceResultBuffer trace_buffer_; | 117 TraceResultBuffer trace_buffer_; |
| 85 TraceResultBuffer::SimpleOutput json_output_; | 118 TraceResultBuffer::SimpleOutput json_output_; |
| 86 }; | 119 }; |
| 87 | 120 |
| 88 TEST_F(V8SamplingProfilerTest, V8SamplingEventFired) { | 121 // TODO(alph): Implement on Windows and Android |
| 89 scoped_ptr<V8SamplingProfiler> sampling_profiler( | 122 // The SamplingEventForTesting is fired when the framework collected at |
| 90 new V8SamplingProfiler(true)); | 123 // least one JitCodeAdded event and one sample event. |
| 91 sampling_profiler->EnableSamplingEventForTesting(); | 124 |
| 125 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 126 #define MAYBE(x) DISABLED_##x |
| 127 #else |
| 128 #define MAYBE(x) x |
| 129 #endif |
| 130 |
| 131 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingEventFired)) { |
| 132 sampling_profiler_->EnableSamplingEventForTesting(); |
| 92 TraceLog::GetInstance()->SetEnabled( | 133 TraceLog::GetInstance()->SetEnabled( |
| 93 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), | 134 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), |
| 94 TraceLog::RECORDING_MODE, TraceOptions()); | 135 TraceLog::RECORDING_MODE, TraceOptions()); |
| 95 sampling_profiler->WaitSamplingEventForTesting(); | 136 base::RunLoop().RunUntilIdle(); |
| 137 sampling_profiler_->WaitSamplingEventForTesting(); |
| 96 TraceLog::GetInstance()->SetDisabled(); | 138 TraceLog::GetInstance()->SetDisabled(); |
| 97 } | 139 } |
| 98 | 140 |
| 99 TEST_F(V8SamplingProfilerTest, V8SamplingJitCodeEventsCollected) { | 141 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingJitCodeEventsCollected)) { |
| 100 TraceLog* trace_log = TraceLog::GetInstance(); | 142 CollectTrace(); |
| 101 trace_log->SetEnabled( | 143 int jit_code_added_events_count = CountEvents("JitCodeAdded"); |
| 102 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")), | |
| 103 TraceLog::RECORDING_MODE, TraceOptions()); | |
| 104 KickV8(); // Make a call to V8 so it can invoke interrupt request callbacks. | |
| 105 trace_log->SetDisabled(); | |
| 106 SyncFlush(trace_log); | |
| 107 size_t trace_parsed_count = trace_parsed_.GetSize(); | |
| 108 int jit_code_added_events_count = 0; | |
| 109 for (size_t i = 0; i < trace_parsed_count; i++) { | |
| 110 const DictionaryValue* dict; | |
| 111 if (!trace_parsed_.GetDictionary(i, &dict)) | |
| 112 continue; | |
| 113 std::string value; | |
| 114 if (!dict->GetString("cat", &value) || | |
| 115 value != TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")) | |
| 116 continue; | |
| 117 if (!dict->GetString("name", &value) || value != "JitCodeAdded") | |
| 118 continue; | |
| 119 ++jit_code_added_events_count; | |
| 120 } | |
| 121 CHECK_LT(0, jit_code_added_events_count); | 144 CHECK_LT(0, jit_code_added_events_count); |
| 122 base::RunLoop().RunUntilIdle(); | 145 base::RunLoop().RunUntilIdle(); |
| 123 } | 146 } |
| 124 | 147 |
| 148 TEST_F(V8SamplingProfilerTest, MAYBE(V8SamplingSamplesCollected)) { |
| 149 CollectTrace(); |
| 150 int sample_events_count = CountEvents("V8Sample"); |
| 151 CHECK_LT(0, sample_events_count); |
| 152 base::RunLoop().RunUntilIdle(); |
| 153 } |
| 154 |
| 125 } // namespace content | 155 } // namespace content |
| OLD | NEW |