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

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: Accidentally removed const qualifiers from unittest. 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/call_stack_profile_params.h" 7 #include "base/metrics/call_stack_profile_params.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/profiler/stack_sampling_profiler.h" 9 #include "base/profiler/stack_sampling_profiler.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // Checks that all properties from multiple profiles are filled as expected. 60 // Checks that all properties from multiple profiles are filled as expected.
61 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { 61 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) {
62 const uintptr_t module1_base_address = 0x1000; 62 const uintptr_t module1_base_address = 0x1000;
63 const uintptr_t module2_base_address = 0x2000; 63 const uintptr_t module2_base_address = 0x2000;
64 const uintptr_t module3_base_address = 0x3000; 64 const uintptr_t module3_base_address = 0x3000;
65 65
66 const Module profile_modules[][2] = { 66 const Module profile_modules[][2] = {
67 { 67 {
68 Module( 68 Module(
69 reinterpret_cast<const void*>(module1_base_address), 69 module1_base_address,
70 "ABCD", 70 "ABCD",
71 #if defined(OS_WIN) 71 #if defined(OS_WIN)
72 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 72 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
73 #else 73 #else
74 base::FilePath("/some/path/to/chrome") 74 base::FilePath("/some/path/to/chrome")
75 #endif 75 #endif
76 ), 76 ),
77 Module( 77 Module(
78 reinterpret_cast<const void*>(module2_base_address), 78 module2_base_address,
79 "EFGH", 79 "EFGH",
80 #if defined(OS_WIN) 80 #if defined(OS_WIN)
81 base::FilePath(L"c:\\some\\path\\to\\third_party.dll") 81 base::FilePath(L"c:\\some\\path\\to\\third_party.dll")
82 #else 82 #else
83 base::FilePath("/some/path/to/third_party.so") 83 base::FilePath("/some/path/to/third_party.so")
84 #endif 84 #endif
85 ), 85 ),
86 }, 86 },
87 { 87 {
88 Module( 88 Module(
89 reinterpret_cast<const void*>(module3_base_address), 89 module3_base_address,
90 "MNOP", 90 "MNOP",
91 #if defined(OS_WIN) 91 #if defined(OS_WIN)
92 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll") 92 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll")
93 #else 93 #else
94 base::FilePath("/some/path/to/third_party2.so") 94 base::FilePath("/some/path/to/third_party2.so")
95 #endif 95 #endif
96 ), 96 ),
97 Module( // Repeated from the first profile. 97 Module( // Repeated from the first profile.
98 reinterpret_cast<const void*>(module1_base_address), 98 module1_base_address,
99 "ABCD", 99 "ABCD",
100 #if defined(OS_WIN) 100 #if defined(OS_WIN)
101 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 101 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
102 #else 102 #else
103 base::FilePath("/some/path/to/chrome") 103 base::FilePath("/some/path/to/chrome")
104 #endif 104 #endif
105 ) 105 )
106 } 106 }
107 }; 107 };
108 108
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // module index corresponding to the module for the profile in 141 // module index corresponding to the module for the profile in
142 // profile_modules. 142 // profile_modules.
143 // 143 //
144 // So, the first stack sample below has its top frame in module 0 at an offset 144 // So, the first stack sample below has its top frame in module 0 at an offset
145 // of 0x10 from the module's base address, the next-to-top frame in module 1 145 // of 0x10 from the module's base address, the next-to-top frame in module 1
146 // at an offset of 0x20 from the module's base address, and the bottom frame 146 // at an offset of 0x20 from the module's base address, and the bottom frame
147 // in module 0 at an offset of 0x30 from the module's base address 147 // in module 0 at an offset of 0x30 from the module's base address
148 const Frame profile_sample_frames[][2][3] = { 148 const Frame profile_sample_frames[][2][3] = {
149 { 149 {
150 { 150 {
151 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 0), 151 Frame(module1_base_address + 0x10, 0),
152 Frame(reinterpret_cast<const void*>(module2_base_address + 0x20), 1), 152 Frame(module2_base_address + 0x20, 1),
153 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 0) 153 Frame(module1_base_address + 0x30, 0)
154 }, 154 },
155 { 155 {
156 Frame(reinterpret_cast<const void*>(module2_base_address + 0x10), 1), 156 Frame(module2_base_address + 0x10, 1),
157 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 0), 157 Frame(module1_base_address + 0x20, 0),
158 Frame(reinterpret_cast<const void*>(module2_base_address + 0x30), 1) 158 Frame(module2_base_address + 0x30, 1)
159 } 159 }
160 }, 160 },
161 { 161 {
162 { 162 {
163 Frame(reinterpret_cast<const void*>(module3_base_address + 0x10), 0), 163 Frame(module3_base_address + 0x10, 0),
164 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 1), 164 Frame(module1_base_address + 0x20, 1),
165 Frame(reinterpret_cast<const void*>(module3_base_address + 0x30), 0) 165 Frame(module3_base_address + 0x30, 0)
166 }, 166 },
167 { 167 {
168 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 1), 168 Frame(module1_base_address + 0x10, 1),
169 Frame(reinterpret_cast<const void*>(module3_base_address + 0x20), 0), 169 Frame(module3_base_address + 0x20, 0),
170 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 1) 170 Frame(module1_base_address + 0x30, 1)
171 } 171 }
172 } 172 }
173 }; 173 };
174 174
175 base::TimeDelta profile_durations[2] = { 175 base::TimeDelta profile_durations[2] = {
176 base::TimeDelta::FromMilliseconds(100), 176 base::TimeDelta::FromMilliseconds(100),
177 base::TimeDelta::FromMilliseconds(200) 177 base::TimeDelta::FromMilliseconds(200)
178 }; 178 };
179 179
180 base::TimeDelta profile_sampling_periods[2] = { 180 base::TimeDelta profile_sampling_periods[2] = {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 } 270 }
271 271
272 // Checks that all duplicate samples are collapsed with 272 // Checks that all duplicate samples are collapsed with
273 // preserve_sample_ordering = false. 273 // preserve_sample_ordering = false.
274 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { 274 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) {
275 const uintptr_t module_base_address = 0x1000; 275 const uintptr_t module_base_address = 0x1000;
276 276
277 const Module modules[] = { 277 const Module modules[] = {
278 Module( 278 Module(
279 reinterpret_cast<const void*>(module_base_address), 279 module_base_address,
280 "ABCD", 280 "ABCD",
281 #if defined(OS_WIN) 281 #if defined(OS_WIN)
282 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 282 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
283 #else 283 #else
284 base::FilePath("/some/path/to/chrome") 284 base::FilePath("/some/path/to/chrome")
285 #endif 285 #endif
286 ) 286 )
287 }; 287 };
288 288
289 // Duplicate samples in slots 0, 2, and 3. 289 // Duplicate samples in slots 0, 2, and 3.
290 const Frame sample_frames[][1] = { 290 const Frame sample_frames[][1] = {
291 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 291 { Frame(module_base_address + 0x10, 0), },
292 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, 292 { Frame(module_base_address + 0x20, 0), },
293 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 293 { Frame(module_base_address + 0x10, 0), },
294 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } 294 { Frame(module_base_address + 0x10, 0) }
295 }; 295 };
296 296
297 Profile profile; 297 Profile profile;
298 profile.modules.insert(profile.modules.end(), &modules[0], 298 profile.modules.insert(profile.modules.end(), &modules[0],
299 &modules[0] + arraysize(modules)); 299 &modules[0] + arraysize(modules));
300 300
301 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 301 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
302 profile.samples.push_back(Sample()); 302 profile.samples.push_back(Sample());
303 Sample& sample = profile.samples.back(); 303 Sample& sample = profile.samples.back();
304 sample.insert(sample.end(), &sample_frames[i][0], 304 sample.insert(sample.end(), &sample_frames[i][0],
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 347 }
348 } 348 }
349 349
350 // Checks that only contiguous duplicate samples are collapsed with 350 // Checks that only contiguous duplicate samples are collapsed with
351 // preserve_sample_ordering = true. 351 // preserve_sample_ordering = true.
352 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { 352 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) {
353 const uintptr_t module_base_address = 0x1000; 353 const uintptr_t module_base_address = 0x1000;
354 354
355 const Module modules[] = { 355 const Module modules[] = {
356 Module( 356 Module(
357 reinterpret_cast<const void*>(module_base_address), 357 module_base_address,
358 "ABCD", 358 "ABCD",
359 #if defined(OS_WIN) 359 #if defined(OS_WIN)
360 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 360 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
361 #else 361 #else
362 base::FilePath("/some/path/to/chrome") 362 base::FilePath("/some/path/to/chrome")
363 #endif 363 #endif
364 ) 364 )
365 }; 365 };
366 366
367 // Duplicate samples in slots 0, 2, and 3. 367 // Duplicate samples in slots 0, 2, and 3.
368 const Frame sample_frames[][1] = { 368 const Frame sample_frames[][1] = {
369 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 369 { Frame(module_base_address + 0x10, 0), },
370 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, 370 { Frame(module_base_address + 0x20, 0), },
371 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, 371 { Frame(module_base_address + 0x10, 0), },
372 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } 372 { Frame(module_base_address + 0x10, 0) }
373 }; 373 };
374 374
375 Profile profile; 375 Profile profile;
376 profile.modules.insert(profile.modules.end(), &modules[0], 376 profile.modules.insert(profile.modules.end(), &modules[0],
377 &modules[0] + arraysize(modules)); 377 &modules[0] + arraysize(modules));
378 378
379 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 379 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
380 profile.samples.push_back(Sample()); 380 profile.samples.push_back(Sample());
381 Sample& sample = profile.samples.back(); 381 Sample& sample = profile.samples.back();
382 sample.insert(sample.end(), &sample_frames[i][0], 382 sample.insert(sample.end(), &sample_frames[i][0],
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 entry.address()); 420 entry.address());
421 ASSERT_TRUE(entry.has_module_id_index()); 421 ASSERT_TRUE(entry.has_module_id_index());
422 EXPECT_EQ(sample_frames[i][j].module_index, 422 EXPECT_EQ(sample_frames[i][j].module_index,
423 static_cast<size_t>(entry.module_id_index())); 423 static_cast<size_t>(entry.module_id_index()));
424 } 424 }
425 } 425 }
426 } 426 }
427 427
428 // Checks that unknown modules produce an empty Entry. 428 // Checks that unknown modules produce an empty Entry.
429 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { 429 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) {
430 const Frame frame(reinterpret_cast<const void*>(0x1000), 430 const Frame frame(0x1000, Frame::kUnknownModuleIndex);
431 Frame::kUnknownModuleIndex);
432 431
433 Profile profile; 432 Profile profile;
434 433
435 profile.samples.push_back(Sample(1, frame)); 434 profile.samples.push_back(Sample(1, frame));
436 435
437 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 436 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
438 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 437 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
439 438
440 CallStackProfileMetricsProvider provider; 439 CallStackProfileMetricsProvider provider;
441 provider.OnRecordingEnabled(); 440 provider.OnRecordingEnabled();
(...skipping 19 matching lines...) Expand all
461 EXPECT_FALSE(entry.has_module_id_index()); 460 EXPECT_FALSE(entry.has_module_id_index());
462 } 461 }
463 462
464 // Checks that pending profiles are only passed back to ProvideGeneralMetrics 463 // Checks that pending profiles are only passed back to ProvideGeneralMetrics
465 // once. 464 // once.
466 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { 465 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) {
467 CallStackProfileMetricsProvider provider; 466 CallStackProfileMetricsProvider provider;
468 for (int i = 0; i < 2; ++i) { 467 for (int i = 0; i < 2; ++i) {
469 Profile profile; 468 Profile profile;
470 profile.samples.push_back(Sample(1, Frame( 469 profile.samples.push_back(Sample(1, Frame(
471 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 470 0x1000, Frame::kUnknownModuleIndex)));
Mike Wittman 2015/09/01 01:42:15 nit: move first arg to previous line (and second,
sydli 2015/09/03 16:21:15 Ran git cl format.
Mike Wittman 2015/09/03 16:58:03 This is fine for this change and below, but has in
472 471
473 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 472 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
474 // Use the sampling period to distinguish the two profiles. 473 // Use the sampling period to distinguish the two profiles.
475 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); 474 profile.sampling_period = base::TimeDelta::FromMilliseconds(i);
476 475
477 provider.OnRecordingEnabled(); 476 provider.OnRecordingEnabled();
478 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 477 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
479 std::vector<Profile>(1, profile)); 478 std::vector<Profile>(1, profile));
480 ChromeUserMetricsExtension uma_proto; 479 ChromeUserMetricsExtension uma_proto;
481 provider.ProvideGeneralMetrics(&uma_proto); 480 provider.ProvideGeneralMetrics(&uma_proto);
482 481
483 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 482 ASSERT_EQ(1, uma_proto.sampled_profile().size());
484 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 483 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
485 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 484 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
486 const CallStackProfile& call_stack_profile = 485 const CallStackProfile& call_stack_profile =
487 sampled_profile.call_stack_profile(); 486 sampled_profile.call_stack_profile();
488 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); 487 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms());
489 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); 488 EXPECT_EQ(i, call_stack_profile.sampling_period_ms());
490 } 489 }
491 } 490 }
492 491
493 // Checks that pending profiles are provided to ProvideGeneralMetrics 492 // Checks that pending profiles are provided to ProvideGeneralMetrics
494 // when collected before CallStackProfileMetricsProvider is instantiated. 493 // when collected before CallStackProfileMetricsProvider is instantiated.
495 TEST_F(CallStackProfileMetricsProviderTest, 494 TEST_F(CallStackProfileMetricsProviderTest,
496 ProfilesProvidedWhenCollectedBeforeInstantiation) { 495 ProfilesProvidedWhenCollectedBeforeInstantiation) {
497 Profile profile; 496 Profile profile;
498 profile.samples.push_back(Sample(1, Frame( 497 profile.samples.push_back(Sample(1, Frame(
499 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 498 0x1000, Frame::kUnknownModuleIndex)));
500 499
501 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 500 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
502 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 501 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
503 502
504 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 503 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
505 std::vector<Profile>(1, profile)); 504 std::vector<Profile>(1, profile));
506 505
507 CallStackProfileMetricsProvider provider; 506 CallStackProfileMetricsProvider provider;
508 provider.OnRecordingEnabled(); 507 provider.OnRecordingEnabled();
509 ChromeUserMetricsExtension uma_proto; 508 ChromeUserMetricsExtension uma_proto;
510 provider.ProvideGeneralMetrics(&uma_proto); 509 provider.ProvideGeneralMetrics(&uma_proto);
511 510
512 EXPECT_EQ(1, uma_proto.sampled_profile_size()); 511 EXPECT_EQ(1, uma_proto.sampled_profile_size());
513 } 512 }
514 513
515 // Checks that pending profiles are not provided to ProvideGeneralMetrics 514 // Checks that pending profiles are not provided to ProvideGeneralMetrics
516 // while recording is disabled. 515 // while recording is disabled.
517 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { 516 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) {
518 Profile profile; 517 Profile profile;
519 profile.samples.push_back(Sample(1, Frame( 518 profile.samples.push_back(Sample(1, Frame(
520 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 519 0x1000, Frame::kUnknownModuleIndex)));
521 520
522 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 521 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
523 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 522 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
524 523
525 CallStackProfileMetricsProvider provider; 524 CallStackProfileMetricsProvider provider;
526 provider.OnRecordingDisabled(); 525 provider.OnRecordingDisabled();
527 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 526 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
528 std::vector<Profile>(1, profile)); 527 std::vector<Profile>(1, profile));
529 ChromeUserMetricsExtension uma_proto; 528 ChromeUserMetricsExtension uma_proto;
530 provider.ProvideGeneralMetrics(&uma_proto); 529 provider.ProvideGeneralMetrics(&uma_proto);
531 530
532 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 531 EXPECT_EQ(0, uma_proto.sampled_profile_size());
533 } 532 }
534 533
535 // Checks that pending profiles are not provided to ProvideGeneralMetrics 534 // Checks that pending profiles are not provided to ProvideGeneralMetrics
536 // if recording is disabled while profiling. 535 // if recording is disabled while profiling.
537 TEST_F(CallStackProfileMetricsProviderTest, 536 TEST_F(CallStackProfileMetricsProviderTest,
538 ProfilesNotProvidedAfterChangeToDisabled) { 537 ProfilesNotProvidedAfterChangeToDisabled) {
539 Profile profile; 538 Profile profile;
540 profile.samples.push_back(Sample(1, Frame( 539 profile.samples.push_back(Sample(1, Frame(
541 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 540 0x1000, Frame::kUnknownModuleIndex)));
542 541
543 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 542 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
544 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 543 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
545 544
546 CallStackProfileMetricsProvider provider; 545 CallStackProfileMetricsProvider provider;
547 provider.OnRecordingEnabled(); 546 provider.OnRecordingEnabled();
548 base::StackSamplingProfiler::CompletedCallback callback = 547 base::StackSamplingProfiler::CompletedCallback callback =
549 CallStackProfileMetricsProvider::GetProfilerCallback( 548 CallStackProfileMetricsProvider::GetProfilerCallback(
550 Params(Params::PROCESS_STARTUP, false)); 549 Params(Params::PROCESS_STARTUP, false));
551 550
552 provider.OnRecordingDisabled(); 551 provider.OnRecordingDisabled();
553 callback.Run(std::vector<Profile>(1, profile)); 552 callback.Run(std::vector<Profile>(1, profile));
554 ChromeUserMetricsExtension uma_proto; 553 ChromeUserMetricsExtension uma_proto;
555 provider.ProvideGeneralMetrics(&uma_proto); 554 provider.ProvideGeneralMetrics(&uma_proto);
556 555
557 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 556 EXPECT_EQ(0, uma_proto.sampled_profile_size());
558 } 557 }
559 558
560 // Checks that pending profiles are not provided to ProvideGeneralMetrics if 559 // Checks that pending profiles are not provided to ProvideGeneralMetrics if
561 // recording is enabled, but then disabled and reenabled while profiling. 560 // recording is enabled, but then disabled and reenabled while profiling.
562 TEST_F(CallStackProfileMetricsProviderTest, 561 TEST_F(CallStackProfileMetricsProviderTest,
563 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { 562 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) {
564 Profile profile; 563 Profile profile;
565 profile.samples.push_back(Sample(1, Frame( 564 profile.samples.push_back(Sample(1, Frame(
566 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 565 0x1000, Frame::kUnknownModuleIndex)));
567 566
568 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 567 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
569 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 568 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
570 569
571 CallStackProfileMetricsProvider provider; 570 CallStackProfileMetricsProvider provider;
572 provider.OnRecordingEnabled(); 571 provider.OnRecordingEnabled();
573 base::StackSamplingProfiler::CompletedCallback callback = 572 base::StackSamplingProfiler::CompletedCallback callback =
574 CallStackProfileMetricsProvider::GetProfilerCallback( 573 CallStackProfileMetricsProvider::GetProfilerCallback(
575 Params(Params::PROCESS_STARTUP, false)); 574 Params(Params::PROCESS_STARTUP, false));
576 575
577 provider.OnRecordingDisabled(); 576 provider.OnRecordingDisabled();
578 provider.OnRecordingEnabled(); 577 provider.OnRecordingEnabled();
579 callback.Run(std::vector<Profile>(1, profile)); 578 callback.Run(std::vector<Profile>(1, profile));
580 ChromeUserMetricsExtension uma_proto; 579 ChromeUserMetricsExtension uma_proto;
581 provider.ProvideGeneralMetrics(&uma_proto); 580 provider.ProvideGeneralMetrics(&uma_proto);
582 581
583 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 582 EXPECT_EQ(0, uma_proto.sampled_profile_size());
584 } 583 }
585 584
586 // Checks that pending profiles are not provided to ProvideGeneralMetrics 585 // Checks that pending profiles are not provided to ProvideGeneralMetrics
587 // if recording is disabled, but then enabled while profiling. 586 // if recording is disabled, but then enabled while profiling.
588 TEST_F(CallStackProfileMetricsProviderTest, 587 TEST_F(CallStackProfileMetricsProviderTest,
589 ProfilesNotProvidedAfterChangeFromDisabled) { 588 ProfilesNotProvidedAfterChangeFromDisabled) {
590 Profile profile; 589 Profile profile;
591 profile.samples.push_back(Sample(1, Frame( 590 profile.samples.push_back(Sample(1, Frame(
592 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 591 0x1000, Frame::kUnknownModuleIndex)));
593 592
594 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 593 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
595 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 594 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
596 595
597 CallStackProfileMetricsProvider provider; 596 CallStackProfileMetricsProvider provider;
598 provider.OnRecordingDisabled(); 597 provider.OnRecordingDisabled();
599 base::StackSamplingProfiler::CompletedCallback callback = 598 base::StackSamplingProfiler::CompletedCallback callback =
600 CallStackProfileMetricsProvider::GetProfilerCallback( 599 CallStackProfileMetricsProvider::GetProfilerCallback(
601 Params(Params::PROCESS_STARTUP, false)); 600 Params(Params::PROCESS_STARTUP, false));
602 601
603 provider.OnRecordingEnabled(); 602 provider.OnRecordingEnabled();
604 callback.Run(std::vector<Profile>(1, profile)); 603 callback.Run(std::vector<Profile>(1, profile));
605 ChromeUserMetricsExtension uma_proto; 604 ChromeUserMetricsExtension uma_proto;
606 provider.ProvideGeneralMetrics(&uma_proto); 605 provider.ProvideGeneralMetrics(&uma_proto);
607 606
608 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 607 EXPECT_EQ(0, uma_proto.sampled_profile_size());
609 } 608 }
610 609
611 } // namespace metrics 610 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698