Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: content/renderer/devtools/v8_sampling_profiler_browsertest.cc

Issue 792903003: V8 Sampling Profiler: Collect V8 JitCodeEvents in tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the test under Debug mode. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/devtools/v8_sampling_profiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
6 #include "base/run_loop.h"
5 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "content/public/test/render_view_test.h"
6 #include "content/renderer/devtools/v8_sampling_profiler.h" 9 #include "content/renderer/devtools/v8_sampling_profiler.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 10
11 using base::DictionaryValue;
12 using base::ListValue;
13 using base::Value;
9 using base::trace_event::CategoryFilter; 14 using base::trace_event::CategoryFilter;
10 using base::trace_event::TraceLog; 15 using base::trace_event::TraceLog;
11 using base::trace_event::TraceOptions; 16 using base::trace_event::TraceOptions;
17 using base::trace_event::TraceResultBuffer;
12 18
13 namespace content { 19 namespace content {
14 20
15 class V8SamplingProfilerTest : public testing::Test {}; 21 class V8SamplingProfilerTest : public RenderViewTest {
22 public:
23 void SetUp() override {
24 RenderViewTest::SetUp();
25 sampling_profiler_.reset(new V8SamplingProfiler(true));
26 trace_buffer_.SetOutputCallback(json_output_.GetCallback());
27 }
28
29 void TearDown() override {
30 sampling_profiler_.reset();
31 RenderViewTest::TearDown();
32 }
33
34 void KickV8() { ExecuteJavaScript("1"); }
35
36 void SyncFlush(TraceLog* trace_log) {
37 base::WaitableEvent flush_complete_event(false, false);
38 trace_log->Flush(
39 base::Bind(&V8SamplingProfilerTest::OnTraceDataCollected,
40 base::Unretained(static_cast<V8SamplingProfilerTest*>(this)),
41 base::Unretained(&flush_complete_event)));
42 base::RunLoop().RunUntilIdle();
43 flush_complete_event.Wait();
44 }
45
46 void OnTraceDataCollected(
47 base::WaitableEvent* flush_complete_event,
48 const scoped_refptr<base::RefCountedString>& events_str,
49 bool has_more_events) {
50 base::AutoLock lock(lock_);
51 json_output_.json_output.clear();
52 trace_buffer_.Start();
53 trace_buffer_.AddFragment(events_str->data());
54 trace_buffer_.Finish();
55
56 scoped_ptr<Value> root;
57 root.reset(base::JSONReader::Read(
58 json_output_.json_output,
59 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN));
60
61 if (!root.get()) {
62 LOG(ERROR) << json_output_.json_output;
63 }
64
65 ListValue* root_list = NULL;
66 ASSERT_TRUE(root.get());
67 ASSERT_TRUE(root->GetAsList(&root_list));
68
69 // Move items into our aggregate collection
70 while (root_list->GetSize()) {
71 scoped_ptr<Value> item;
72 root_list->Remove(0, &item);
73 trace_parsed_.Append(item.release());
74 }
75
76 if (!has_more_events)
77 flush_complete_event->Signal();
78 }
79
80 scoped_ptr<V8SamplingProfiler> sampling_profiler_;
81 base::Lock lock_;
82
83 ListValue trace_parsed_;
84 TraceResultBuffer trace_buffer_;
85 TraceResultBuffer::SimpleOutput json_output_;
86 };
16 87
17 TEST_F(V8SamplingProfilerTest, V8SamplingEventFired) { 88 TEST_F(V8SamplingProfilerTest, V8SamplingEventFired) {
18 scoped_ptr<V8SamplingProfiler> sampling_profiler(new V8SamplingProfiler()); 89 scoped_ptr<V8SamplingProfiler> sampling_profiler(
90 new V8SamplingProfiler(true));
19 sampling_profiler->EnableSamplingEventForTesting(); 91 sampling_profiler->EnableSamplingEventForTesting();
20 TraceLog::GetInstance()->SetEnabled( 92 TraceLog::GetInstance()->SetEnabled(
21 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8_cpu_profile")), 93 CategoryFilter(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")),
22 TraceLog::RECORDING_MODE, TraceOptions()); 94 TraceLog::RECORDING_MODE, TraceOptions());
23 sampling_profiler->WaitSamplingEventForTesting(); 95 sampling_profiler->WaitSamplingEventForTesting();
24 TraceLog::GetInstance()->SetDisabled(); 96 TraceLog::GetInstance()->SetDisabled();
25 } 97 }
26 98
99 TEST_F(V8SamplingProfilerTest, V8SamplingJitCodeEventsCollected) {
100 TraceLog* trace_log = TraceLog::GetInstance();
101 trace_log->SetEnabled(
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);
122 base::RunLoop().RunUntilIdle();
123 }
124
27 } // namespace content 125 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/devtools/v8_sampling_profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698