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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/trace_event/trace_buffer.h" | 10 #include "base/trace_event/trace_buffer.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 void OnTraceDataCollected( | 49 void OnTraceDataCollected( |
50 base::WaitableEvent* flush_complete_event, | 50 base::WaitableEvent* flush_complete_event, |
51 const scoped_refptr<base::RefCountedString>& events_str, | 51 const scoped_refptr<base::RefCountedString>& events_str, |
52 bool has_more_events) { | 52 bool has_more_events) { |
53 base::AutoLock lock(lock_); | 53 base::AutoLock lock(lock_); |
54 json_output_.json_output.clear(); | 54 json_output_.json_output.clear(); |
55 trace_buffer_.Start(); | 55 trace_buffer_.Start(); |
56 trace_buffer_.AddFragment(events_str->data()); | 56 trace_buffer_.AddFragment(events_str->data()); |
57 trace_buffer_.Finish(); | 57 trace_buffer_.Finish(); |
58 | 58 |
59 scoped_ptr<Value> root; | 59 std::unique_ptr<Value> root; |
60 root = base::JSONReader::Read( | 60 root = base::JSONReader::Read( |
61 json_output_.json_output, | 61 json_output_.json_output, |
62 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN); | 62 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN); |
63 | 63 |
64 if (!root.get()) { | 64 if (!root.get()) { |
65 LOG(ERROR) << json_output_.json_output; | 65 LOG(ERROR) << json_output_.json_output; |
66 } | 66 } |
67 | 67 |
68 ListValue* root_list = NULL; | 68 ListValue* root_list = NULL; |
69 ASSERT_TRUE(root.get()); | 69 ASSERT_TRUE(root.get()); |
70 ASSERT_TRUE(root->GetAsList(&root_list)); | 70 ASSERT_TRUE(root->GetAsList(&root_list)); |
71 | 71 |
72 // Move items into our aggregate collection | 72 // Move items into our aggregate collection |
73 while (root_list->GetSize()) { | 73 while (root_list->GetSize()) { |
74 scoped_ptr<Value> item; | 74 std::unique_ptr<Value> item; |
75 root_list->Remove(0, &item); | 75 root_list->Remove(0, &item); |
76 trace_parsed_.Append(item.release()); | 76 trace_parsed_.Append(item.release()); |
77 } | 77 } |
78 | 78 |
79 if (!has_more_events) | 79 if (!has_more_events) |
80 flush_complete_event->Signal(); | 80 flush_complete_event->Signal(); |
81 } | 81 } |
82 | 82 |
83 void CollectTrace(int code_added_events, int sample_events) { | 83 void CollectTrace(int code_added_events, int sample_events) { |
84 TraceLog* trace_log = TraceLog::GetInstance(); | 84 TraceLog* trace_log = TraceLog::GetInstance(); |
(...skipping 22 matching lines...) Expand all Loading... |
107 if (!dict->GetString("cat", &value) || | 107 if (!dict->GetString("cat", &value) || |
108 value != TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")) | 108 value != TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile")) |
109 continue; | 109 continue; |
110 if (!dict->GetString("name", &value) || value != name) | 110 if (!dict->GetString("name", &value) || value != name) |
111 continue; | 111 continue; |
112 ++events_count; | 112 ++events_count; |
113 } | 113 } |
114 return events_count; | 114 return events_count; |
115 } | 115 } |
116 | 116 |
117 scoped_ptr<V8SamplingProfiler> sampling_profiler_; | 117 std::unique_ptr<V8SamplingProfiler> sampling_profiler_; |
118 base::Lock lock_; | 118 base::Lock lock_; |
119 | 119 |
120 ListValue trace_parsed_; | 120 ListValue trace_parsed_; |
121 TraceResultBuffer trace_buffer_; | 121 TraceResultBuffer trace_buffer_; |
122 TraceResultBuffer::SimpleOutput json_output_; | 122 TraceResultBuffer::SimpleOutput json_output_; |
123 }; | 123 }; |
124 | 124 |
125 TEST_F(V8SamplingProfilerTest, V8SamplingEventFired) { | 125 TEST_F(V8SamplingProfilerTest, V8SamplingEventFired) { |
126 sampling_profiler_->EnableSamplingEventForTesting(0, 0); | 126 sampling_profiler_->EnableSamplingEventForTesting(0, 0); |
127 TraceLog::GetInstance()->SetEnabled( | 127 TraceLog::GetInstance()->SetEnabled( |
(...skipping 13 matching lines...) Expand all Loading... |
141 } | 141 } |
142 | 142 |
143 TEST_F(V8SamplingProfilerTest, V8SamplingSamplesCollected) { | 143 TEST_F(V8SamplingProfilerTest, V8SamplingSamplesCollected) { |
144 CollectTrace(0, 1); | 144 CollectTrace(0, 1); |
145 int sample_events_count = CountEvents("V8Sample"); | 145 int sample_events_count = CountEvents("V8Sample"); |
146 CHECK_LT(0, sample_events_count); | 146 CHECK_LT(0, sample_events_count); |
147 base::RunLoop().RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
148 } | 148 } |
149 | 149 |
150 } // namespace content | 150 } // namespace content |
OLD | NEW |