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

Side by Side Diff: components/metrics/call_stack_profile_metrics_provider_unittest.cc

Issue 1325653003: Type change in StackSamplingProfiler from void* to uintptr_t. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@UMA2_refactor
Patch Set: Moved IPC structures into content/common and merged with dependent CL. Created 5 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/metrics/call_stack_profile_metrics_provider.h" 5 #include "components/metrics/call_stack_profile_metrics_provider.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/profiler/stack_sampling_profiler.h" 8 #include "base/profiler/stack_sampling_profiler.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProviderTest); 56 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProviderTest);
57 }; 57 };
58 58
59 // Checks that all properties from multiple profiles are filled as expected. 59 // Checks that all properties from multiple profiles are filled as expected.
60 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { 60 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) {
61 const uintptr_t module1_base_address = 0x1000; 61 const uintptr_t module1_base_address = 0x1000;
62 const uintptr_t module2_base_address = 0x2000; 62 const uintptr_t module2_base_address = 0x2000;
63 const uintptr_t module3_base_address = 0x3000; 63 const uintptr_t module3_base_address = 0x3000;
64 64
65 const Module profile_modules[][2] = { 65 const Module profile_modules[][2] = {
66 { 66 {
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting (see "git cl format" comm
sydli 2015/09/03 17:18:13 Gotcha. Unreformatted.
67 Module( 67 Module(module1_base_address, "ABCD",
68 reinterpret_cast<const void*>(module1_base_address),
69 "ABCD",
70 #if defined(OS_WIN) 68 #if defined(OS_WIN)
71 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 69 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
72 #else 70 #else
73 base::FilePath("/some/path/to/chrome") 71 base::FilePath("/some/path/to/chrome")
74 #endif 72 #endif
75 ), 73 ),
76 Module( 74 Module(module2_base_address, "EFGH",
77 reinterpret_cast<const void*>(module2_base_address),
78 "EFGH",
79 #if defined(OS_WIN) 75 #if defined(OS_WIN)
80 base::FilePath(L"c:\\some\\path\\to\\third_party.dll") 76 base::FilePath(L"c:\\some\\path\\to\\third_party.dll")
81 #else 77 #else
82 base::FilePath("/some/path/to/third_party.so") 78 base::FilePath("/some/path/to/third_party.so")
83 #endif 79 #endif
84 ), 80 ),
85 }, 81 },
86 { 82 {Module(module3_base_address, "MNOP",
87 Module(
88 reinterpret_cast<const void*>(module3_base_address),
89 "MNOP",
90 #if defined(OS_WIN) 83 #if defined(OS_WIN)
91 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll") 84 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll")
92 #else 85 #else
93 base::FilePath("/some/path/to/third_party2.so") 86 base::FilePath("/some/path/to/third_party2.so")
94 #endif 87 #endif
95 ), 88 ),
96 Module( // Repeated from the first profile. 89 Module( // Repeated from the first profile.
97 reinterpret_cast<const void*>(module1_base_address), 90 module1_base_address, "ABCD",
98 "ABCD",
99 #if defined(OS_WIN) 91 #if defined(OS_WIN)
100 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 92 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
101 #else 93 #else
102 base::FilePath("/some/path/to/chrome") 94 base::FilePath("/some/path/to/chrome")
103 #endif 95 #endif
104 ) 96 )}};
105 }
106 };
107 97
108 // Values for Windows generated with: 98 // Values for Windows generated with:
109 // perl -MDigest::MD5=md5 -MEncode=encode 99 // perl -MDigest::MD5=md5 -MEncode=encode
110 // -e 'for(@ARGV){printf "%x\n", unpack "Q>", md5 encode "UTF-16LE", $_}' 100 // -e 'for(@ARGV){printf "%x\n", unpack "Q>", md5 encode "UTF-16LE", $_}'
111 // chrome.exe third_party.dll third_party2.dll 101 // chrome.exe third_party.dll third_party2.dll
112 // 102 //
113 // Values for Linux generated with: 103 // Values for Linux generated with:
114 // perl -MDigest::MD5=md5 104 // perl -MDigest::MD5=md5
115 // -e 'for(@ARGV){printf "%x\n", unpack "Q>", md5 $_}' 105 // -e 'for(@ARGV){printf "%x\n", unpack "Q>", md5 $_}'
116 // chrome third_party.so third_party2.so 106 // chrome third_party.so third_party2.so
(...skipping 21 matching lines...) Expand all
138 // Represents two stack samples for each of two profiles, where each stack 128 // Represents two stack samples for each of two profiles, where each stack
139 // contains three frames. Each frame contains an instruction pointer and a 129 // contains three frames. Each frame contains an instruction pointer and a
140 // module index corresponding to the module for the profile in 130 // module index corresponding to the module for the profile in
141 // profile_modules. 131 // profile_modules.
142 // 132 //
143 // So, the first stack sample below has its top frame in module 0 at an offset 133 // So, the first stack sample below has its top frame in module 0 at an offset
144 // of 0x10 from the module's base address, the next-to-top frame in module 1 134 // of 0x10 from the module's base address, the next-to-top frame in module 1
145 // at an offset of 0x20 from the module's base address, and the bottom frame 135 // at an offset of 0x20 from the module's base address, and the bottom frame
146 // in module 0 at an offset of 0x30 from the module's base address 136 // in module 0 at an offset of 0x30 from the module's base address
147 const Frame profile_sample_frames[][2][3] = { 137 const Frame profile_sample_frames[][2][3] = {
148 { 138 {{Frame(module1_base_address + 0x10, 0),
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting.
149 { 139 Frame(module2_base_address + 0x20, 1),
150 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 0), 140 Frame(module1_base_address + 0x30, 0)},
151 Frame(reinterpret_cast<const void*>(module2_base_address + 0x20), 1), 141 {Frame(module2_base_address + 0x10, 1),
152 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 0) 142 Frame(module1_base_address + 0x20, 0),
153 }, 143 Frame(module2_base_address + 0x30, 1)}},
154 { 144 {{Frame(module3_base_address + 0x10, 0),
155 Frame(reinterpret_cast<const void*>(module2_base_address + 0x10), 1), 145 Frame(module1_base_address + 0x20, 1),
156 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 0), 146 Frame(module3_base_address + 0x30, 0)},
157 Frame(reinterpret_cast<const void*>(module2_base_address + 0x30), 1) 147 {Frame(module1_base_address + 0x10, 1),
158 } 148 Frame(module3_base_address + 0x20, 0),
159 }, 149 Frame(module1_base_address + 0x30, 1)}}};
160 {
161 {
162 Frame(reinterpret_cast<const void*>(module3_base_address + 0x10), 0),
163 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 1),
164 Frame(reinterpret_cast<const void*>(module3_base_address + 0x30), 0)
165 },
166 {
167 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 1),
168 Frame(reinterpret_cast<const void*>(module3_base_address + 0x20), 0),
169 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 1)
170 }
171 }
172 };
173 150
174 base::TimeDelta profile_durations[2] = { 151 base::TimeDelta profile_durations[2] = {
175 base::TimeDelta::FromMilliseconds(100), 152 base::TimeDelta::FromMilliseconds(100),
176 base::TimeDelta::FromMilliseconds(200) 153 base::TimeDelta::FromMilliseconds(200)
177 }; 154 };
178 155
179 base::TimeDelta profile_sampling_periods[2] = { 156 base::TimeDelta profile_sampling_periods[2] = {
180 base::TimeDelta::FromMilliseconds(10), 157 base::TimeDelta::FromMilliseconds(10),
181 base::TimeDelta::FromMilliseconds(20) 158 base::TimeDelta::FromMilliseconds(20)
182 }; 159 };
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_EQ(SampledProfile::PROCESS_STARTUP, sampled_profile.trigger_event()); 246 EXPECT_EQ(SampledProfile::PROCESS_STARTUP, sampled_profile.trigger_event());
270 } 247 }
271 } 248 }
272 249
273 // Checks that all duplicate samples are collapsed with 250 // Checks that all duplicate samples are collapsed with
274 // preserve_sample_ordering = false. 251 // preserve_sample_ordering = false.
275 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { 252 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) {
276 const uintptr_t module_base_address = 0x1000; 253 const uintptr_t module_base_address = 0x1000;
277 254
278 const Module modules[] = { 255 const Module modules[] = {
279 Module( 256 Module(module_base_address, "ABCD",
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting.
280 reinterpret_cast<const void*>(module_base_address),
281 "ABCD",
282 #if defined(OS_WIN) 257 #if defined(OS_WIN)
283 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 258 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
284 #else 259 #else
285 base::FilePath("/some/path/to/chrome") 260 base::FilePath("/some/path/to/chrome")
286 #endif 261 #endif
287 ) 262 )
288 }; 263 };
289 264
290 // Duplicate samples in slots 0, 2, and 3. 265 // Duplicate samples in slots 0, 2, and 3.
291 const Frame sample_frames[][1] = { 266 const Frame sample_frames[][1] = {{
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting.
292 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 267 Frame(module_base_address + 0x10, 0),
293 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, 268 },
294 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 269 {
295 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } 270 Frame(module_base_address + 0x20, 0),
296 }; 271 },
272 {
273 Frame(module_base_address + 0x10, 0),
274 },
275 {Frame(module_base_address + 0x10, 0)}};
297 276
298 Profile profile; 277 Profile profile;
299 profile.modules.insert(profile.modules.end(), &modules[0], 278 profile.modules.insert(profile.modules.end(), &modules[0],
300 &modules[0] + arraysize(modules)); 279 &modules[0] + arraysize(modules));
301 280
302 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 281 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
303 profile.samples.push_back(Sample()); 282 profile.samples.push_back(Sample());
304 Sample& sample = profile.samples.back(); 283 Sample& sample = profile.samples.back();
305 sample.insert(sample.end(), &sample_frames[i][0], 284 sample.insert(sample.end(), &sample_frames[i][0],
306 &sample_frames[i][0] + arraysize(sample_frames[i])); 285 &sample_frames[i][0] + arraysize(sample_frames[i]));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 327 }
349 } 328 }
350 } 329 }
351 330
352 // Checks that only contiguous duplicate samples are collapsed with 331 // Checks that only contiguous duplicate samples are collapsed with
353 // preserve_sample_ordering = true. 332 // preserve_sample_ordering = true.
354 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { 333 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) {
355 const uintptr_t module_base_address = 0x1000; 334 const uintptr_t module_base_address = 0x1000;
356 335
357 const Module modules[] = { 336 const Module modules[] = {
358 Module( 337 Module(module_base_address, "ABCD",
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting.
359 reinterpret_cast<const void*>(module_base_address),
360 "ABCD",
361 #if defined(OS_WIN) 338 #if defined(OS_WIN)
362 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 339 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
363 #else 340 #else
364 base::FilePath("/some/path/to/chrome") 341 base::FilePath("/some/path/to/chrome")
365 #endif 342 #endif
366 ) 343 )
367 }; 344 };
368 345
369 // Duplicate samples in slots 0, 2, and 3. 346 // Duplicate samples in slots 0, 2, and 3.
370 const Frame sample_frames[][1] = { 347 const Frame sample_frames[][1] = {{
Mike Wittman 2015/09/03 16:58:04 Please undo reformatting.
371 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 348 Frame(module_base_address + 0x10, 0),
372 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, 349 },
373 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 350 {
374 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } 351 Frame(module_base_address + 0x20, 0),
375 }; 352 },
353 {
354 Frame(module_base_address + 0x10, 0),
355 },
356 {Frame(module_base_address + 0x10, 0)}};
376 357
377 Profile profile; 358 Profile profile;
378 profile.modules.insert(profile.modules.end(), &modules[0], 359 profile.modules.insert(profile.modules.end(), &modules[0],
379 &modules[0] + arraysize(modules)); 360 &modules[0] + arraysize(modules));
380 361
381 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 362 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
382 profile.samples.push_back(Sample()); 363 profile.samples.push_back(Sample());
383 Sample& sample = profile.samples.back(); 364 Sample& sample = profile.samples.back();
384 sample.insert(sample.end(), &sample_frames[i][0], 365 sample.insert(sample.end(), &sample_frames[i][0],
385 &sample_frames[i][0] + arraysize(sample_frames[i])); 366 &sample_frames[i][0] + arraysize(sample_frames[i]));
386 } 367 }
387 368
388 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 369 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
389 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 370 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
390 371
391 CallStackProfileMetricsProvider provider; 372 CallStackProfileMetricsProvider provider;
392 provider.OnRecordingEnabled(); 373 provider.OnRecordingEnabled();
393 AppendProfiles( 374 AppendProfiles(Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true),
394 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), 375 std::vector<Profile>(1, profile));
395 std::vector<Profile>(1, profile));
396 ChromeUserMetricsExtension uma_proto; 376 ChromeUserMetricsExtension uma_proto;
397 provider.ProvideGeneralMetrics(&uma_proto); 377 provider.ProvideGeneralMetrics(&uma_proto);
398 378
399 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 379 ASSERT_EQ(1, uma_proto.sampled_profile().size());
400 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 380 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
401 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 381 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
402 const CallStackProfile& call_stack_profile = 382 const CallStackProfile& call_stack_profile =
403 sampled_profile.call_stack_profile(); 383 sampled_profile.call_stack_profile();
404 384
405 ASSERT_EQ(3, call_stack_profile.sample().size()); 385 ASSERT_EQ(3, call_stack_profile.sample().size());
(...skipping 17 matching lines...) Expand all
423 entry.address()); 403 entry.address());
424 ASSERT_TRUE(entry.has_module_id_index()); 404 ASSERT_TRUE(entry.has_module_id_index());
425 EXPECT_EQ(sample_frames[i][j].module_index, 405 EXPECT_EQ(sample_frames[i][j].module_index,
426 static_cast<size_t>(entry.module_id_index())); 406 static_cast<size_t>(entry.module_id_index()));
427 } 407 }
428 } 408 }
429 } 409 }
430 410
431 // Checks that unknown modules produce an empty Entry. 411 // Checks that unknown modules produce an empty Entry.
432 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { 412 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) {
433 const Frame frame(reinterpret_cast<const void*>(0x1000), 413 const Frame frame(0x1000, Frame::kUnknownModuleIndex);
434 Frame::kUnknownModuleIndex);
435 414
436 Profile profile; 415 Profile profile;
437 416
438 profile.samples.push_back(Sample(1, frame)); 417 profile.samples.push_back(Sample(1, frame));
439 418
440 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 419 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
441 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 420 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
442 421
443 CallStackProfileMetricsProvider provider; 422 CallStackProfileMetricsProvider provider;
444 provider.OnRecordingEnabled(); 423 provider.OnRecordingEnabled();
(...skipping 19 matching lines...) Expand all
464 EXPECT_FALSE(entry.has_address()); 443 EXPECT_FALSE(entry.has_address());
465 EXPECT_FALSE(entry.has_module_id_index()); 444 EXPECT_FALSE(entry.has_module_id_index());
466 } 445 }
467 446
468 // Checks that pending profiles are only passed back to ProvideGeneralMetrics 447 // Checks that pending profiles are only passed back to ProvideGeneralMetrics
469 // once. 448 // once.
470 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { 449 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) {
471 CallStackProfileMetricsProvider provider; 450 CallStackProfileMetricsProvider provider;
472 for (int i = 0; i < 2; ++i) { 451 for (int i = 0; i < 2; ++i) {
473 Profile profile; 452 Profile profile;
474 profile.samples.push_back(Sample(1, Frame( 453 profile.samples.push_back(
475 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 454 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
476 455
477 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 456 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
478 // Use the sampling period to distinguish the two profiles. 457 // Use the sampling period to distinguish the two profiles.
479 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); 458 profile.sampling_period = base::TimeDelta::FromMilliseconds(i);
480 459
481 provider.OnRecordingEnabled(); 460 provider.OnRecordingEnabled();
482 AppendProfiles( 461 AppendProfiles(
483 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), 462 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false),
484 std::vector<Profile>(1, profile)); 463 std::vector<Profile>(1, profile));
485 ChromeUserMetricsExtension uma_proto; 464 ChromeUserMetricsExtension uma_proto;
486 provider.ProvideGeneralMetrics(&uma_proto); 465 provider.ProvideGeneralMetrics(&uma_proto);
487 466
488 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 467 ASSERT_EQ(1, uma_proto.sampled_profile().size());
489 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 468 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
490 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 469 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
491 const CallStackProfile& call_stack_profile = 470 const CallStackProfile& call_stack_profile =
492 sampled_profile.call_stack_profile(); 471 sampled_profile.call_stack_profile();
493 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); 472 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms());
494 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); 473 EXPECT_EQ(i, call_stack_profile.sampling_period_ms());
495 } 474 }
496 } 475 }
497 476
498 // Checks that pending profiles are provided to ProvideGeneralMetrics 477 // Checks that pending profiles are provided to ProvideGeneralMetrics
499 // when collected before CallStackProfileMetricsProvider is instantiated. 478 // when collected before CallStackProfileMetricsProvider is instantiated.
500 TEST_F(CallStackProfileMetricsProviderTest, 479 TEST_F(CallStackProfileMetricsProviderTest,
501 ProfilesProvidedWhenCollectedBeforeInstantiation) { 480 ProfilesProvidedWhenCollectedBeforeInstantiation) {
502 Profile profile; 481 Profile profile;
503 profile.samples.push_back(Sample(1, Frame( 482 profile.samples.push_back(
504 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 483 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
505 484
506 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 485 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
507 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 486 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
508 487
509 AppendProfiles( 488 AppendProfiles(
510 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), 489 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false),
511 std::vector<Profile>(1, profile)); 490 std::vector<Profile>(1, profile));
512 491
513 CallStackProfileMetricsProvider provider; 492 CallStackProfileMetricsProvider provider;
514 provider.OnRecordingEnabled(); 493 provider.OnRecordingEnabled();
515 ChromeUserMetricsExtension uma_proto; 494 ChromeUserMetricsExtension uma_proto;
516 provider.ProvideGeneralMetrics(&uma_proto); 495 provider.ProvideGeneralMetrics(&uma_proto);
517 496
518 EXPECT_EQ(1, uma_proto.sampled_profile_size()); 497 EXPECT_EQ(1, uma_proto.sampled_profile_size());
519 } 498 }
520 499
521 // Checks that pending profiles are not provided to ProvideGeneralMetrics 500 // Checks that pending profiles are not provided to ProvideGeneralMetrics
522 // while recording is disabled. 501 // while recording is disabled.
523 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { 502 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) {
524 Profile profile; 503 Profile profile;
525 profile.samples.push_back(Sample(1, Frame( 504 profile.samples.push_back(
526 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 505 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
527 506
528 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 507 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
529 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 508 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
530 509
531 CallStackProfileMetricsProvider provider; 510 CallStackProfileMetricsProvider provider;
532 provider.OnRecordingDisabled(); 511 provider.OnRecordingDisabled();
533 AppendProfiles( 512 AppendProfiles(
534 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), 513 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false),
535 std::vector<Profile>(1, profile)); 514 std::vector<Profile>(1, profile));
536 ChromeUserMetricsExtension uma_proto; 515 ChromeUserMetricsExtension uma_proto;
537 provider.ProvideGeneralMetrics(&uma_proto); 516 provider.ProvideGeneralMetrics(&uma_proto);
538 517
539 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 518 EXPECT_EQ(0, uma_proto.sampled_profile_size());
540 } 519 }
541 520
542 // Checks that pending profiles are not provided to ProvideGeneralMetrics 521 // Checks that pending profiles are not provided to ProvideGeneralMetrics
543 // if recording is disabled while profiling. 522 // if recording is disabled while profiling.
544 TEST_F(CallStackProfileMetricsProviderTest, 523 TEST_F(CallStackProfileMetricsProviderTest,
545 ProfilesNotProvidedAfterChangeToDisabled) { 524 ProfilesNotProvidedAfterChangeToDisabled) {
546 Profile profile; 525 Profile profile;
547 profile.samples.push_back(Sample(1, Frame( 526 profile.samples.push_back(
548 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 527 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
549 528
550 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 529 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
551 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 530 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
552 531
553 CallStackProfileMetricsProvider provider; 532 CallStackProfileMetricsProvider provider;
554 provider.OnRecordingEnabled(); 533 provider.OnRecordingEnabled();
555 base::StackSamplingProfiler::CompletedCallback callback = 534 base::StackSamplingProfiler::CompletedCallback callback =
556 CallStackProfileMetricsProvider::GetProfilerCallback( 535 CallStackProfileMetricsProvider::GetProfilerCallback(
557 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); 536 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false));
558 537
559 provider.OnRecordingDisabled(); 538 provider.OnRecordingDisabled();
560 callback.Run(std::vector<Profile>(1, profile)); 539 callback.Run(std::vector<Profile>(1, profile));
561 ChromeUserMetricsExtension uma_proto; 540 ChromeUserMetricsExtension uma_proto;
562 provider.ProvideGeneralMetrics(&uma_proto); 541 provider.ProvideGeneralMetrics(&uma_proto);
563 542
564 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 543 EXPECT_EQ(0, uma_proto.sampled_profile_size());
565 } 544 }
566 545
567 // Checks that pending profiles are not provided to ProvideGeneralMetrics if 546 // Checks that pending profiles are not provided to ProvideGeneralMetrics if
568 // recording is enabled, but then disabled and reenabled while profiling. 547 // recording is enabled, but then disabled and reenabled while profiling.
569 TEST_F(CallStackProfileMetricsProviderTest, 548 TEST_F(CallStackProfileMetricsProviderTest,
570 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { 549 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) {
571 Profile profile; 550 Profile profile;
572 profile.samples.push_back(Sample(1, Frame( 551 profile.samples.push_back(
573 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 552 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
574 553
575 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 554 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
576 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 555 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
577 556
578 CallStackProfileMetricsProvider provider; 557 CallStackProfileMetricsProvider provider;
579 provider.OnRecordingEnabled(); 558 provider.OnRecordingEnabled();
580 base::StackSamplingProfiler::CompletedCallback callback = 559 base::StackSamplingProfiler::CompletedCallback callback =
581 CallStackProfileMetricsProvider::GetProfilerCallback( 560 CallStackProfileMetricsProvider::GetProfilerCallback(
582 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); 561 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false));
583 562
584 provider.OnRecordingDisabled(); 563 provider.OnRecordingDisabled();
585 provider.OnRecordingEnabled(); 564 provider.OnRecordingEnabled();
586 callback.Run(std::vector<Profile>(1, profile)); 565 callback.Run(std::vector<Profile>(1, profile));
587 ChromeUserMetricsExtension uma_proto; 566 ChromeUserMetricsExtension uma_proto;
588 provider.ProvideGeneralMetrics(&uma_proto); 567 provider.ProvideGeneralMetrics(&uma_proto);
589 568
590 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 569 EXPECT_EQ(0, uma_proto.sampled_profile_size());
591 } 570 }
592 571
593 // Checks that pending profiles are not provided to ProvideGeneralMetrics 572 // Checks that pending profiles are not provided to ProvideGeneralMetrics
594 // if recording is disabled, but then enabled while profiling. 573 // if recording is disabled, but then enabled while profiling.
595 TEST_F(CallStackProfileMetricsProviderTest, 574 TEST_F(CallStackProfileMetricsProviderTest,
596 ProfilesNotProvidedAfterChangeFromDisabled) { 575 ProfilesNotProvidedAfterChangeFromDisabled) {
597 Profile profile; 576 Profile profile;
598 profile.samples.push_back(Sample(1, Frame( 577 profile.samples.push_back(
599 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 578 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
600 579
601 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 580 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
602 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 581 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
603 582
604 CallStackProfileMetricsProvider provider; 583 CallStackProfileMetricsProvider provider;
605 provider.OnRecordingDisabled(); 584 provider.OnRecordingDisabled();
606 base::StackSamplingProfiler::CompletedCallback callback = 585 base::StackSamplingProfiler::CompletedCallback callback =
607 CallStackProfileMetricsProvider::GetProfilerCallback( 586 CallStackProfileMetricsProvider::GetProfilerCallback(
608 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); 587 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false));
609 588
610 provider.OnRecordingEnabled(); 589 provider.OnRecordingEnabled();
611 callback.Run(std::vector<Profile>(1, profile)); 590 callback.Run(std::vector<Profile>(1, profile));
612 ChromeUserMetricsExtension uma_proto; 591 ChromeUserMetricsExtension uma_proto;
613 provider.ProvideGeneralMetrics(&uma_proto); 592 provider.ProvideGeneralMetrics(&uma_proto);
614 593
615 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 594 EXPECT_EQ(0, uma_proto.sampled_profile_size());
616 } 595 }
617 596
618 } // namespace metrics 597 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698