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

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

Issue 1030923002: StackSamplingProfiler clean up (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: add comment on priority boost Created 5 years, 8 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 | « components/metrics/call_stack_profile_metrics_provider.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/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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ASSERT_TRUE(entry.has_address()); 194 ASSERT_TRUE(entry.has_address());
195 const char* instruction_pointer = reinterpret_cast<const char*>( 195 const char* instruction_pointer = reinterpret_cast<const char*>(
196 profile_sample_frames[i][j][k].instruction_pointer); 196 profile_sample_frames[i][j][k].instruction_pointer);
197 const char* module_base_address = reinterpret_cast<const char*>( 197 const char* module_base_address = reinterpret_cast<const char*>(
198 profile_modules[i][profile_sample_frames[i][j][k].module_index] 198 profile_modules[i][profile_sample_frames[i][j][k].module_index]
199 .base_address); 199 .base_address);
200 EXPECT_EQ(static_cast<uint64>(instruction_pointer - 200 EXPECT_EQ(static_cast<uint64>(instruction_pointer -
201 module_base_address), entry.address()); 201 module_base_address), entry.address());
202 ASSERT_TRUE(entry.has_module_id_index()); 202 ASSERT_TRUE(entry.has_module_id_index());
203 EXPECT_EQ(profile_sample_frames[i][j][k].module_index, 203 EXPECT_EQ(profile_sample_frames[i][j][k].module_index,
204 entry.module_id_index()); 204 static_cast<size_t>(entry.module_id_index()));
205 } 205 }
206 } 206 }
207 207
208 ASSERT_EQ(static_cast<int>(arraysize(profile_modules[i])), 208 ASSERT_EQ(static_cast<int>(arraysize(profile_modules[i])),
209 call_stack_profile.module_id().size()); 209 call_stack_profile.module_id().size());
210 for (size_t j = 0; j < arraysize(profile_modules[i]); ++j) { 210 for (size_t j = 0; j < arraysize(profile_modules[i]); ++j) {
211 SCOPED_TRACE("module " + base::IntToString(j)); 211 SCOPED_TRACE("module " + base::IntToString(j));
212 const CallStackProfile::ModuleIdentifier& module_identifier = 212 const CallStackProfile::ModuleIdentifier& module_identifier =
213 call_stack_profile.module_id().Get(j); 213 call_stack_profile.module_id().Get(j);
214 ASSERT_TRUE(module_identifier.has_build_id()); 214 ASSERT_TRUE(module_identifier.has_build_id());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 SCOPED_TRACE("frame " + base::IntToString(j)); 291 SCOPED_TRACE("frame " + base::IntToString(j));
292 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j); 292 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j);
293 ASSERT_TRUE(entry.has_address()); 293 ASSERT_TRUE(entry.has_address());
294 const char* instruction_pointer = reinterpret_cast<const char*>( 294 const char* instruction_pointer = reinterpret_cast<const char*>(
295 sample_frames[i][j].instruction_pointer); 295 sample_frames[i][j].instruction_pointer);
296 const char* module_base_address = reinterpret_cast<const char*>( 296 const char* module_base_address = reinterpret_cast<const char*>(
297 modules[sample_frames[i][j].module_index].base_address); 297 modules[sample_frames[i][j].module_index].base_address);
298 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), 298 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address),
299 entry.address()); 299 entry.address());
300 ASSERT_TRUE(entry.has_module_id_index()); 300 ASSERT_TRUE(entry.has_module_id_index());
301 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); 301 EXPECT_EQ(sample_frames[i][j].module_index,
302 static_cast<size_t>(entry.module_id_index()));
302 } 303 }
303 } 304 }
304 } 305 }
305 306
306 // Checks that only contiguous duplicate samples are collapsed with 307 // Checks that only contiguous duplicate samples are collapsed with
307 // preserve_sample_ordering = true. 308 // preserve_sample_ordering = true.
308 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { 309 TEST(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) {
309 const uintptr_t module_base_address = 0x1000; 310 const uintptr_t module_base_address = 0x1000;
310 311
311 const Module modules[] = { 312 const Module modules[] = {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 SCOPED_TRACE("frame " + base::IntToString(j)); 368 SCOPED_TRACE("frame " + base::IntToString(j));
368 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j); 369 const CallStackProfile::Entry& entry = proto_sample.entry().Get(j);
369 ASSERT_TRUE(entry.has_address()); 370 ASSERT_TRUE(entry.has_address());
370 const char* instruction_pointer = reinterpret_cast<const char*>( 371 const char* instruction_pointer = reinterpret_cast<const char*>(
371 sample_frames[i][j].instruction_pointer); 372 sample_frames[i][j].instruction_pointer);
372 const char* module_base_address = reinterpret_cast<const char*>( 373 const char* module_base_address = reinterpret_cast<const char*>(
373 modules[sample_frames[i][j].module_index].base_address); 374 modules[sample_frames[i][j].module_index].base_address);
374 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address), 375 EXPECT_EQ(static_cast<uint64>(instruction_pointer - module_base_address),
375 entry.address()); 376 entry.address());
376 ASSERT_TRUE(entry.has_module_id_index()); 377 ASSERT_TRUE(entry.has_module_id_index());
377 EXPECT_EQ(sample_frames[i][j].module_index, entry.module_id_index()); 378 EXPECT_EQ(sample_frames[i][j].module_index,
379 static_cast<size_t>(entry.module_id_index()));
378 } 380 }
379 } 381 }
380 } 382 }
381 383
382 384
383 // Checks that unknown modules produce an empty Entry. 385 // Checks that unknown modules produce an empty Entry.
384 TEST(CallStackProfileMetricsProviderTest, UnknownModule) { 386 TEST(CallStackProfileMetricsProviderTest, UnknownModule) {
385 // -1 indicates an unknown module. 387 const Frame frame(reinterpret_cast<const void*>(0x1000),
386 const Frame frame(reinterpret_cast<const void*>(0x1000), -1); 388 Frame::kUnknownModuleIndex);
387 389
388 Profile profile; 390 Profile profile;
389 391
390 profile.samples.push_back(Sample(1, frame)); 392 profile.samples.push_back(Sample(1, frame));
391 393
392 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); 394 profile.profile_duration = base::TimeDelta::FromMilliseconds(100);
393 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); 395 profile.sampling_period = base::TimeDelta::FromMilliseconds(10);
394 profile.preserve_sample_ordering = false; 396 profile.preserve_sample_ordering = false;
395 397
396 CallStackProfileMetricsProvider provider; 398 CallStackProfileMetricsProvider provider;
(...skipping 12 matching lines...) Expand all
409 call_stack_profile.sample().Get(0); 411 call_stack_profile.sample().Get(0);
410 ASSERT_EQ(1, proto_sample.entry().size()); 412 ASSERT_EQ(1, proto_sample.entry().size());
411 ASSERT_TRUE(proto_sample.has_count()); 413 ASSERT_TRUE(proto_sample.has_count());
412 EXPECT_EQ(1u, proto_sample.count()); 414 EXPECT_EQ(1u, proto_sample.count());
413 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0); 415 const CallStackProfile::Entry& entry = proto_sample.entry().Get(0);
414 EXPECT_FALSE(entry.has_address()); 416 EXPECT_FALSE(entry.has_address());
415 EXPECT_FALSE(entry.has_module_id_index()); 417 EXPECT_FALSE(entry.has_module_id_index());
416 } 418 }
417 419
418 } // namespace metrics 420 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/call_stack_profile_metrics_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698