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 { | |
|
Ilya Sherman
2015/03/24 04:02:03
nit: Please leave a blank line here.
Mike Wittman
2015/03/24 18:37:39
Done.
| |
| 23 class CallStackProfileMetricsProviderTest : public testing::Test { | |
| 24 public: | |
| 25 CallStackProfileMetricsProviderTest() {} | |
| 26 ~CallStackProfileMetricsProviderTest() {} | |
| 27 | |
| 28 void SetUp() override { | |
| 29 field_trial_list_.reset(new base::FieldTrialList( | |
| 30 new metrics::SHA1EntropyProvider("foo"))); | |
| 31 base::FieldTrialList::CreateFieldTrial( | |
| 32 CallStackProfileMetricsProvider::kFieldTrialName, | |
| 33 CallStackProfileMetricsProvider::kReportProfilesGroupName); | |
| 34 } | |
| 35 | |
| 36 void TearDown() override { | |
| 37 field_trial_list_.reset(); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 42 }; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 20 // Checks that all properties from multiple profiles are filled as expected. | 46 // Checks that all properties from multiple profiles are filled as expected. |
| 21 TEST(CallStackProfileMetricsProviderTest, MultipleProfiles) { | 47 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { |
| 22 const uintptr_t module1_base_address = 0x1000; | 48 const uintptr_t module1_base_address = 0x1000; |
| 23 const uintptr_t module2_base_address = 0x2000; | 49 const uintptr_t module2_base_address = 0x2000; |
| 24 const uintptr_t module3_base_address = 0x3000; | 50 const uintptr_t module3_base_address = 0x3000; |
| 25 | 51 |
| 26 const Module profile_modules[][2] = { | 52 const Module profile_modules[][2] = { |
| 27 { | 53 { |
| 28 Module( | 54 Module( |
| 29 reinterpret_cast<const void*>(module1_base_address), | 55 reinterpret_cast<const void*>(module1_base_address), |
| 30 "ABCD", | 56 "ABCD", |
| 31 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 EXPECT_EQ(profile_durations[i].InMilliseconds(), | 248 EXPECT_EQ(profile_durations[i].InMilliseconds(), |
| 223 call_stack_profile.profile_duration_ms()); | 249 call_stack_profile.profile_duration_ms()); |
| 224 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 250 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
| 225 EXPECT_EQ(profile_sampling_periods[i].InMilliseconds(), | 251 EXPECT_EQ(profile_sampling_periods[i].InMilliseconds(), |
| 226 call_stack_profile.sampling_period_ms()); | 252 call_stack_profile.sampling_period_ms()); |
| 227 } | 253 } |
| 228 } | 254 } |
| 229 | 255 |
| 230 // Checks that all duplicate samples are collapsed with | 256 // Checks that all duplicate samples are collapsed with |
| 231 // preserve_sample_ordering = false. | 257 // preserve_sample_ordering = false. |
| 232 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { | 258 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { |
| 233 const uintptr_t module_base_address = 0x1000; | 259 const uintptr_t module_base_address = 0x1000; |
| 234 | 260 |
| 235 const Module modules[] = { | 261 const Module modules[] = { |
| 236 Module( | 262 Module( |
| 237 reinterpret_cast<const void*>(module_base_address), | 263 reinterpret_cast<const void*>(module_base_address), |
| 238 "ABCD", | 264 "ABCD", |
| 239 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
| 240 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 266 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
| 241 #else | 267 #else |
| 242 base::FilePath("/some/path/to/chrome") | 268 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), | 324 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), |
| 299 entry.address()); | 325 entry.address()); |
| 300 ASSERT_TRUE(entry.has_module_id_index()); | 326 ASSERT_TRUE(entry.has_module_id_index()); |
| 301 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); | 327 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); |
| 302 } | 328 } |
| 303 } | 329 } |
| 304 } | 330 } |
| 305 | 331 |
| 306 // Checks that only contiguous duplicate samples are collapsed with | 332 // Checks that only contiguous duplicate samples are collapsed with |
| 307 // preserve_sample_ordering = true. | 333 // preserve_sample_ordering = true. |
| 308 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { | 334 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { |
| 309 const uintptr_t module_base_address = 0x1000; | 335 const uintptr_t module_base_address = 0x1000; |
| 310 | 336 |
| 311 const Module modules[] = { | 337 const Module modules[] = { |
| 312 Module( | 338 Module( |
| 313 reinterpret_cast<const void*>(module_base_address), | 339 reinterpret_cast<const void*>(module_base_address), |
| 314 "ABCD", | 340 "ABCD", |
| 315 #if defined(OS_WIN) | 341 #if defined(OS_WIN) |
| 316 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 342 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
| 317 #else | 343 #else |
| 318 base::FilePath("/some/path/to/chrome") | 344 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), | 400 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), |
| 375 entry.address()); | 401 entry.address()); |
| 376 ASSERT_TRUE(entry.has_module_id_index()); | 402 ASSERT_TRUE(entry.has_module_id_index()); |
| 377 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); | 403 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); |
| 378 } | 404 } |
| 379 } | 405 } |
| 380 } | 406 } |
| 381 | 407 |
| 382 | 408 |
| 383 // Checks that unknown modules produce an empty Entry. | 409 // Checks that unknown modules produce an empty Entry. |
| 384 TEST(CallStackProfileMetricsProviderTest, UnknownModule) { | 410 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { |
| 385 // -1 indicates an unknown module. | 411 // -1 indicates an unknown module. |
| 386 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); | 412 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); |
| 387 | 413 |
| 388 Profile profile; | 414 Profile profile; |
| 389 | 415 |
| 390 profile.samples.push_back(Sample(1, frame)); | 416 profile.samples.push_back(Sample(1, frame)); |
| 391 | 417 |
| 392 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 418 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 393 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 419 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 394 profile.preserve_sample_ordering = false; | 420 profile.preserve_sample_ordering = false; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 409 call_stack_profile.sample().Get(0); | 435 call_stack_profile.sample().Get(0); |
| 410 ASSERT_EQ(1, proto_sample.entry().size()); | 436 ASSERT_EQ(1, proto_sample.entry().size()); |
| 411 ASSERT_TRUE(proto_sample.has_count()); | 437 ASSERT_TRUE(proto_sample.has_count()); |
| 412 EXPECT_EQ(1u, proto_sample.count()); | 438 EXPECT_EQ(1u, proto_sample.count()); |
| 413 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); | 439 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); |
| 414 EXPECT_FALSE(entry.has_address()); | 440 EXPECT_FALSE(entry.has_address()); |
| 415 EXPECT_FALSE(entry.has_module_id_index()); | 441 EXPECT_FALSE(entry.has_module_id_index()); |
| 416 } | 442 } |
| 417 | 443 |
| 418 } // namespace metrics | 444 } // namespace metrics |
| OLD | NEW |