Chromium Code Reviews| 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/metrics/field_trial.h" | |
| 7 #include "base/profiler/stack_sampling_profiler.h" | 8 #include "base/profiler/stack_sampling_profiler.h" |
| 8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 9 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 10 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 11 #include "components/variations/entropy_provider.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 using base::StackSamplingProfiler; | 14 using base::StackSamplingProfiler; |
| 13 using Frame = StackSamplingProfiler::Frame; | 15 using Frame = StackSamplingProfiler::Frame; |
| 14 using Module = StackSamplingProfiler::Module; | 16 using Module = StackSamplingProfiler::Module; |
| 15 using Profile = StackSamplingProfiler::Profile; | 17 using Profile = StackSamplingProfiler::Profile; |
| 16 using Sample = StackSamplingProfiler::Sample; | 18 using Sample = StackSamplingProfiler::Sample; |
| 17 | 19 |
| 18 namespace metrics { | 20 namespace metrics { |
| 19 | 21 |
| 22 namespace { | |
| 23 | |
| 24 // This test fixture enables the field trial that | |
| 25 // CallStackProfileMetricsProvider depends on to report profiles. | |
| 26 class CallStackProfileMetricsProviderTest : public testing::Test { | |
|
Ilya Sherman
2015/03/24 21:07:55
nit: I believe that test fixtures are supposed to
Mike Wittman
2015/03/24 22:40:59
Yes, that sounds familiar.
| |
| 27 public: | |
| 28 CallStackProfileMetricsProviderTest() {} | |
| 29 ~CallStackProfileMetricsProviderTest() {} | |
| 30 | |
| 31 void SetUp() override { | |
| 32 field_trial_list_.reset(new base::FieldTrialList( | |
| 33 new metrics::SHA1EntropyProvider("foo"))); | |
| 34 base::FieldTrialList::CreateFieldTrial( | |
| 35 FieldTrialState::kFieldTrialName, | |
| 36 FieldTrialState::kReportProfilesGroupName); | |
| 37 } | |
| 38 | |
| 39 void TearDown() override { | |
| 40 field_trial_list_.reset(); | |
|
Ilya Sherman
2015/03/24 21:07:55
nit: No need to call this explicitly, unless it ne
Mike Wittman
2015/03/24 22:40:59
Removed. Also moved the SetUp contents into the co
| |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 // Exposes field trial/group names from the CallStackProfileMetricsProvider. | |
| 45 class FieldTrialState : public CallStackProfileMetricsProvider { | |
| 46 public: | |
| 47 using CallStackProfileMetricsProvider::kFieldTrialName; | |
| 48 using CallStackProfileMetricsProvider::kReportProfilesGroupName; | |
| 49 }; | |
| 50 | |
| 51 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 52 }; | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 20 // Checks that all properties from multiple profiles are filled as expected. | 56 // Checks that all properties from multiple profiles are filled as expected. |
| 21 TEST(CallStackProfileMetricsProviderTest, MultipleProfiles) { | 57 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { |
| 22 const uintptr_t module1_base_address = 0x1000; | 58 const uintptr_t module1_base_address = 0x1000; |
| 23 const uintptr_t module2_base_address = 0x2000; | 59 const uintptr_t module2_base_address = 0x2000; |
| 24 const uintptr_t module3_base_address = 0x3000; | 60 const uintptr_t module3_base_address = 0x3000; |
| 25 | 61 |
| 26 const Module profile_modules[][2] = { | 62 const Module profile_modules[][2] = { |
| 27 { | 63 { |
| 28 Module( | 64 Module( |
| 29 reinterpret_cast<const void*>(module1_base_address), | 65 reinterpret_cast<const void*>(module1_base_address), |
| 30 "ABCD", | 66 "ABCD", |
| 31 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 EXPECT_EQ(profile_durations[i].InMilliseconds(), | 258 EXPECT_EQ(profile_durations[i].InMilliseconds(), |
| 223 call_stack_profile.profile_duration_ms()); | 259 call_stack_profile.profile_duration_ms()); |
| 224 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 260 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
| 225 EXPECT_EQ(profile_sampling_periods[i].InMilliseconds(), | 261 EXPECT_EQ(profile_sampling_periods[i].InMilliseconds(), |
| 226 call_stack_profile.sampling_period_ms()); | 262 call_stack_profile.sampling_period_ms()); |
| 227 } | 263 } |
| 228 } | 264 } |
| 229 | 265 |
| 230 // Checks that all duplicate samples are collapsed with | 266 // Checks that all duplicate samples are collapsed with |
| 231 // preserve_sample_ordering = false. | 267 // preserve_sample_ordering = false. |
| 232 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { | 268 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { |
| 233 const uintptr_t module_base_address = 0x1000; | 269 const uintptr_t module_base_address = 0x1000; |
| 234 | 270 |
| 235 const Module modules[] = { | 271 const Module modules[] = { |
| 236 Module( | 272 Module( |
| 237 reinterpret_cast<const void*>(module_base_address), | 273 reinterpret_cast<const void*>(module_base_address), |
| 238 "ABCD", | 274 "ABCD", |
| 239 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 240 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 276 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
| 241 #else | 277 #else |
| 242 base::FilePath("/some/path/to/chrome") | 278 base::FilePath("/some/path/to/chrome") |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), | 334 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), |
| 299 entry.address()); | 335 entry.address()); |
| 300 ASSERT_TRUE(entry.has_module_id_index()); | 336 ASSERT_TRUE(entry.has_module_id_index()); |
| 301 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); | 337 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); |
| 302 } | 338 } |
| 303 } | 339 } |
| 304 } | 340 } |
| 305 | 341 |
| 306 // Checks that only contiguous duplicate samples are collapsed with | 342 // Checks that only contiguous duplicate samples are collapsed with |
| 307 // preserve_sample_ordering = true. | 343 // preserve_sample_ordering = true. |
| 308 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { | 344 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { |
| 309 const uintptr_t module_base_address = 0x1000; | 345 const uintptr_t module_base_address = 0x1000; |
| 310 | 346 |
| 311 const Module modules[] = { | 347 const Module modules[] = { |
| 312 Module( | 348 Module( |
| 313 reinterpret_cast<const void*>(module_base_address), | 349 reinterpret_cast<const void*>(module_base_address), |
| 314 "ABCD", | 350 "ABCD", |
| 315 #if defined(OS_WIN) | 351 #if defined(OS_WIN) |
| 316 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 352 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
| 317 #else | 353 #else |
| 318 base::FilePath("/some/path/to/chrome") | 354 base::FilePath("/some/path/to/chrome") |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), | 410 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), |
| 375 entry.address()); | 411 entry.address()); |
| 376 ASSERT_TRUE(entry.has_module_id_index()); | 412 ASSERT_TRUE(entry.has_module_id_index()); |
| 377 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); | 413 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); |
| 378 } | 414 } |
| 379 } | 415 } |
| 380 } | 416 } |
| 381 | 417 |
| 382 | 418 |
| 383 // Checks that unknown modules produce an empty Entry. | 419 // Checks that unknown modules produce an empty Entry. |
| 384 TEST(CallStackProfileMetricsProviderTest, UnknownModule) { | 420 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { |
| 385 // -1 indicates an unknown module. | 421 // -1 indicates an unknown module. |
| 386 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); | 422 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); |
| 387 | 423 |
| 388 Profile profile; | 424 Profile profile; |
| 389 | 425 |
| 390 profile.samples.push_back(Sample(1, frame)); | 426 profile.samples.push_back(Sample(1, frame)); |
| 391 | 427 |
| 392 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 428 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 393 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 429 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 394 profile.preserve_sample_ordering = false; | 430 profile.preserve_sample_ordering = false; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 409 call_stack_profile.sample().Get(0); | 445 call_stack_profile.sample().Get(0); |
| 410 ASSERT_EQ(1, proto_sample.entry().size()); | 446 ASSERT_EQ(1, proto_sample.entry().size()); |
| 411 ASSERT_TRUE(proto_sample.has_count()); | 447 ASSERT_TRUE(proto_sample.has_count()); |
| 412 EXPECT_EQ(1u, proto_sample.count()); | 448 EXPECT_EQ(1u, proto_sample.count()); |
| 413 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); | 449 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); |
| 414 EXPECT_FALSE(entry.has_address()); | 450 EXPECT_FALSE(entry.has_address()); |
| 415 EXPECT_FALSE(entry.has_module_id_index()); | 451 EXPECT_FALSE(entry.has_module_id_index()); |
| 416 } | 452 } |
| 417 | 453 |
| 418 } // namespace metrics | 454 } // namespace metrics |
| OLD | NEW |