Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / metrics / profiler / profiler_metrics_provider_unittest.cc
blob36fa25f7e2bb6b3349de4759447c3932dcca55bd
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/metrics/profiler/profiler_metrics_provider.h"
7 #include <stdint.h>
9 #include "base/bind.h"
10 #include "base/tracked_objects.h"
11 #include "components/metrics/metrics_hashes.h"
12 #include "content/public/common/process_type.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using tracked_objects::ProcessDataPhaseSnapshot;
16 using tracked_objects::TaskSnapshot;
18 namespace metrics {
20 TEST(ProfilerMetricsProviderTest, RecordData) {
21 // WARNING: If you broke the below check, you've modified how
22 // HashMetricName works. Please also modify all server-side code that
23 // relies on the existing way of hashing.
24 EXPECT_EQ(UINT64_C(1518842999910132863), HashMetricName("birth_thread*"));
26 ProfilerMetricsProvider profiler_metrics_provider;
29 // Add data from the browser process.
30 ProcessDataPhaseSnapshot process_data_phase;
31 process_data_phase.tasks.push_back(TaskSnapshot());
32 process_data_phase.tasks.back().birth.location.file_name = "a/b/file.h";
33 process_data_phase.tasks.back().birth.location.function_name = "function";
34 process_data_phase.tasks.back().birth.location.line_number = 1337;
35 process_data_phase.tasks.back().birth.thread_name = "birth_thread";
36 process_data_phase.tasks.back().death_data.count = 37;
37 process_data_phase.tasks.back().death_data.run_duration_sum = 31;
38 process_data_phase.tasks.back().death_data.run_duration_max = 17;
39 process_data_phase.tasks.back().death_data.run_duration_sample = 13;
40 process_data_phase.tasks.back().death_data.queue_duration_sum = 8;
41 process_data_phase.tasks.back().death_data.queue_duration_max = 5;
42 process_data_phase.tasks.back().death_data.queue_duration_sample = 3;
43 process_data_phase.tasks.back().death_thread_name = "Still_Alive";
44 process_data_phase.tasks.push_back(TaskSnapshot());
45 process_data_phase.tasks.back().birth.location.file_name = "c\\d\\file2";
46 process_data_phase.tasks.back().birth.location.function_name = "function2";
47 process_data_phase.tasks.back().birth.location.line_number = 1773;
48 process_data_phase.tasks.back().birth.thread_name = "birth_thread2";
49 process_data_phase.tasks.back().death_data.count = 19;
50 process_data_phase.tasks.back().death_data.run_duration_sum = 23;
51 process_data_phase.tasks.back().death_data.run_duration_max = 11;
52 process_data_phase.tasks.back().death_data.run_duration_sample = 7;
53 process_data_phase.tasks.back().death_data.queue_duration_sum = 0;
54 process_data_phase.tasks.back().death_data.queue_duration_max = 0;
55 process_data_phase.tasks.back().death_data.queue_duration_sample = 0;
56 process_data_phase.tasks.back().death_thread_name = "death_thread";
58 profiler_metrics_provider.RecordProfilerData(
59 process_data_phase, 177, content::PROCESS_TYPE_BROWSER, 0,
60 base::TimeDelta::FromMinutes(1), base::TimeDelta::FromMinutes(2),
61 ProfilerEvents());
65 // Add second phase from the browser process.
66 ProcessDataPhaseSnapshot process_data_phase;
67 process_data_phase.tasks.push_back(TaskSnapshot());
68 process_data_phase.tasks.back().birth.location.file_name = "a/b/file10.h";
69 process_data_phase.tasks.back().birth.location.function_name = "function10";
70 process_data_phase.tasks.back().birth.location.line_number = 101337;
71 process_data_phase.tasks.back().birth.thread_name = "birth_thread_ten";
72 process_data_phase.tasks.back().death_data.count = 1037;
73 process_data_phase.tasks.back().death_data.run_duration_sum = 1031;
74 process_data_phase.tasks.back().death_data.run_duration_max = 1017;
75 process_data_phase.tasks.back().death_data.run_duration_sample = 1013;
76 process_data_phase.tasks.back().death_data.queue_duration_sum = 108;
77 process_data_phase.tasks.back().death_data.queue_duration_max = 105;
78 process_data_phase.tasks.back().death_data.queue_duration_sample = 103;
79 process_data_phase.tasks.back().death_thread_name = "Already_Dead";
80 process_data_phase.tasks.push_back(TaskSnapshot());
81 process_data_phase.tasks.back().birth.location.file_name = "c\\d\\file210";
82 process_data_phase.tasks.back().birth.location.function_name =
83 "function210";
84 process_data_phase.tasks.back().birth.location.line_number = 101773;
85 process_data_phase.tasks.back().birth.thread_name = "birth_thread_ten2";
86 process_data_phase.tasks.back().death_data.count = 1019;
87 process_data_phase.tasks.back().death_data.run_duration_sum = 1023;
88 process_data_phase.tasks.back().death_data.run_duration_max = 1011;
89 process_data_phase.tasks.back().death_data.run_duration_sample = 107;
90 process_data_phase.tasks.back().death_data.queue_duration_sum = 100;
91 process_data_phase.tasks.back().death_data.queue_duration_max = 100;
92 process_data_phase.tasks.back().death_data.queue_duration_sample = 100;
93 process_data_phase.tasks.back().death_thread_name = "death_thread_ten";
95 profiler_metrics_provider.RecordProfilerData(
96 process_data_phase, 177, content::PROCESS_TYPE_BROWSER, 1,
97 base::TimeDelta::FromMinutes(10), base::TimeDelta::FromMinutes(20),
98 ProfilerEvents(1, ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT));
102 // Add data from a renderer process.
103 ProcessDataPhaseSnapshot process_data_phase;
104 process_data_phase.tasks.push_back(TaskSnapshot());
105 process_data_phase.tasks.back().birth.location.file_name = "file3";
106 process_data_phase.tasks.back().birth.location.function_name = "function3";
107 process_data_phase.tasks.back().birth.location.line_number = 7331;
108 process_data_phase.tasks.back().birth.thread_name = "birth_thread3";
109 process_data_phase.tasks.back().death_data.count = 137;
110 process_data_phase.tasks.back().death_data.run_duration_sum = 131;
111 process_data_phase.tasks.back().death_data.run_duration_max = 117;
112 process_data_phase.tasks.back().death_data.run_duration_sample = 113;
113 process_data_phase.tasks.back().death_data.queue_duration_sum = 108;
114 process_data_phase.tasks.back().death_data.queue_duration_max = 105;
115 process_data_phase.tasks.back().death_data.queue_duration_sample = 103;
116 process_data_phase.tasks.back().death_thread_name = "death_thread3";
117 process_data_phase.tasks.push_back(TaskSnapshot());
118 process_data_phase.tasks.back().birth.location.file_name = "";
119 process_data_phase.tasks.back().birth.location.function_name = "";
120 process_data_phase.tasks.back().birth.location.line_number = 7332;
121 process_data_phase.tasks.back().birth.thread_name = "";
122 process_data_phase.tasks.back().death_data.count = 138;
123 process_data_phase.tasks.back().death_data.run_duration_sum = 132;
124 process_data_phase.tasks.back().death_data.run_duration_max = 118;
125 process_data_phase.tasks.back().death_data.run_duration_sample = 114;
126 process_data_phase.tasks.back().death_data.queue_duration_sum = 109;
127 process_data_phase.tasks.back().death_data.queue_duration_max = 106;
128 process_data_phase.tasks.back().death_data.queue_duration_sample = 104;
129 process_data_phase.tasks.back().death_thread_name = "";
131 profiler_metrics_provider.RecordProfilerData(
132 process_data_phase, 1177, content::PROCESS_TYPE_RENDERER, 0,
133 base::TimeDelta::FromMinutes(1), base::TimeDelta::FromMinutes(2),
134 ProfilerEvents());
137 // Capture the data and verify that it is as expected.
138 ChromeUserMetricsExtension uma_proto;
139 profiler_metrics_provider.ProvideGeneralMetrics(&uma_proto);
141 // Phase 0
142 ASSERT_EQ(2, uma_proto.profiler_event_size());
144 EXPECT_EQ(ProfilerEventProto::VERSION_SPLIT_PROFILE,
145 uma_proto.profiler_event(0).profile_version());
146 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
147 uma_proto.profiler_event(0).time_source());
148 ASSERT_EQ(0, uma_proto.profiler_event(0).past_session_event_size());
149 ASSERT_EQ(60000, uma_proto.profiler_event(0).profiling_start_ms());
150 ASSERT_EQ(120000, uma_proto.profiler_event(0).profiling_finish_ms());
151 ASSERT_EQ(4, uma_proto.profiler_event(0).tracked_object_size());
153 const ProfilerEventProto::TrackedObject* tracked_object =
154 &uma_proto.profiler_event(0).tracked_object(0);
155 EXPECT_EQ(HashMetricName("file.h"), tracked_object->source_file_name_hash());
156 EXPECT_EQ(HashMetricName("function"),
157 tracked_object->source_function_name_hash());
158 EXPECT_EQ(1337, tracked_object->source_line_number());
159 EXPECT_EQ(HashMetricName("birth_thread"),
160 tracked_object->birth_thread_name_hash());
161 EXPECT_EQ(37, tracked_object->exec_count());
162 EXPECT_EQ(31, tracked_object->exec_time_total());
163 EXPECT_EQ(13, tracked_object->exec_time_sampled());
164 EXPECT_EQ(8, tracked_object->queue_time_total());
165 EXPECT_EQ(3, tracked_object->queue_time_sampled());
166 EXPECT_EQ(HashMetricName("Still_Alive"),
167 tracked_object->exec_thread_name_hash());
168 EXPECT_EQ(177U, tracked_object->process_id());
169 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
170 tracked_object->process_type());
172 tracked_object = &uma_proto.profiler_event(0).tracked_object(1);
173 EXPECT_EQ(HashMetricName("file2"), tracked_object->source_file_name_hash());
174 EXPECT_EQ(HashMetricName("function2"),
175 tracked_object->source_function_name_hash());
176 EXPECT_EQ(1773, tracked_object->source_line_number());
177 EXPECT_EQ(HashMetricName("birth_thread*"),
178 tracked_object->birth_thread_name_hash());
179 EXPECT_EQ(19, tracked_object->exec_count());
180 EXPECT_EQ(23, tracked_object->exec_time_total());
181 EXPECT_EQ(7, tracked_object->exec_time_sampled());
182 EXPECT_EQ(0, tracked_object->queue_time_total());
183 EXPECT_EQ(0, tracked_object->queue_time_sampled());
184 EXPECT_EQ(HashMetricName("death_thread"),
185 tracked_object->exec_thread_name_hash());
186 EXPECT_EQ(177U, tracked_object->process_id());
187 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
188 tracked_object->process_type());
190 tracked_object = &uma_proto.profiler_event(0).tracked_object(2);
191 EXPECT_EQ(HashMetricName("file3"), tracked_object->source_file_name_hash());
192 EXPECT_EQ(HashMetricName("function3"),
193 tracked_object->source_function_name_hash());
194 EXPECT_EQ(7331, tracked_object->source_line_number());
195 EXPECT_EQ(HashMetricName("birth_thread*"),
196 tracked_object->birth_thread_name_hash());
197 EXPECT_EQ(137, tracked_object->exec_count());
198 EXPECT_EQ(131, tracked_object->exec_time_total());
199 EXPECT_EQ(113, tracked_object->exec_time_sampled());
200 EXPECT_EQ(108, tracked_object->queue_time_total());
201 EXPECT_EQ(103, tracked_object->queue_time_sampled());
202 EXPECT_EQ(HashMetricName("death_thread*"),
203 tracked_object->exec_thread_name_hash());
204 EXPECT_EQ(1177U, tracked_object->process_id());
205 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER,
206 tracked_object->process_type());
208 tracked_object = &uma_proto.profiler_event(0).tracked_object(3);
209 EXPECT_EQ(HashMetricName(""), tracked_object->source_file_name_hash());
210 EXPECT_EQ(HashMetricName(""), tracked_object->source_function_name_hash());
211 EXPECT_EQ(7332, tracked_object->source_line_number());
212 EXPECT_EQ(HashMetricName(""), tracked_object->birth_thread_name_hash());
213 EXPECT_EQ(138, tracked_object->exec_count());
214 EXPECT_EQ(132, tracked_object->exec_time_total());
215 EXPECT_EQ(114, tracked_object->exec_time_sampled());
216 EXPECT_EQ(109, tracked_object->queue_time_total());
217 EXPECT_EQ(104, tracked_object->queue_time_sampled());
218 EXPECT_EQ(HashMetricName(""), tracked_object->exec_thread_name_hash());
219 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER,
220 tracked_object->process_type());
222 // Phase 1
223 EXPECT_EQ(ProfilerEventProto::VERSION_SPLIT_PROFILE,
224 uma_proto.profiler_event(1).profile_version());
225 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
226 uma_proto.profiler_event(1).time_source());
227 ASSERT_EQ(1, uma_proto.profiler_event(1).past_session_event_size());
228 ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT,
229 uma_proto.profiler_event(1).past_session_event(0));
230 ASSERT_EQ(600000, uma_proto.profiler_event(1).profiling_start_ms());
231 ASSERT_EQ(1200000, uma_proto.profiler_event(1).profiling_finish_ms());
232 ASSERT_EQ(2, uma_proto.profiler_event(1).tracked_object_size());
234 tracked_object = &uma_proto.profiler_event(1).tracked_object(0);
235 EXPECT_EQ(HashMetricName("file10.h"),
236 tracked_object->source_file_name_hash());
237 EXPECT_EQ(HashMetricName("function10"),
238 tracked_object->source_function_name_hash());
239 EXPECT_EQ(101337, tracked_object->source_line_number());
240 EXPECT_EQ(HashMetricName("birth_thread_ten"),
241 tracked_object->birth_thread_name_hash());
242 EXPECT_EQ(1037, tracked_object->exec_count());
243 EXPECT_EQ(1031, tracked_object->exec_time_total());
244 EXPECT_EQ(1013, tracked_object->exec_time_sampled());
245 EXPECT_EQ(108, tracked_object->queue_time_total());
246 EXPECT_EQ(103, tracked_object->queue_time_sampled());
247 EXPECT_EQ(HashMetricName("Already_Dead"),
248 tracked_object->exec_thread_name_hash());
249 EXPECT_EQ(177U, tracked_object->process_id());
250 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
251 tracked_object->process_type());
253 tracked_object = &uma_proto.profiler_event(1).tracked_object(1);
254 EXPECT_EQ(HashMetricName("file210"), tracked_object->source_file_name_hash());
255 EXPECT_EQ(HashMetricName("function210"),
256 tracked_object->source_function_name_hash());
257 EXPECT_EQ(101773, tracked_object->source_line_number());
258 EXPECT_EQ(HashMetricName("birth_thread_ten*"),
259 tracked_object->birth_thread_name_hash());
260 EXPECT_EQ(1019, tracked_object->exec_count());
261 EXPECT_EQ(1023, tracked_object->exec_time_total());
262 EXPECT_EQ(107, tracked_object->exec_time_sampled());
263 EXPECT_EQ(100, tracked_object->queue_time_total());
264 EXPECT_EQ(100, tracked_object->queue_time_sampled());
265 EXPECT_EQ(HashMetricName("death_thread_ten"),
266 tracked_object->exec_thread_name_hash());
267 EXPECT_EQ(177U, tracked_object->process_id());
268 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
269 tracked_object->process_type());
272 } // namespace metrics