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

Side by Side Diff: chrome/common/metrics/metrics_log_base.cc

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split Name/Parameters Created 6 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/common/metrics/metrics_log_base.h" 5 #include "chrome/common/metrics/metrics_log_base.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/md5.h"
10 #include "base/metrics/histogram_base.h" 9 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/histogram_samples.h" 10 #include "base/metrics/histogram_samples.h"
12 #include "base/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
Alexei Svitkine (slow) 2014/02/05 18:07:01 Is this header needed by this file anymore?
Steven Holte 2014/02/05 22:44:37 Removed, along with a couple other headers that do
13 #include "base/sys_info.h" 12 #include "base/sys_info.h"
14 #include "chrome/common/chrome_version_info.h" 13 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/logging_chrome.h" 14 #include "chrome/common/logging_chrome.h"
16 #include "chrome/common/metrics/proto/histogram_event.pb.h" 15 #include "chrome/common/metrics/proto/histogram_event.pb.h"
17 #include "chrome/common/metrics/proto/system_profile.pb.h" 16 #include "chrome/common/metrics/proto/system_profile.pb.h"
18 #include "chrome/common/metrics/proto/user_action_event.pb.h" 17 #include "chrome/common/metrics/proto/user_action_event.pb.h"
18 #include "components/variations/metrics_util.h"
19 19
20 using base::Histogram; 20 using base::Histogram;
21 using base::HistogramBase; 21 using base::HistogramBase;
22 using base::HistogramSamples; 22 using base::HistogramSamples;
23 using base::SampleCountIterator; 23 using base::SampleCountIterator;
24 using base::Time; 24 using base::Time;
25 using base::TimeDelta; 25 using base::TimeDelta;
26 using metrics::HistogramEventProto; 26 using metrics::HistogramEventProto;
27 using metrics::SystemProfileProto; 27 using metrics::SystemProfileProto;
28 using metrics::UserActionEventProto; 28 using metrics::UserActionEventProto;
29 29
30 namespace { 30 namespace {
31 31
32 // Any id less than 16 bytes is considered to be a testing id. 32 // Any id less than 16 bytes is considered to be a testing id.
33 bool IsTestingID(const std::string& id) { 33 bool IsTestingID(const std::string& id) {
34 return id.size() < 16; 34 return id.size() < 16;
35 } 35 }
36 36
37 // Converts the 8-byte prefix of an MD5 hash into a uint64 value.
38 inline uint64 HashToUInt64(const std::string& hash) {
39 uint64 value;
40 DCHECK_GE(hash.size(), sizeof(value));
41 memcpy(&value, hash.data(), sizeof(value));
42 return base::HostToNet64(value);
43 }
44
45 SystemProfileProto::Channel AsProtobufChannel( 37 SystemProfileProto::Channel AsProtobufChannel(
46 chrome::VersionInfo::Channel channel) { 38 chrome::VersionInfo::Channel channel) {
47 switch (channel) { 39 switch (channel) {
48 case chrome::VersionInfo::CHANNEL_UNKNOWN: 40 case chrome::VersionInfo::CHANNEL_UNKNOWN:
49 return SystemProfileProto::CHANNEL_UNKNOWN; 41 return SystemProfileProto::CHANNEL_UNKNOWN;
50 case chrome::VersionInfo::CHANNEL_CANARY: 42 case chrome::VersionInfo::CHANNEL_CANARY:
51 return SystemProfileProto::CHANNEL_CANARY; 43 return SystemProfileProto::CHANNEL_CANARY;
52 case chrome::VersionInfo::CHANNEL_DEV: 44 case chrome::VersionInfo::CHANNEL_DEV:
53 return SystemProfileProto::CHANNEL_DEV; 45 return SystemProfileProto::CHANNEL_DEV;
54 case chrome::VersionInfo::CHANNEL_BETA: 46 case chrome::VersionInfo::CHANNEL_BETA:
(...skipping 21 matching lines...) Expand all
76 uma_proto_.mutable_system_profile()->set_build_timestamp(GetBuildTime()); 68 uma_proto_.mutable_system_profile()->set_build_timestamp(GetBuildTime());
77 uma_proto_.mutable_system_profile()->set_app_version(version_string); 69 uma_proto_.mutable_system_profile()->set_app_version(version_string);
78 uma_proto_.mutable_system_profile()->set_channel( 70 uma_proto_.mutable_system_profile()->set_channel(
79 AsProtobufChannel(chrome::VersionInfo::GetChannel())); 71 AsProtobufChannel(chrome::VersionInfo::GetChannel()));
80 } 72 }
81 73
82 MetricsLogBase::~MetricsLogBase() {} 74 MetricsLogBase::~MetricsLogBase() {}
83 75
84 // static 76 // static
85 uint64 MetricsLogBase::Hash(const std::string& value) { 77 uint64 MetricsLogBase::Hash(const std::string& value) {
86 // Create an MD5 hash of the given |value|, represented as a byte buffer 78 uint64 hash = metrics::HashMetricName(value);
87 // encoded as an std::string.
88 base::MD5Context context;
89 base::MD5Init(&context);
90 base::MD5Update(&context, value);
91
92 base::MD5Digest digest;
93 base::MD5Final(&digest, &context);
94
95 std::string hash_str(reinterpret_cast<char*>(digest.a), arraysize(digest.a));
96 uint64 hash = HashToUInt64(hash_str);
97 79
98 // The following log is VERY helpful when folks add some named histogram into 80 // The following log is VERY helpful when folks add some named histogram into
99 // the code, but forgot to update the descriptive list of histograms. When 81 // the code, but forgot to update the descriptive list of histograms. When
100 // that happens, all we get to see (server side) is a hash of the histogram 82 // that happens, all we get to see (server side) is a hash of the histogram
101 // name. We can then use this logging to find out what histogram name was 83 // name. We can then use this logging to find out what histogram name was
102 // being hashed to a given MD5 value by just running the version of Chromium 84 // being hashed to a given MD5 value by just running the version of Chromium
103 // in question with --enable-logging. 85 // in question with --enable-logging.
104 DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]"; 86 DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]";
105 87
106 return hash; 88 return hash;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { 154 for (int i = 0; i < histogram_proto->bucket_size(); ++i) {
173 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); 155 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i);
174 if (i + 1 < histogram_proto->bucket_size() && 156 if (i + 1 < histogram_proto->bucket_size() &&
175 bucket->max() == histogram_proto->bucket(i + 1).min()) { 157 bucket->max() == histogram_proto->bucket(i + 1).min()) {
176 bucket->clear_max(); 158 bucket->clear_max();
177 } else if (bucket->max() == bucket->min() + 1) { 159 } else if (bucket->max() == bucket->min() + 1) {
178 bucket->clear_min(); 160 bucket->clear_min();
179 } 161 }
180 } 162 }
181 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698