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

Side by Side Diff: chrome/browser/metrics/call_stack_profile_metrics_provider.cc

Issue 981143006: Metrics provider for statistical stack profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: fix clang compilation Created 5 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "call_stack_profile_metrics_provider.h"
6
7 #include "base/md5.h"
8 #include "base/profiler/stack_sampling_profiler.h"
9 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
10
11 using base::StackSamplingProfiler;
12 using metrics::CallStackProfile;
13 using metrics::CallStackEntry;
Ilya Sherman 2015/03/10 01:44:46 nit: Please alphabetize
Mike Wittman 2015/03/16 23:55:14 Done.
14 using metrics::ChromeUserMetricsExtension;
15 using metrics::ModuleIdentifier;
16 using metrics::SampledProfile;
17
18 namespace {
Ilya Sherman 2015/03/10 01:44:46 nit: Please include a blank line after this one.
Mike Wittman 2015/03/16 23:55:15 Done.
19 // The protobuf expects the MD5 checksum prefix of the module name.
20 uint64 HashModuleFilename(const base::FilePath& filename) {
21 const base::FilePath::StringType basename = filename.BaseName().value();
22 base::MD5Digest md5;
23 base::MD5Sum(&basename[0], basename.size() * sizeof(base::FilePath::CharType),
24 &md5);
25 return *reinterpret_cast<uint64*>(&md5.a[0]);
26 }
27
28 void CopySampleToProto(const StackSamplingProfiler::Sample& sample,
29 CallStackProfile::Sample* proto_sample) {
Ilya Sherman 2015/03/10 01:44:46 nit: Please document all functions, including loca
Mike Wittman 2015/03/16 23:55:15 Done.
30 for (const StackSamplingProfiler::Frame& frame : sample) {
31 CallStackEntry* call_stack_entry = proto_sample->add_entries();
32 call_stack_entry->set_address(frame.ip_offset);
33 call_stack_entry->set_module_id_index(frame.module_index);
34 }
35 }
36
37 void CopyProfileToProto(
38 const StackSamplingProfiler::Profile& profile,
39 metrics::CallStackProfile* proto_profile) {
40 if (profile.samples.empty())
41 return;
42
43 CallStackProfile::Sample* current_sample_proto = nullptr;
44 for (auto it = profile.samples.begin(); it != profile.samples.end(); ++it) {
45 if (!current_sample_proto || *it != *(it - 1)) {
Ilya Sherman 2015/03/10 01:44:46 Hmm, this seems like a surprising design. Why doe
Mike Wittman 2015/03/16 23:55:15 After further discussion, we want to support two d
46 current_sample_proto = proto_profile->add_samples();
47 CopySampleToProto(profile.samples.front(), current_sample_proto);
48 current_sample_proto->set_count(1);
49 } else {
50 current_sample_proto->set_count(current_sample_proto->count() + 1);
51 }
52 }
53
54 for (const StackSamplingProfiler::Module& module : profile.modules) {
55 ModuleIdentifier* module_id = proto_profile->add_module_ids();
56 module_id->set_build_id(module.id);
57 module_id->set_name_md5_prefix(HashModuleFilename(module.filename));
58 }
59
60 proto_profile->set_profile_duration_ms(
61 profile.profile_duration.InMilliseconds());
62 proto_profile->set_sampling_period_ms(
63 profile.sampling_period.InMilliseconds());
64 }
65 } // namespace
66
67 CallStackProfileMetricsProvider::CallStackProfileMetricsProvider() {}
68
69 CallStackProfileMetricsProvider::~CallStackProfileMetricsProvider() {}
70
71 void CallStackProfileMetricsProvider::ProvideGeneralMetrics(
72 metrics::ChromeUserMetricsExtension* uma_proto) {
73 std::vector<StackSamplingProfiler::Profile> profiles;
74 StackSamplingProfiler::GetPendingProfiles(&profiles);
75
76 for (StackSamplingProfiler::Profile profile : profiles) {
77 CallStackProfile* call_stack_profile =
78 uma_proto->add_sampled_profile()->mutable_call_stack_profile();
79 CopyProfileToProto(profile, call_stack_profile);
80 }
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698