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

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

Issue 1319973011: Stack sampling profiler uses uintptr_t instead of void*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@UMA2_refactor
Patch Set: 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
« no previous file with comments | « base/profiler/stack_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 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),
431 Frame::kUnknownModuleIndex); 431 Frame::kUnknownModuleIndex);
432 432
433 Profile profile; 433 Profile profile;
434 434
435 profile.samples.push_back(Sample(1, frame)); 435 profile.samples.push_back(Sample(1, frame));
436 436
437 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 437 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
438 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 438 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
439 439
440 CallStackProfileMetricsProvider provider; 440 CallStackProfileMetricsProvider provider;
(...skipping 20 matching lines...) Expand all
461 EXPECT_FALSE(entry.has_module_id_index()); 461 EXPECT_FALSE(entry.has_module_id_index());
462 } 462 }
463 463
464 // Checks that pending profiles are only passed back to ProvideGeneralMetrics 464 // Checks that pending profiles are only passed back to ProvideGeneralMetrics
465 // once. 465 // once.
466 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { 466 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) {
467 CallStackProfileMetricsProvider provider; 467 CallStackProfileMetricsProvider provider;
468 for (int i = 0; i < 2; ++i) { 468 for (int i = 0; i < 2; ++i) {
469 Profile profile; 469 Profile profile;
470 profile.samples.push_back(Sample(1, Frame( 470 profile.samples.push_back(Sample(1, Frame(
471 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 471 (0x1000), Frame::kUnknownModuleIndex)));
472 472
473 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 473 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
474 // Use the sampling period to distinguish the two profiles. 474 // Use the sampling period to distinguish the two profiles.
475 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); 475 profile.sampling_period = base::TimeDelta::FromMilliseconds(i);
476 476
477 provider.OnRecordingEnabled(); 477 provider.OnRecordingEnabled();
478 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 478 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
479 std::vector<Profile>(1, profile)); 479 std::vector<Profile>(1, profile));
480 ChromeUserMetricsExtension uma_proto; 480 ChromeUserMetricsExtension uma_proto;
481 provider.ProvideGeneralMetrics(&uma_proto); 481 provider.ProvideGeneralMetrics(&uma_proto);
482 482
483 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 483 ASSERT_EQ(1, uma_proto.sampled_profile().size());
484 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 484 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
485 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 485 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
486 const CallStackProfile& call_stack_profile = 486 const CallStackProfile& call_stack_profile =
487 sampled_profile.call_stack_profile(); 487 sampled_profile.call_stack_profile();
488 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); 488 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms());
489 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); 489 EXPECT_EQ(i, call_stack_profile.sampling_period_ms());
490 } 490 }
491 } 491 }
492 492
493 // Checks that pending profiles are provided to ProvideGeneralMetrics 493 // Checks that pending profiles are provided to ProvideGeneralMetrics
494 // when collected before CallStackProfileMetricsProvider is instantiated. 494 // when collected before CallStackProfileMetricsProvider is instantiated.
495 TEST_F(CallStackProfileMetricsProviderTest, 495 TEST_F(CallStackProfileMetricsProviderTest,
496 ProfilesProvidedWhenCollectedBeforeInstantiation) { 496 ProfilesProvidedWhenCollectedBeforeInstantiation) {
497 Profile profile; 497 Profile profile;
498 profile.samples.push_back(Sample(1, Frame( 498 profile.samples.push_back(Sample(1, Frame(
499 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 499 (0x1000), Frame::kUnknownModuleIndex)));
500 500
501 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 501 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
502 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 502 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
503 503
504 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 504 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
505 std::vector<Profile>(1, profile)); 505 std::vector<Profile>(1, profile));
506 506
507 CallStackProfileMetricsProvider provider; 507 CallStackProfileMetricsProvider provider;
508 provider.OnRecordingEnabled(); 508 provider.OnRecordingEnabled();
509 ChromeUserMetricsExtension uma_proto; 509 ChromeUserMetricsExtension uma_proto;
510 provider.ProvideGeneralMetrics(&uma_proto); 510 provider.ProvideGeneralMetrics(&uma_proto);
511 511
512 EXPECT_EQ(1, uma_proto.sampled_profile_size()); 512 EXPECT_EQ(1, uma_proto.sampled_profile_size());
513 } 513 }
514 514
515 // Checks that pending profiles are not provided to ProvideGeneralMetrics 515 // Checks that pending profiles are not provided to ProvideGeneralMetrics
516 // while recording is disabled. 516 // while recording is disabled.
517 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { 517 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) {
518 Profile profile; 518 Profile profile;
519 profile.samples.push_back(Sample(1, Frame( 519 profile.samples.push_back(Sample(1, Frame(
520 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 520 (0x1000), Frame::kUnknownModuleIndex)));
521 521
522 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 522 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
523 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 523 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
524 524
525 CallStackProfileMetricsProvider provider; 525 CallStackProfileMetricsProvider provider;
526 provider.OnRecordingDisabled(); 526 provider.OnRecordingDisabled();
527 AppendProfiles(Params(Params::PROCESS_STARTUP, false), 527 AppendProfiles(Params(Params::PROCESS_STARTUP, false),
528 std::vector<Profile>(1, profile)); 528 std::vector<Profile>(1, profile));
529 ChromeUserMetricsExtension uma_proto; 529 ChromeUserMetricsExtension uma_proto;
530 provider.ProvideGeneralMetrics(&uma_proto); 530 provider.ProvideGeneralMetrics(&uma_proto);
531 531
532 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 532 EXPECT_EQ(0, uma_proto.sampled_profile_size());
533 } 533 }
534 534
535 // Checks that pending profiles are not provided to ProvideGeneralMetrics 535 // Checks that pending profiles are not provided to ProvideGeneralMetrics
536 // if recording is disabled while profiling. 536 // if recording is disabled while profiling.
537 TEST_F(CallStackProfileMetricsProviderTest, 537 TEST_F(CallStackProfileMetricsProviderTest,
538 ProfilesNotProvidedAfterChangeToDisabled) { 538 ProfilesNotProvidedAfterChangeToDisabled) {
539 Profile profile; 539 Profile profile;
540 profile.samples.push_back(Sample(1, Frame( 540 profile.samples.push_back(Sample(1, Frame(
541 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 541 (0x1000), Frame::kUnknownModuleIndex)));
542 542
543 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 543 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
544 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 544 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
545 545
546 CallStackProfileMetricsProvider provider; 546 CallStackProfileMetricsProvider provider;
547 provider.OnRecordingEnabled(); 547 provider.OnRecordingEnabled();
548 base::StackSamplingProfiler::CompletedCallback callback = 548 base::StackSamplingProfiler::CompletedCallback callback =
549 CallStackProfileMetricsProvider::GetProfilerCallback( 549 CallStackProfileMetricsProvider::GetProfilerCallback(
550 Params(Params::PROCESS_STARTUP, false)); 550 Params(Params::PROCESS_STARTUP, false));
551 551
552 provider.OnRecordingDisabled(); 552 provider.OnRecordingDisabled();
553 callback.Run(std::vector<Profile>(1, profile)); 553 callback.Run(std::vector<Profile>(1, profile));
554 ChromeUserMetricsExtension uma_proto; 554 ChromeUserMetricsExtension uma_proto;
555 provider.ProvideGeneralMetrics(&uma_proto); 555 provider.ProvideGeneralMetrics(&uma_proto);
556 556
557 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 557 EXPECT_EQ(0, uma_proto.sampled_profile_size());
558 } 558 }
559 559
560 // Checks that pending profiles are not provided to ProvideGeneralMetrics if 560 // Checks that pending profiles are not provided to ProvideGeneralMetrics if
561 // recording is enabled, but then disabled and reenabled while profiling. 561 // recording is enabled, but then disabled and reenabled while profiling.
562 TEST_F(CallStackProfileMetricsProviderTest, 562 TEST_F(CallStackProfileMetricsProviderTest,
563 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { 563 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) {
564 Profile profile; 564 Profile profile;
565 profile.samples.push_back(Sample(1, Frame( 565 profile.samples.push_back(Sample(1, Frame(
566 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 566 (0x1000), Frame::kUnknownModuleIndex)));
567 567
568 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 568 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
569 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 569 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
570 570
571 CallStackProfileMetricsProvider provider; 571 CallStackProfileMetricsProvider provider;
572 provider.OnRecordingEnabled(); 572 provider.OnRecordingEnabled();
573 base::StackSamplingProfiler::CompletedCallback callback = 573 base::StackSamplingProfiler::CompletedCallback callback =
574 CallStackProfileMetricsProvider::GetProfilerCallback( 574 CallStackProfileMetricsProvider::GetProfilerCallback(
575 Params(Params::PROCESS_STARTUP, false)); 575 Params(Params::PROCESS_STARTUP, false));
576 576
577 provider.OnRecordingDisabled(); 577 provider.OnRecordingDisabled();
578 provider.OnRecordingEnabled(); 578 provider.OnRecordingEnabled();
579 callback.Run(std::vector<Profile>(1, profile)); 579 callback.Run(std::vector<Profile>(1, profile));
580 ChromeUserMetricsExtension uma_proto; 580 ChromeUserMetricsExtension uma_proto;
581 provider.ProvideGeneralMetrics(&uma_proto); 581 provider.ProvideGeneralMetrics(&uma_proto);
582 582
583 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 583 EXPECT_EQ(0, uma_proto.sampled_profile_size());
584 } 584 }
585 585
586 // Checks that pending profiles are not provided to ProvideGeneralMetrics 586 // Checks that pending profiles are not provided to ProvideGeneralMetrics
587 // if recording is disabled, but then enabled while profiling. 587 // if recording is disabled, but then enabled while profiling.
588 TEST_F(CallStackProfileMetricsProviderTest, 588 TEST_F(CallStackProfileMetricsProviderTest,
589 ProfilesNotProvidedAfterChangeFromDisabled) { 589 ProfilesNotProvidedAfterChangeFromDisabled) {
590 Profile profile; 590 Profile profile;
591 profile.samples.push_back(Sample(1, Frame( 591 profile.samples.push_back(Sample(1, Frame(
592 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); 592 (0x1000), Frame::kUnknownModuleIndex)));
593 593
594 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 594 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
595 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 595 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
596 596
597 CallStackProfileMetricsProvider provider; 597 CallStackProfileMetricsProvider provider;
598 provider.OnRecordingDisabled(); 598 provider.OnRecordingDisabled();
599 base::StackSamplingProfiler::CompletedCallback callback = 599 base::StackSamplingProfiler::CompletedCallback callback =
600 CallStackProfileMetricsProvider::GetProfilerCallback( 600 CallStackProfileMetricsProvider::GetProfilerCallback(
601 Params(Params::PROCESS_STARTUP, false)); 601 Params(Params::PROCESS_STARTUP, false));
602 602
603 provider.OnRecordingEnabled(); 603 provider.OnRecordingEnabled();
604 callback.Run(std::vector<Profile>(1, profile)); 604 callback.Run(std::vector<Profile>(1, profile));
605 ChromeUserMetricsExtension uma_proto; 605 ChromeUserMetricsExtension uma_proto;
606 provider.ProvideGeneralMetrics(&uma_proto); 606 provider.ProvideGeneralMetrics(&uma_proto);
607 607
608 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 608 EXPECT_EQ(0, uma_proto.sampled_profile_size());
609 } 609 }
610 610
611 } // namespace metrics 611 } // namespace metrics
OLDNEW
« no previous file with comments | « base/profiler/stack_sampling_profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698