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 <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 19 #include "base/metrics/metrics_hashes.h" |
19 #include "base/profiler/stack_sampling_profiler.h" | 20 #include "base/profiler/stack_sampling_profiler.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "components/metrics/metrics_hashes.h" | |
25 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 25 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
26 | 26 |
27 using base::StackSamplingProfiler; | 27 using base::StackSamplingProfiler; |
28 | 28 |
29 namespace metrics { | 29 namespace metrics { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // ProfilesState -------------------------------------------------------------- | 33 // ProfilesState -------------------------------------------------------------- |
34 | 34 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Functions to encode protobufs ---------------------------------------------- | 201 // Functions to encode protobufs ---------------------------------------------- |
202 | 202 |
203 // The protobuf expects the MD5 checksum prefix of the module name. | 203 // The protobuf expects the MD5 checksum prefix of the module name. |
204 uint64 HashModuleFilename(const base::FilePath& filename) { | 204 uint64 HashModuleFilename(const base::FilePath& filename) { |
205 const base::FilePath::StringType basename = filename.BaseName().value(); | 205 const base::FilePath::StringType basename = filename.BaseName().value(); |
206 // Copy the bytes in basename into a string buffer. | 206 // Copy the bytes in basename into a string buffer. |
207 size_t basename_length_in_bytes = | 207 size_t basename_length_in_bytes = |
208 basename.size() * sizeof(base::FilePath::CharType); | 208 basename.size() * sizeof(base::FilePath::CharType); |
209 std::string name_bytes(basename_length_in_bytes, '\0'); | 209 std::string name_bytes(basename_length_in_bytes, '\0'); |
210 memcpy(&name_bytes[0], &basename[0], basename_length_in_bytes); | 210 memcpy(&name_bytes[0], &basename[0], basename_length_in_bytes); |
211 return HashMetricName(name_bytes); | 211 return base::HashMetricName(name_bytes); |
212 } | 212 } |
213 | 213 |
214 // Transcode |sample| into |proto_sample|, using base addresses in |modules| to | 214 // Transcode |sample| into |proto_sample|, using base addresses in |modules| to |
215 // compute module instruction pointer offsets. | 215 // compute module instruction pointer offsets. |
216 void CopySampleToProto( | 216 void CopySampleToProto( |
217 const StackSamplingProfiler::Sample& sample, | 217 const StackSamplingProfiler::Sample& sample, |
218 const std::vector<StackSamplingProfiler::Module>& modules, | 218 const std::vector<StackSamplingProfiler::Module>& modules, |
219 CallStackProfile::Sample* proto_sample) { | 219 CallStackProfile::Sample* proto_sample) { |
220 for (const StackSamplingProfiler::Frame& frame : sample) { | 220 for (const StackSamplingProfiler::Frame& frame : sample) { |
221 CallStackProfile::Entry* entry = proto_sample->add_entry(); | 221 CallStackProfile::Entry* entry = proto_sample->add_entry(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 384 |
385 // static | 385 // static |
386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { | 386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { |
387 const std::string group_name = base::FieldTrialList::FindFullName( | 387 const std::string group_name = base::FieldTrialList::FindFullName( |
388 CallStackProfileMetricsProvider::kFieldTrialName); | 388 CallStackProfileMetricsProvider::kFieldTrialName); |
389 return group_name == | 389 return group_name == |
390 CallStackProfileMetricsProvider::kReportProfilesGroupName; | 390 CallStackProfileMetricsProvider::kReportProfilesGroupName; |
391 } | 391 } |
392 | 392 |
393 } // namespace metrics | 393 } // namespace metrics |
OLD | NEW |