OLD | NEW |
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/profiler/stack_sampling_profiler.h" | 7 #include "base/profiler/stack_sampling_profiler.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 9 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using base::StackSamplingProfiler; | 12 using base::StackSamplingProfiler; |
13 using Frame = StackSamplingProfiler::Frame; | 13 using Frame = StackSamplingProfiler::Frame; |
14 using Module = StackSamplingProfiler::Module; | 14 using Module = StackSamplingProfiler::Module; |
15 using Profile = StackSamplingProfiler::Profile; | 15 using Profile = StackSamplingProfiler::CallStackProfile; |
16 using Sample = StackSamplingProfiler::Sample; | 16 using Sample = StackSamplingProfiler::Sample; |
17 | 17 |
18 namespace metrics { | 18 namespace metrics { |
19 | 19 |
20 // Checks that all properties from multiple profiles are filled as expected. | 20 // Checks that all properties from multiple profiles are filled as expected. |
21 TEST(CallStackProfileMetricsProviderTest, MultipleProfiles) { | 21 TEST(CallStackProfileMetricsProviderTest, MultipleProfiles) { |
22 const uintptr_t module1_base_address = 0x1000; | 22 const uintptr_t module1_base_address = 0x1000; |
23 const uintptr_t module2_base_address = 0x2000; | 23 const uintptr_t module2_base_address = 0x2000; |
24 const uintptr_t module3_base_address = 0x3000; | 24 const uintptr_t module3_base_address = 0x3000; |
25 | 25 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 entry.address()); | 375 entry.address()); |
376 ASSERT_TRUE(entry.has_module_id_index()); | 376 ASSERT_TRUE(entry.has_module_id_index()); |
377 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); | 377 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); |
378 } | 378 } |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 | 382 |
383 // Checks that unknown modules produce an empty Entry. | 383 // Checks that unknown modules produce an empty Entry. |
384 TEST(CallStackProfileMetricsProviderTest, UnknownModule) { | 384 TEST(CallStackProfileMetricsProviderTest, UnknownModule) { |
385 // -1 indicates an unknown module. | 385 const Frame frame(reinterpret_cast<const void*>(0x1000), |
386 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); | 386 Frame::kUnknownModuleIndex); |
387 | 387 |
388 Profile profile; | 388 Profile profile; |
389 | 389 |
390 profile.samples.push_back(Sample(1, frame)); | 390 profile.samples.push_back(Sample(1, frame)); |
391 | 391 |
392 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 392 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
393 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 393 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
394 profile.preserve_sample_ordering = false; | 394 profile.preserve_sample_ordering = false; |
395 | 395 |
396 CallStackProfileMetricsProvider provider; | 396 CallStackProfileMetricsProvider provider; |
(...skipping 12 matching lines...) Expand all Loading... |
409 call_stack_profile.sample().Get(0); | 409 call_stack_profile.sample().Get(0); |
410 ASSERT_EQ(1, proto_sample.entry().size()); | 410 ASSERT_EQ(1, proto_sample.entry().size()); |
411 ASSERT_TRUE(proto_sample.has_count()); | 411 ASSERT_TRUE(proto_sample.has_count()); |
412 EXPECT_EQ(1u, proto_sample.count()); | 412 EXPECT_EQ(1u, proto_sample.count()); |
413 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); | 413 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); |
414 EXPECT_FALSE(entry.has_address()); | 414 EXPECT_FALSE(entry.has_address()); |
415 EXPECT_FALSE(entry.has_module_id_index()); | 415 EXPECT_FALSE(entry.has_module_id_index()); |
416 } | 416 } |
417 | 417 |
418 } // namespace metrics | 418 } // namespace metrics |
OLD | NEW |