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

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

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 <stddef.h>
8 #include <stdint.h>
9
7 #include <algorithm> 10 #include <algorithm>
8 #include <cstring> 11 #include <cstring>
9 #include <map> 12 #include <map>
10 #include <utility> 13 #include <utility>
11 #include <vector> 14 #include <vector>
12 15
13 #include "base/bind.h" 16 #include "base/bind.h"
14 #include "base/location.h" 17 #include "base/location.h"
15 #include "base/logging.h" 18 #include "base/logging.h"
16 #include "base/macros.h" 19 #include "base/macros.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 197 }
195 198
196 // Invoked on an arbitrary thread. Ignores the provided profiles. 199 // Invoked on an arbitrary thread. Ignores the provided profiles.
197 void IgnoreCompletedProfiles( 200 void IgnoreCompletedProfiles(
198 const StackSamplingProfiler::CallStackProfiles& profiles) { 201 const StackSamplingProfiler::CallStackProfiles& profiles) {
199 } 202 }
200 203
201 // Functions to encode protobufs ---------------------------------------------- 204 // Functions to encode protobufs ----------------------------------------------
202 205
203 // The protobuf expects the MD5 checksum prefix of the module name. 206 // The protobuf expects the MD5 checksum prefix of the module name.
204 uint64 HashModuleFilename(const base::FilePath& filename) { 207 uint64_t HashModuleFilename(const base::FilePath& filename) {
205 const base::FilePath::StringType basename = filename.BaseName().value(); 208 const base::FilePath::StringType basename = filename.BaseName().value();
206 // Copy the bytes in basename into a string buffer. 209 // Copy the bytes in basename into a string buffer.
207 size_t basename_length_in_bytes = 210 size_t basename_length_in_bytes =
208 basename.size() * sizeof(base::FilePath::CharType); 211 basename.size() * sizeof(base::FilePath::CharType);
209 std::string name_bytes(basename_length_in_bytes, '\0'); 212 std::string name_bytes(basename_length_in_bytes, '\0');
210 memcpy(&name_bytes[0], &basename[0], basename_length_in_bytes); 213 memcpy(&name_bytes[0], &basename[0], basename_length_in_bytes);
211 return base::HashMetricName(name_bytes); 214 return base::HashMetricName(name_bytes);
212 } 215 }
213 216
214 // Transcode |sample| into |proto_sample|, using base addresses in |modules| to 217 // Transcode |sample| into |proto_sample|, using base addresses in |modules| to
215 // compute module instruction pointer offsets. 218 // compute module instruction pointer offsets.
216 void CopySampleToProto( 219 void CopySampleToProto(
217 const StackSamplingProfiler::Sample& sample, 220 const StackSamplingProfiler::Sample& sample,
218 const std::vector<StackSamplingProfiler::Module>& modules, 221 const std::vector<StackSamplingProfiler::Module>& modules,
219 CallStackProfile::Sample* proto_sample) { 222 CallStackProfile::Sample* proto_sample) {
220 for (const StackSamplingProfiler::Frame& frame : sample) { 223 for (const StackSamplingProfiler::Frame& frame : sample) {
221 CallStackProfile::Entry* entry = proto_sample->add_entry(); 224 CallStackProfile::Entry* entry = proto_sample->add_entry();
222 // A frame may not have a valid module. If so, we can't compute the 225 // A frame may not have a valid module. If so, we can't compute the
223 // instruction pointer offset, and we don't want to send bare pointers, so 226 // instruction pointer offset, and we don't want to send bare pointers, so
224 // leave call_stack_entry empty. 227 // leave call_stack_entry empty.
225 if (frame.module_index == StackSamplingProfiler::Frame::kUnknownModuleIndex) 228 if (frame.module_index == StackSamplingProfiler::Frame::kUnknownModuleIndex)
226 continue; 229 continue;
227 int64 module_offset = 230 int64_t module_offset =
228 reinterpret_cast<const char*>(frame.instruction_pointer) - 231 reinterpret_cast<const char*>(frame.instruction_pointer) -
229 reinterpret_cast<const char*>(modules[frame.module_index].base_address); 232 reinterpret_cast<const char*>(modules[frame.module_index].base_address);
230 DCHECK_GE(module_offset, 0); 233 DCHECK_GE(module_offset, 0);
231 entry->set_address(static_cast<uint64>(module_offset)); 234 entry->set_address(static_cast<uint64_t>(module_offset));
232 entry->set_module_id_index(frame.module_index); 235 entry->set_module_id_index(frame.module_index);
233 } 236 }
234 } 237 }
235 238
236 // Transcode |profile| into |proto_profile|. 239 // Transcode |profile| into |proto_profile|.
237 void CopyProfileToProto( 240 void CopyProfileToProto(
238 const StackSamplingProfiler::CallStackProfile& profile, 241 const StackSamplingProfiler::CallStackProfile& profile,
239 bool preserve_sample_ordering, 242 bool preserve_sample_ordering,
240 CallStackProfile* proto_profile) { 243 CallStackProfile* proto_profile) {
241 if (profile.samples.empty()) 244 if (profile.samples.empty())
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 387
385 // static 388 // static
386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { 389 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() {
387 const std::string group_name = base::FieldTrialList::FindFullName( 390 const std::string group_name = base::FieldTrialList::FindFullName(
388 CallStackProfileMetricsProvider::kFieldTrialName); 391 CallStackProfileMetricsProvider::kFieldTrialName);
389 return group_name == 392 return group_name ==
390 CallStackProfileMetricsProvider::kReportProfilesGroupName; 393 CallStackProfileMetricsProvider::kReportProfilesGroupName;
391 } 394 }
392 395
393 } // namespace metrics 396 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698