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 2444143002: Add process lifetime annotations to stack samples. (Closed)
Patch Set: addressed review comments and added test Created 4 years, 1 month 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 std::vector<Profile> profiles; 186 std::vector<Profile> profiles;
187 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { 187 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) {
188 Profile profile; 188 Profile profile;
189 profile.modules.insert( 189 profile.modules.insert(
190 profile.modules.end(), &profile_modules[i][0], 190 profile.modules.end(), &profile_modules[i][0],
191 &profile_modules[i][0] + arraysize(profile_modules[i])); 191 &profile_modules[i][0] + arraysize(profile_modules[i]));
192 192
193 for (size_t j = 0; j < arraysize(profile_sample_frames[i]); ++j) { 193 for (size_t j = 0; j < arraysize(profile_sample_frames[i]); ++j) {
194 profile.samples.push_back(Sample()); 194 profile.samples.push_back(Sample());
195 Sample& sample = profile.samples.back(); 195 Sample& sample = profile.samples.back();
196 sample.insert(sample.end(), &profile_sample_frames[i][j][0], 196 sample.frames.insert(sample.frames.end(), &profile_sample_frames[i][j][0],
197 &profile_sample_frames[i][j][0] + 197 &profile_sample_frames[i][j][0] +
198 arraysize(profile_sample_frames[i][j])); 198 arraysize(profile_sample_frames[i][j]));
199 } 199 }
200 200
201 profile.profile_duration = profile_durations[i]; 201 profile.profile_duration = profile_durations[i];
202 profile.sampling_period = profile_sampling_periods[i]; 202 profile.sampling_period = profile_sampling_periods[i];
203 203
204 profiles.push_back(std::move(profile)); 204 profiles.push_back(std::move(profile));
205 } 205 }
206 206
207 CallStackProfileMetricsProvider provider; 207 CallStackProfileMetricsProvider provider;
208 provider.OnRecordingEnabled(); 208 provider.OnRecordingEnabled();
209 AppendProfiles( 209 AppendProfiles(
210 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 210 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
211 CallStackProfileParams::UI_THREAD, 211 CallStackProfileParams::UI_THREAD,
212 CallStackProfileParams::PROCESS_STARTUP, 212 CallStackProfileParams::PROCESS_STARTUP,
213 CallStackProfileParams::MAY_SHUFFLE), 213 CallStackProfileParams::MAY_SHUFFLE),
214 std::move(profiles)); 214 std::move(profiles));
215 ChromeUserMetricsExtension uma_proto; 215 ChromeUserMetricsExtension uma_proto;
216 provider.ProvideGeneralMetrics(&uma_proto); 216 provider.ProvideGeneralMetrics(&uma_proto);
217 217
218 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)), 218 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)),
219 uma_proto.sampled_profile().size()); 219 uma_proto.sampled_profile().size());
220 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { 220 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) {
221 SCOPED_TRACE("profile " + base::SizeTToString(i)); 221 SCOPED_TRACE("profile " + base::SizeTToString(i));
222 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i); 222 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i);
223 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 223 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
224 const CallStackProfile& call_stack_profile = 224 const CallStackProfile& call_stack_profile =
225 sampled_profile.call_stack_profile(); 225 sampled_profile.call_stack_profile();
226
227 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames[i])), 226 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames[i])),
228 call_stack_profile.sample().size()); 227 call_stack_profile.sample().size());
229 for (size_t j = 0; j < arraysize(profile_sample_frames[i]); ++j) { 228 for (size_t j = 0; j < arraysize(profile_sample_frames[i]); ++j) {
230 SCOPED_TRACE("sample " + base::SizeTToString(j)); 229 SCOPED_TRACE("sample " + base::SizeTToString(j));
231 const CallStackProfile::Sample& proto_sample = 230 const CallStackProfile::Sample& proto_sample =
232 call_stack_profile.sample().Get(j); 231 call_stack_profile.sample().Get(j);
233 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames[i][j])), 232 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames[i][j])),
234 proto_sample.entry().size()); 233 proto_sample.entry().size());
235 ASSERT_TRUE(proto_sample.has_count()); 234 ASSERT_TRUE(proto_sample.has_count());
236 EXPECT_EQ(1u, proto_sample.count()); 235 EXPECT_EQ(1u, proto_sample.count());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 module_base_address, 289 module_base_address,
291 "ABCD", 290 "ABCD",
292 #if defined(OS_WIN) 291 #if defined(OS_WIN)
293 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 292 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
294 #else 293 #else
295 base::FilePath("/some/path/to/chrome") 294 base::FilePath("/some/path/to/chrome")
296 #endif 295 #endif
297 ) 296 )
298 }; 297 };
299 298
300 // Duplicate samples in slots 0, 2, and 3. 299 // Samples are unique only if the phase, activity, and frame all match.
300 const uint32_t profile_phases_and_activities[][2] = {
301 { 1, 0 },
302 { 1, 0 },
303 { 3, 0 },
304 { 3, 0 },
305 { 3, 1 },
306 // Unique above, duplicates below.
307 { 1, 0 },
308 { 1, 0 },
309 { 3, 0 },
310 };
301 const Frame sample_frames[][1] = { 311 const Frame sample_frames[][1] = {
Mike Wittman 2016/11/03 21:15:39 This test is getting kind of hard to follow... I t
302 { Frame(module_base_address + 0x10, 0), }, 312 { Frame(module_base_address + 0x10, 0), },
303 { Frame(module_base_address + 0x20, 0), }, 313 { Frame(module_base_address + 0x20, 0), },
304 { Frame(module_base_address + 0x10, 0), }, 314 { Frame(module_base_address + 0x10, 0), },
305 { Frame(module_base_address + 0x10, 0) } 315 { Frame(module_base_address + 0x20, 0), },
316 { Frame(module_base_address + 0x10, 0), },
317 // Unique above, duplicates below.
318 { Frame(module_base_address + 0x10, 0), },
319 { Frame(module_base_address + 0x10, 0), },
320 { Frame(module_base_address + 0x10, 0), },
321 };
322
323 const int duplicate_counts[] = {
324 3, 1, 2, 1, 1,
306 }; 325 };
307 326
308 Profile profile; 327 Profile profile;
309 profile.modules.insert(profile.modules.end(), &modules[0], 328 profile.modules.insert(profile.modules.end(), &modules[0],
310 &modules[0] + arraysize(modules)); 329 &modules[0] + arraysize(modules));
311 330
312 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 331 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
313 profile.samples.push_back(Sample()); 332 profile.samples.push_back(Sample());
314 Sample& sample = profile.samples.back(); 333 Sample& sample = profile.samples.back();
315 sample.insert(sample.end(), &sample_frames[i][0], 334 sample.process_phases = profile_phases_and_activities[i][0];
316 &sample_frames[i][0] + arraysize(sample_frames[i])); 335 sample.current_activities = profile_phases_and_activities[i][1];
336 sample.frames.insert(sample.frames.end(), &sample_frames[i][0],
337 &sample_frames[i][0] + arraysize(sample_frames[i]));
317 } 338 }
318 339
319 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 340 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
320 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 341 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
321 Profiles profiles; 342 Profiles profiles;
322 profiles.push_back(std::move(profile)); 343 profiles.push_back(std::move(profile));
323 344
324 CallStackProfileMetricsProvider provider; 345 CallStackProfileMetricsProvider provider;
325 provider.OnRecordingEnabled(); 346 provider.OnRecordingEnabled();
326 AppendProfiles( 347 AppendProfiles(
327 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 348 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
328 CallStackProfileParams::UI_THREAD, 349 CallStackProfileParams::UI_THREAD,
329 CallStackProfileParams::PROCESS_STARTUP, 350 CallStackProfileParams::PROCESS_STARTUP,
330 CallStackProfileParams::MAY_SHUFFLE), 351 CallStackProfileParams::MAY_SHUFFLE),
331 std::move(profiles)); 352 std::move(profiles));
332 ChromeUserMetricsExtension uma_proto; 353 ChromeUserMetricsExtension uma_proto;
333 provider.ProvideGeneralMetrics(&uma_proto); 354 provider.ProvideGeneralMetrics(&uma_proto);
334 355
335 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 356 ASSERT_EQ(1, uma_proto.sampled_profile().size());
336 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 357 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
337 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 358 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
338 const CallStackProfile& call_stack_profile = 359 const CallStackProfile& call_stack_profile =
339 sampled_profile.call_stack_profile(); 360 sampled_profile.call_stack_profile();
340 361
341 ASSERT_EQ(2, call_stack_profile.sample().size()); 362 ASSERT_EQ(static_cast<int>(arraysize(duplicate_counts)),
342 for (int i = 0; i < 2; ++i) { 363 call_stack_profile.sample().size());
343 SCOPED_TRACE("sample " + base::IntToString(i)); 364 for (size_t i = 0; i < arraysize(duplicate_counts); ++i) {
365 SCOPED_TRACE("sample " + base::SizeTToString(i));
344 const CallStackProfile::Sample& proto_sample = 366 const CallStackProfile::Sample& proto_sample =
345 call_stack_profile.sample().Get(i); 367 call_stack_profile.sample().Get(i);
368
369 // For MAY_SHUFFLE, these are reset with every sample.
370 uint32_t process_phase = 0;
371 uint32_t current_activities = 0;
372
346 ASSERT_EQ(static_cast<int>(arraysize(sample_frames[i])), 373 ASSERT_EQ(static_cast<int>(arraysize(sample_frames[i])),
347 proto_sample.entry().size()); 374 proto_sample.entry().size());
348 ASSERT_TRUE(proto_sample.has_count()); 375 ASSERT_TRUE(proto_sample.has_count());
349 EXPECT_EQ(i == 0 ? 3u : 1u, proto_sample.count()); 376 EXPECT_EQ(duplicate_counts[i], proto_sample.count());
350 for (size_t j = 0; j < arraysize(sample_frames[i]); ++j) { 377 for (size_t j = 0; j < arraysize(sample_frames[i]); ++j) {
351 SCOPED_TRACE("frame " + base::SizeTToString(j)); 378 SCOPED_TRACE("frame " + base::SizeTToString(j));
352 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j); 379 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j);
353 ASSERT_TRUE(entry.has_address()); 380 ASSERT_TRUE(entry.has_address());
354 const char* instruction_pointer = reinterpret_cast<const char*>( 381 const char* instruction_pointer = reinterpret_cast<const char*>(
355 sample_frames[i][j].instruction_pointer); 382 sample_frames[i][j].instruction_pointer);
356 const char* module_base_address = reinterpret_cast<const char*>( 383 const char* module_base_address = reinterpret_cast<const char*>(
357 modules[sample_frames[i][j].module_index].base_address); 384 modules[sample_frames[i][j].module_index].base_address);
358 EXPECT_EQ( 385 EXPECT_EQ(
359 static_cast<uint64_t>(instruction_pointer - module_base_address), 386 static_cast<uint64_t>(instruction_pointer - module_base_address),
360 entry.address()); 387 entry.address());
361 ASSERT_TRUE(entry.has_module_id_index()); 388 ASSERT_TRUE(entry.has_module_id_index());
362 EXPECT_EQ(sample_frames[i][j].module_index, 389 EXPECT_EQ(sample_frames[i][j].module_index,
363 static_cast<size_t>(entry.module_id_index())); 390 static_cast<size_t>(entry.module_id_index()));
364 } 391 }
392
393 for (int x = 0; x < proto_sample.process_phase_size(); ++x) {
394 process_phase |= 1 << proto_sample.process_phase(x);
395 }
396 EXPECT_EQ(profile_phases_and_activities[i][0], process_phase);
397
398 for (int x = 0; x < proto_sample.activities_begun_size(); ++x) {
399 current_activities |= 1 << proto_sample.activities_begun(x);
400 }
401 for (int x = 0; x < proto_sample.activities_ended_size(); ++x) {
Mike Wittman 2016/11/03 21:15:39 EXPECT_EQ(0u, proto_sample.activities_ended_size()
402 current_activities &= ~(1 << proto_sample.activities_ended(x));
403 }
404 EXPECT_EQ(profile_phases_and_activities[i][1], current_activities);
365 } 405 }
366 } 406 }
367 407
368 // Checks that only contiguous duplicate samples are collapsed with 408 // Checks that only contiguous duplicate samples are collapsed with
369 // preserve_sample_ordering = true. 409 // preserve_sample_ordering = true.
370 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { 410 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) {
371 const uintptr_t module_base_address = 0x1000; 411 const uintptr_t module_base_address = 0x1000;
372 412
373 const Module modules[] = { 413 const Module modules[] = {
374 Module( 414 Module(
375 module_base_address, 415 module_base_address,
376 "ABCD", 416 "ABCD",
377 #if defined(OS_WIN) 417 #if defined(OS_WIN)
378 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") 418 base::FilePath(L"c:\\some\\path\\to\\chrome.exe")
379 #else 419 #else
380 base::FilePath("/some/path/to/chrome") 420 base::FilePath("/some/path/to/chrome")
381 #endif 421 #endif
382 ) 422 )
383 }; 423 };
384 424
385 // Duplicate samples in slots 0, 2, and 3. 425 // Samples are unique only if the phase, activity, and frame all match.
426 const uint32_t profile_phases_and_activities[][2] = {
427 { 1, 0 },
428 { 1, 0 },
429 { 1, 0 },
430 { 1, 0 },
431
432 { 3, 0 },
433 { 3, 1 },
434 { 3, 0 },
435 { 3, 0 },
436 };
386 const Frame sample_frames[][1] = { 437 const Frame sample_frames[][1] = {
Mike Wittman 2016/11/03 21:15:39 Same comment here about representing with Sample.
387 { Frame(module_base_address + 0x10, 0), }, 438 { Frame(module_base_address + 0x10, 0), },
388 { Frame(module_base_address + 0x20, 0), }, 439 { Frame(module_base_address + 0x20, 0), },
389 { Frame(module_base_address + 0x10, 0), }, 440 { Frame(module_base_address + 0x10, 0), },
390 { Frame(module_base_address + 0x10, 0) } 441 { Frame(module_base_address + 0x10, 0), },
442
443 { Frame(module_base_address + 0x10, 0), },
444 { Frame(module_base_address + 0x20, 0), },
445 { Frame(module_base_address + 0x10, 0), },
446 { Frame(module_base_address + 0x10, 0), },
447 };
448
449 const int duplicate_counts[] = {
450 1, 1, 2, 1, 1, 2
391 }; 451 };
392 452
393 Profile profile; 453 Profile profile;
394 profile.modules.insert(profile.modules.end(), &modules[0], 454 profile.modules.insert(profile.modules.end(), &modules[0],
395 &modules[0] + arraysize(modules)); 455 &modules[0] + arraysize(modules));
396 456
397 for (size_t i = 0; i < arraysize(sample_frames); ++i) { 457 for (size_t i = 0; i < arraysize(sample_frames); ++i) {
398 profile.samples.push_back(Sample()); 458 profile.samples.push_back(Sample());
399 Sample& sample = profile.samples.back(); 459 Sample& sample = profile.samples.back();
400 sample.insert(sample.end(), &sample_frames[i][0], 460 sample.process_phases = profile_phases_and_activities[i][0];
401 &sample_frames[i][0] + arraysize(sample_frames[i])); 461 sample.current_activities = profile_phases_and_activities[i][1];
462 sample.frames.insert(sample.frames.end(), &sample_frames[i][0],
463 &sample_frames[i][0] + arraysize(sample_frames[i]));
402 } 464 }
403 465
404 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 466 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
405 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 467 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
406 Profiles profiles; 468 Profiles profiles;
407 profiles.push_back(std::move(profile)); 469 profiles.push_back(std::move(profile));
408 470
409 CallStackProfileMetricsProvider provider; 471 CallStackProfileMetricsProvider provider;
410 provider.OnRecordingEnabled(); 472 provider.OnRecordingEnabled();
411 AppendProfiles(CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 473 AppendProfiles(CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
412 CallStackProfileParams::UI_THREAD, 474 CallStackProfileParams::UI_THREAD,
413 CallStackProfileParams::PROCESS_STARTUP, 475 CallStackProfileParams::PROCESS_STARTUP,
414 CallStackProfileParams::PRESERVE_ORDER), 476 CallStackProfileParams::PRESERVE_ORDER),
415 std::move(profiles)); 477 std::move(profiles));
416 ChromeUserMetricsExtension uma_proto; 478 ChromeUserMetricsExtension uma_proto;
417 provider.ProvideGeneralMetrics(&uma_proto); 479 provider.ProvideGeneralMetrics(&uma_proto);
418 480
419 ASSERT_EQ(1, uma_proto.sampled_profile().size()); 481 ASSERT_EQ(1, uma_proto.sampled_profile().size());
420 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); 482 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0);
421 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); 483 ASSERT_TRUE(sampled_profile.has_call_stack_profile());
422 const CallStackProfile& call_stack_profile = 484 const CallStackProfile& call_stack_profile =
423 sampled_profile.call_stack_profile(); 485 sampled_profile.call_stack_profile();
424 486
425 ASSERT_EQ(3, call_stack_profile.sample().size()); 487 // For PRESERVE_ORDER, these are reset with every profile.
426 for (int i = 0; i < 3; ++i) { 488 uint32_t process_phase = 0;
427 SCOPED_TRACE("sample " + base::IntToString(i)); 489 uint32_t current_activities = 0;
490
491 ASSERT_EQ(static_cast<int>(arraysize(duplicate_counts)),
492 call_stack_profile.sample().size());
493 for (size_t i = 0, d = 0; i < arraysize(duplicate_counts);
494 d += duplicate_counts[i], ++i) {
495 // |d| is the index after compensating for duplicate compression.
496 SCOPED_TRACE("sample " + base::SizeTToString(i));
428 const CallStackProfile::Sample& proto_sample = 497 const CallStackProfile::Sample& proto_sample =
429 call_stack_profile.sample().Get(i); 498 call_stack_profile.sample().Get(i);
430 ASSERT_EQ(static_cast<int>(arraysize(sample_frames[i])), 499 ASSERT_EQ(static_cast<int>(arraysize(sample_frames[i])),
431 proto_sample.entry().size()); 500 proto_sample.entry().size());
432 ASSERT_TRUE(proto_sample.has_count()); 501 ASSERT_TRUE(proto_sample.has_count());
433 EXPECT_EQ(i == 2 ? 2u : 1u, proto_sample.count()); 502 EXPECT_EQ(duplicate_counts[i], proto_sample.count());
434 for (size_t j = 0; j < arraysize(sample_frames[i]); ++j) { 503 for (size_t j = 0; j < arraysize(sample_frames[d]); ++j) {
435 SCOPED_TRACE("frame " + base::SizeTToString(j)); 504 SCOPED_TRACE("frame " + base::SizeTToString(j));
436 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j); 505 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j);
437 ASSERT_TRUE(entry.has_address()); 506 ASSERT_TRUE(entry.has_address());
438 const char* instruction_pointer = reinterpret_cast<const char*>( 507 const char* instruction_pointer = reinterpret_cast<const char*>(
439 sample_frames[i][j].instruction_pointer); 508 sample_frames[d][j].instruction_pointer);
440 const char* module_base_address = reinterpret_cast<const char*>( 509 const char* module_base_address = reinterpret_cast<const char*>(
441 modules[sample_frames[i][j].module_index].base_address); 510 modules[sample_frames[d][j].module_index].base_address);
442 EXPECT_EQ( 511 EXPECT_EQ(
443 static_cast<uint64_t>(instruction_pointer - module_base_address), 512 static_cast<uint64_t>(instruction_pointer - module_base_address),
444 entry.address()); 513 entry.address());
445 ASSERT_TRUE(entry.has_module_id_index()); 514 ASSERT_TRUE(entry.has_module_id_index());
446 EXPECT_EQ(sample_frames[i][j].module_index, 515 EXPECT_EQ(sample_frames[d][j].module_index,
447 static_cast<size_t>(entry.module_id_index())); 516 static_cast<size_t>(entry.module_id_index()));
448 } 517 }
518
519 for (int x = 0; x < proto_sample.process_phase_size(); ++x) {
520 process_phase |= 1 << proto_sample.process_phase(x);
521 }
522 EXPECT_EQ(profile_phases_and_activities[d][0], process_phase);
523
524 for (int x = 0; x < proto_sample.activities_begun_size(); ++x) {
525 current_activities |= 1 << proto_sample.activities_begun(x);
526 }
527 for (int x = 0; x < proto_sample.activities_ended_size(); ++x) {
528 current_activities &= ~(1 << proto_sample.activities_ended(x));
529 }
530 EXPECT_EQ(profile_phases_and_activities[d][1], current_activities);
449 } 531 }
450 } 532 }
451 533
452 // Checks that unknown modules produce an empty Entry. 534 // Checks that unknown modules produce an empty Entry.
453 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { 535 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) {
454 const Frame frame(0x1000, Frame::kUnknownModuleIndex);
455
456 Profile profile; 536 Profile profile;
457 537 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
458 profile.samples.push_back(Sample(1, frame));
459
460 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 538 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
461 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 539 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
462 Profiles profiles; 540 Profiles profiles;
463 profiles.push_back(std::move(profile)); 541 profiles.push_back(std::move(profile));
464 542
465 CallStackProfileMetricsProvider provider; 543 CallStackProfileMetricsProvider provider;
466 provider.OnRecordingEnabled(); 544 provider.OnRecordingEnabled();
467 AppendProfiles( 545 AppendProfiles(
468 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 546 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
469 CallStackProfileParams::UI_THREAD, 547 CallStackProfileParams::UI_THREAD,
(...skipping 20 matching lines...) Expand all
490 EXPECT_FALSE(entry.has_module_id_index()); 568 EXPECT_FALSE(entry.has_module_id_index());
491 } 569 }
492 570
493 // Checks that pending profiles are only passed back to ProvideGeneralMetrics 571 // Checks that pending profiles are only passed back to ProvideGeneralMetrics
494 // once. 572 // once.
495 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { 573 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) {
496 CallStackProfileMetricsProvider provider; 574 CallStackProfileMetricsProvider provider;
497 for (int i = 0; i < 2; ++i) { 575 for (int i = 0; i < 2; ++i) {
498 Profile profile; 576 Profile profile;
499 profile.samples.push_back( 577 profile.samples.push_back(
500 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); 578 Sample((Frame(0x1000, Frame::kUnknownModuleIndex))));
501 579
502 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 580 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
503 // Use the sampling period to distinguish the two profiles. 581 // Use the sampling period to distinguish the two profiles.
504 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); 582 profile.sampling_period = base::TimeDelta::FromMilliseconds(i);
505 Profiles profiles; 583 Profiles profiles;
506 profiles.push_back(std::move(profile)); 584 profiles.push_back(std::move(profile));
507 585
508 provider.OnRecordingEnabled(); 586 provider.OnRecordingEnabled();
509 AppendProfiles( 587 AppendProfiles(
510 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 588 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
(...skipping 12 matching lines...) Expand all
523 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); 601 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms());
524 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); 602 EXPECT_EQ(i, call_stack_profile.sampling_period_ms());
525 } 603 }
526 } 604 }
527 605
528 // Checks that pending profiles are provided to ProvideGeneralMetrics 606 // Checks that pending profiles are provided to ProvideGeneralMetrics
529 // when collected before CallStackProfileMetricsProvider is instantiated. 607 // when collected before CallStackProfileMetricsProvider is instantiated.
530 TEST_F(CallStackProfileMetricsProviderTest, 608 TEST_F(CallStackProfileMetricsProviderTest,
531 ProfilesProvidedWhenCollectedBeforeInstantiation) { 609 ProfilesProvidedWhenCollectedBeforeInstantiation) {
532 Profile profile; 610 Profile profile;
533 profile.samples.push_back( 611 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
534 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
535
536 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 612 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
537 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 613 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
538 Profiles profiles; 614 Profiles profiles;
539 profiles.push_back(std::move(profile)); 615 profiles.push_back(std::move(profile));
540 616
541 AppendProfiles( 617 AppendProfiles(
542 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 618 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
543 CallStackProfileParams::UI_THREAD, 619 CallStackProfileParams::UI_THREAD,
544 CallStackProfileParams::PROCESS_STARTUP, 620 CallStackProfileParams::PROCESS_STARTUP,
545 CallStackProfileParams::MAY_SHUFFLE), 621 CallStackProfileParams::MAY_SHUFFLE),
546 std::move(profiles)); 622 std::move(profiles));
547 623
548 CallStackProfileMetricsProvider provider; 624 CallStackProfileMetricsProvider provider;
549 provider.OnRecordingEnabled(); 625 provider.OnRecordingEnabled();
550 ChromeUserMetricsExtension uma_proto; 626 ChromeUserMetricsExtension uma_proto;
551 provider.ProvideGeneralMetrics(&uma_proto); 627 provider.ProvideGeneralMetrics(&uma_proto);
552 628
553 EXPECT_EQ(1, uma_proto.sampled_profile_size()); 629 EXPECT_EQ(1, uma_proto.sampled_profile_size());
554 } 630 }
555 631
556 // Checks that pending profiles are not provided to ProvideGeneralMetrics 632 // Checks that pending profiles are not provided to ProvideGeneralMetrics
557 // while recording is disabled. 633 // while recording is disabled.
558 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { 634 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) {
559 Profile profile; 635 Profile profile;
560 profile.samples.push_back( 636 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
561 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
562
563 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 637 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
564 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 638 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
565 Profiles profiles; 639 Profiles profiles;
566 profiles.push_back(std::move(profile)); 640 profiles.push_back(std::move(profile));
567 641
568 CallStackProfileMetricsProvider provider; 642 CallStackProfileMetricsProvider provider;
569 provider.OnRecordingDisabled(); 643 provider.OnRecordingDisabled();
570 AppendProfiles( 644 AppendProfiles(
571 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 645 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
572 CallStackProfileParams::UI_THREAD, 646 CallStackProfileParams::UI_THREAD,
573 CallStackProfileParams::PROCESS_STARTUP, 647 CallStackProfileParams::PROCESS_STARTUP,
574 CallStackProfileParams::MAY_SHUFFLE), 648 CallStackProfileParams::MAY_SHUFFLE),
575 std::move(profiles)); 649 std::move(profiles));
576 ChromeUserMetricsExtension uma_proto; 650 ChromeUserMetricsExtension uma_proto;
577 provider.ProvideGeneralMetrics(&uma_proto); 651 provider.ProvideGeneralMetrics(&uma_proto);
578 652
579 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 653 EXPECT_EQ(0, uma_proto.sampled_profile_size());
580 } 654 }
581 655
582 // Checks that pending profiles are not provided to ProvideGeneralMetrics 656 // Checks that pending profiles are not provided to ProvideGeneralMetrics
583 // if recording is disabled while profiling. 657 // if recording is disabled while profiling.
584 TEST_F(CallStackProfileMetricsProviderTest, 658 TEST_F(CallStackProfileMetricsProviderTest,
585 ProfilesNotProvidedAfterChangeToDisabled) { 659 ProfilesNotProvidedAfterChangeToDisabled) {
586 Profile profile; 660 Profile profile;
587 profile.samples.push_back( 661 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
588 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
589
590 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 662 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
591 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 663 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
592 664
593 CallStackProfileMetricsProvider provider; 665 CallStackProfileMetricsProvider provider;
594 provider.OnRecordingEnabled(); 666 provider.OnRecordingEnabled();
595 base::StackSamplingProfiler::CompletedCallback callback = 667 base::StackSamplingProfiler::CompletedCallback callback =
596 CallStackProfileMetricsProvider::GetProfilerCallback( 668 CallStackProfileMetricsProvider::GetProfilerCallback(
597 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 669 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
598 CallStackProfileParams::UI_THREAD, 670 CallStackProfileParams::UI_THREAD,
599 CallStackProfileParams::PROCESS_STARTUP, 671 CallStackProfileParams::PROCESS_STARTUP,
600 CallStackProfileParams::MAY_SHUFFLE)); 672 CallStackProfileParams::MAY_SHUFFLE));
601 673
602 provider.OnRecordingDisabled(); 674 provider.OnRecordingDisabled();
603 Profiles profiles; 675 Profiles profiles;
604 profiles.push_back(std::move(profile)); 676 profiles.push_back(std::move(profile));
605 callback.Run(std::move(profiles)); 677 callback.Run(std::move(profiles));
606 ChromeUserMetricsExtension uma_proto; 678 ChromeUserMetricsExtension uma_proto;
607 provider.ProvideGeneralMetrics(&uma_proto); 679 provider.ProvideGeneralMetrics(&uma_proto);
608 680
609 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 681 EXPECT_EQ(0, uma_proto.sampled_profile_size());
610 } 682 }
611 683
612 // Checks that pending profiles are not provided to ProvideGeneralMetrics if 684 // Checks that pending profiles are not provided to ProvideGeneralMetrics if
613 // recording is enabled, but then disabled and reenabled while profiling. 685 // recording is enabled, but then disabled and reenabled while profiling.
614 TEST_F(CallStackProfileMetricsProviderTest, 686 TEST_F(CallStackProfileMetricsProviderTest,
615 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { 687 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) {
616 Profile profile; 688 Profile profile;
617 profile.samples.push_back( 689 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
618 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
619
620 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 690 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
621 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 691 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
622 692
623 CallStackProfileMetricsProvider provider; 693 CallStackProfileMetricsProvider provider;
624 provider.OnRecordingEnabled(); 694 provider.OnRecordingEnabled();
625 base::StackSamplingProfiler::CompletedCallback callback = 695 base::StackSamplingProfiler::CompletedCallback callback =
626 CallStackProfileMetricsProvider::GetProfilerCallback( 696 CallStackProfileMetricsProvider::GetProfilerCallback(
627 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 697 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
628 CallStackProfileParams::UI_THREAD, 698 CallStackProfileParams::UI_THREAD,
629 CallStackProfileParams::PROCESS_STARTUP, 699 CallStackProfileParams::PROCESS_STARTUP,
630 CallStackProfileParams::MAY_SHUFFLE)); 700 CallStackProfileParams::MAY_SHUFFLE));
631 701
632 provider.OnRecordingDisabled(); 702 provider.OnRecordingDisabled();
633 provider.OnRecordingEnabled(); 703 provider.OnRecordingEnabled();
634 Profiles profiles; 704 Profiles profiles;
635 profiles.push_back(std::move(profile)); 705 profiles.push_back(std::move(profile));
636 callback.Run(std::move(profiles)); 706 callback.Run(std::move(profiles));
637 ChromeUserMetricsExtension uma_proto; 707 ChromeUserMetricsExtension uma_proto;
638 provider.ProvideGeneralMetrics(&uma_proto); 708 provider.ProvideGeneralMetrics(&uma_proto);
639 709
640 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 710 EXPECT_EQ(0, uma_proto.sampled_profile_size());
641 } 711 }
642 712
643 // Checks that pending profiles are not provided to ProvideGeneralMetrics 713 // Checks that pending profiles are not provided to ProvideGeneralMetrics
644 // if recording is disabled, but then enabled while profiling. 714 // if recording is disabled, but then enabled while profiling.
645 TEST_F(CallStackProfileMetricsProviderTest, 715 TEST_F(CallStackProfileMetricsProviderTest,
646 ProfilesNotProvidedAfterChangeFromDisabled) { 716 ProfilesNotProvidedAfterChangeFromDisabled) {
647 Profile profile; 717 Profile profile;
648 profile.samples.push_back( 718 profile.samples.push_back(Sample(Frame(0x1000, Frame::kUnknownModuleIndex)));
649 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex)));
650
651 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 719 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
652 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 720 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
653 721
654 CallStackProfileMetricsProvider provider; 722 CallStackProfileMetricsProvider provider;
655 provider.OnRecordingDisabled(); 723 provider.OnRecordingDisabled();
656 base::StackSamplingProfiler::CompletedCallback callback = 724 base::StackSamplingProfiler::CompletedCallback callback =
657 CallStackProfileMetricsProvider::GetProfilerCallback( 725 CallStackProfileMetricsProvider::GetProfilerCallback(
658 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, 726 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS,
659 CallStackProfileParams::UI_THREAD, 727 CallStackProfileParams::UI_THREAD,
660 CallStackProfileParams::PROCESS_STARTUP, 728 CallStackProfileParams::PROCESS_STARTUP,
661 CallStackProfileParams::MAY_SHUFFLE)); 729 CallStackProfileParams::MAY_SHUFFLE));
662 730
663 provider.OnRecordingEnabled(); 731 provider.OnRecordingEnabled();
664 Profiles profiles; 732 Profiles profiles;
665 profiles.push_back(std::move(profile)); 733 profiles.push_back(std::move(profile));
666 callback.Run(std::move(profiles)); 734 callback.Run(std::move(profiles));
667 ChromeUserMetricsExtension uma_proto; 735 ChromeUserMetricsExtension uma_proto;
668 provider.ProvideGeneralMetrics(&uma_proto); 736 provider.ProvideGeneralMetrics(&uma_proto);
669 737
670 EXPECT_EQ(0, uma_proto.sampled_profile_size()); 738 EXPECT_EQ(0, uma_proto.sampled_profile_size());
671 } 739 }
672 740
673 } // namespace metrics 741 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/call_stack_profile_metrics_provider.cc ('k') | components/metrics/proto/call_stack_profile.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698