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

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

Issue 1030923002: StackSamplingProfiler clean up (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: address comments 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
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 <cstring> 7 #include <cstring>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 24 matching lines...) Expand all
35 // compute module instruction pointer offsets. 35 // compute module instruction pointer offsets.
36 void CopySampleToProto( 36 void CopySampleToProto(
37 const StackSamplingProfiler::Sample& sample, 37 const StackSamplingProfiler::Sample& sample,
38 const std::vector<StackSamplingProfiler::Module>& modules, 38 const std::vector<StackSamplingProfiler::Module>& modules,
39 CallStackProfile::Sample* proto_sample) { 39 CallStackProfile::Sample* proto_sample) {
40 for (const StackSamplingProfiler::Frame& frame : sample) { 40 for (const StackSamplingProfiler::Frame& frame : sample) {
41 CallStackProfile::Entry* entry = proto_sample->add_entry(); 41 CallStackProfile::Entry* entry = proto_sample->add_entry();
42 // A frame may not have a valid module. If so, we can't compute the 42 // A frame may not have a valid module. If so, we can't compute the
43 // instruction pointer offset, and we don't want to send bare pointers, so 43 // instruction pointer offset, and we don't want to send bare pointers, so
44 // leave call_stack_entry empty. 44 // leave call_stack_entry empty.
45 if (frame.module_index < 0) 45 if (frame.module_index == StackSamplingProfiler::Frame::kUnknownModuleIndex)
46 continue; 46 continue;
47 int64 module_offset = 47 int64 module_offset =
48 reinterpret_cast<const char*>(frame.instruction_pointer) - 48 reinterpret_cast<const char*>(frame.instruction_pointer) -
49 reinterpret_cast<const char*>(modules[frame.module_index].base_address); 49 reinterpret_cast<const char*>(modules[frame.module_index].base_address);
50 DCHECK_GE(module_offset, 0); 50 DCHECK_GE(module_offset, 0);
51 entry->set_address(static_cast<uint64>(module_offset)); 51 entry->set_address(static_cast<uint64>(module_offset));
52 entry->set_module_id_index(frame.module_index); 52 entry->set_module_id_index(frame.module_index);
53 } 53 }
54 } 54 }
55 55
56 // Transcode |profile| into |proto_profile|. 56 // Transcode |profile| into |proto_profile|.
57 void CopyProfileToProto( 57 void CopyProfileToProto(
58 const StackSamplingProfiler::Profile& profile, 58 const StackSamplingProfiler::CallStackProfile& profile,
59 CallStackProfile* proto_profile) { 59 CallStackProfile* proto_profile) {
60 if (profile.samples.empty()) 60 if (profile.samples.empty())
61 return; 61 return;
62 62
63 if (profile.preserve_sample_ordering) { 63 if (profile.preserve_sample_ordering) {
64 // Collapse only consecutive repeated samples together. 64 // Collapse only consecutive repeated samples together.
65 CallStackProfile::Sample* current_sample_proto = nullptr; 65 CallStackProfile::Sample* current_sample_proto = nullptr;
66 for (auto it = profile.samples.begin(); it != profile.samples.end(); ++it) { 66 for (auto it = profile.samples.begin(); it != profile.samples.end(); ++it) {
67 if (!current_sample_proto || *it != *(it - 1)) { 67 if (!current_sample_proto || *it != *(it - 1)) {
68 current_sample_proto = proto_profile->add_sample(); 68 current_sample_proto = proto_profile->add_sample();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 profile.sampling_period.InMilliseconds()); 105 profile.sampling_period.InMilliseconds());
106 } 106 }
107 } // namespace 107 } // namespace
108 108
109 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() {} 109 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() {}
110 110
111 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() {} 111 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() {}
112 112
113 void CallStackProfileMetricsProvider::ProvideGeneralMetrics( 113 void CallStackProfileMetricsProvider::ProvideGeneralMetrics(
114 ChromeUserMetricsExtension* uma_proto) { 114 ChromeUserMetricsExtension* uma_proto) {
115 std::vector<StackSamplingProfiler::Profile> profiles; 115 std::vector<StackSamplingProfiler::CallStackProfile> profiles;
116 if (!source_profiles_for_test_.empty()) 116 if (!source_profiles_for_test_.empty())
117 profiles.swap(source_profiles_for_test_); 117 profiles.swap(source_profiles_for_test_);
118 else 118 else
119 StackSamplingProfiler::GetPendingProfiles(&profiles); 119 StackSamplingProfiler::GetPendingProfiles(&profiles);
120 120
121 for (const StackSamplingProfiler::Profile& profile : profiles) { 121 for (const StackSamplingProfiler::CallStackProfile& profile : profiles) {
122 CallStackProfile* call_stack_profile = 122 CallStackProfile* call_stack_profile =
123 uma_proto->add_sampled_profile()->mutable_call_stack_profile(); 123 uma_proto->add_sampled_profile()->mutable_call_stack_profile();
124 CopyProfileToProto(profile, call_stack_profile); 124 CopyProfileToProto(profile, call_stack_profile);
125 } 125 }
126 } 126 }
127 127
128 void CallStackProfileMetricsProvider::SetSourceProfilesForTesting( 128 void CallStackProfileMetricsProvider::SetSourceProfilesForTesting(
129 const std::vector<StackSamplingProfiler::Profile>& profiles) { 129 const std::vector<StackSamplingProfiler::CallStackProfile>& profiles) {
130 source_profiles_for_test_ = profiles; 130 source_profiles_for_test_ = profiles;
131 } 131 }
132 132
133 } // namespace metrics 133 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698