Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / nacl / renderer / histogram.cc
blob7f146578973b138b454221c4e07d86397e0b5024
1 // Copyright 2014 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.
5 #include "components/nacl/renderer/histogram.h"
7 #include "base/metrics/histogram.h"
9 namespace nacl {
11 void HistogramCustomCounts(const std::string& name,
12 int32_t sample,
13 int32_t min,
14 int32_t max,
15 uint32_t bucket_count) {
16 base::HistogramBase* counter =
17 base::Histogram::FactoryGet(
18 name,
19 min,
20 max,
21 bucket_count,
22 base::HistogramBase::kUmaTargetedHistogramFlag);
23 // The histogram can be NULL if it is constructed with bad arguments. Ignore
24 // that data for this API. An error message will be logged.
25 if (counter)
26 counter->Add(sample);
29 void HistogramEnumerate(const std::string& name,
30 int32_t sample,
31 int32_t boundary_value) {
32 base::HistogramBase* counter =
33 base::LinearHistogram::FactoryGet(
34 name,
36 boundary_value,
37 boundary_value + 1,
38 base::HistogramBase::kUmaTargetedHistogramFlag);
39 counter->Add(sample);
42 void HistogramEnumerateLoadStatus(PP_NaClError error_code,
43 bool is_installed) {
44 HistogramEnumerate("NaCl.LoadStatus.Plugin", error_code, PP_NACL_ERROR_MAX);
46 // Gather data to see if being installed changes load outcomes.
47 const char* name = is_installed ?
48 "NaCl.LoadStatus.Plugin.InstalledApp" :
49 "NaCl.LoadStatus.Plugin.NotInstalledApp";
50 HistogramEnumerate(name, error_code, PP_NACL_ERROR_MAX);
53 void HistogramEnumerateOsArch(const std::string& sandbox_isa) {
54 enum NaClOSArch {
55 kNaClLinux32 = 0,
56 kNaClLinux64,
57 kNaClLinuxArm,
58 kNaClMac32,
59 kNaClMac64,
60 kNaClMacArm,
61 kNaClWin32,
62 kNaClWin64,
63 kNaClWinArm,
64 kNaClLinuxMips,
65 kNaClOSArchMax
68 NaClOSArch os_arch = kNaClOSArchMax;
69 #if OS_LINUX
70 os_arch = kNaClLinux32;
71 #elif OS_MACOSX
72 os_arch = kNaClMac32;
73 #elif OS_WIN
74 os_arch = kNaClWin32;
75 #endif
77 if (sandbox_isa == "x86-64")
78 os_arch = static_cast<NaClOSArch>(os_arch + 1);
79 if (sandbox_isa == "arm")
80 os_arch = static_cast<NaClOSArch>(os_arch + 2);
81 if (sandbox_isa == "mips32")
82 os_arch = kNaClLinuxMips;
84 HistogramEnumerate("NaCl.Client.OSArch", os_arch, kNaClOSArchMax);
87 // Records values up to 20 seconds.
88 void HistogramTimeSmall(const std::string& name, int64_t sample) {
89 if (sample < 0)
90 sample = 0;
91 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
92 name,
93 base::TimeDelta::FromMilliseconds(1),
94 base::TimeDelta::FromMilliseconds(20000),
95 100,
96 base::HistogramBase::kUmaTargetedHistogramFlag);
97 if (counter)
98 counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
101 // Records values up to 3 minutes, 20 seconds.
102 void HistogramTimeMedium(const std::string& name, int64_t sample) {
103 if (sample < 0)
104 sample = 0;
105 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
106 name,
107 base::TimeDelta::FromMilliseconds(10),
108 base::TimeDelta::FromMilliseconds(200000),
109 100,
110 base::HistogramBase::kUmaTargetedHistogramFlag);
111 if (counter)
112 counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
115 // Records values up to 33 minutes.
116 void HistogramTimeLarge(const std::string& name, int64_t sample) {
117 if (sample < 0)
118 sample = 0;
119 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
120 name,
121 base::TimeDelta::FromMilliseconds(100),
122 base::TimeDelta::FromMilliseconds(2000000),
123 100,
124 base::HistogramBase::kUmaTargetedHistogramFlag);
125 if (counter)
126 counter->AddTime(base::TimeDelta::FromMilliseconds(sample));
129 // Records values up to 12 minutes.
130 void HistogramTimeTranslation(const std::string& name, int64_t sample_ms) {
131 if (sample_ms < 0)
132 sample_ms = 0;
133 base::HistogramBase* counter = base::Histogram::FactoryTimeGet(
134 name,
135 base::TimeDelta::FromMilliseconds(10),
136 base::TimeDelta::FromMilliseconds(720000),
137 100,
138 base::HistogramBase::kUmaTargetedHistogramFlag);
139 if (counter)
140 counter->AddTime(base::TimeDelta::FromMilliseconds(sample_ms));
143 void HistogramStartupTimeSmall(const std::string& name,
144 base::TimeDelta td,
145 int64_t nexe_size) {
146 HistogramTimeSmall(name, static_cast<int64_t>(td.InMilliseconds()));
147 if (nexe_size > 0) {
148 float size_in_MB = static_cast<float>(nexe_size) / (1024.f * 1024.f);
149 HistogramTimeSmall(name + "PerMB",
150 static_cast<int64_t>(td.InMilliseconds() / size_in_MB));
154 void HistogramStartupTimeMedium(const std::string& name,
155 base::TimeDelta td,
156 int64_t nexe_size) {
157 HistogramTimeMedium(name, static_cast<int64_t>(td.InMilliseconds()));
158 if (nexe_size > 0) {
159 float size_in_MB = static_cast<float>(nexe_size) / (1024.f * 1024.f);
160 HistogramTimeMedium(name + "PerMB",
161 static_cast<int64_t>(td.InMilliseconds() / size_in_MB));
165 void HistogramSizeKB(const std::string& name, int32_t sample) {
166 if (sample < 0) return;
167 HistogramCustomCounts(name,
168 sample,
170 512 * 1024, // A very large .nexe.
171 100);
174 void HistogramHTTPStatusCode(const std::string& name,
175 int32_t status) {
176 // Log the status codes in rough buckets - 1XX, 2XX, etc.
177 int sample = status / 100;
178 // HTTP status codes only go up to 5XX, using "6" to indicate an internal
179 // error.
180 // Note: installed files may have "0" for a status code.
181 if (status < 0 || status >= 600)
182 sample = 6;
183 HistogramEnumerate(name, sample, 7);
186 void HistogramEnumerateManifestIsDataURI(bool is_data_uri) {
187 HistogramEnumerate("NaCl.Manifest.IsDataURI", is_data_uri, 2);
190 void HistogramKBPerSec(const std::string& name, int64_t kb, int64_t us) {
191 if (kb < 0 || us <= 0) return;
192 static const double kMaxRate = 30 * 1000.0; // max of 30MB/sec.
193 int32_t rate = std::min(kb / (us / 1000000.0), kMaxRate);
194 HistogramCustomCounts(name,
195 rate,
197 30 * 1000, // max of 30 MB/sec.
198 100);
201 void HistogramRatio(const std::string& name,
202 int64_t numerator,
203 int64_t denominator) {
204 static const int32_t kRatioMin = 10;
205 static const int32_t kRatioMax = 10 * 100; // max of 10x difference.
206 static const uint32_t kRatioBuckets = 100;
207 if (numerator < 0 || denominator <= 0)
208 return;
209 HistogramCustomCounts(name,
210 static_cast<int32_t>(100 * numerator / denominator),
211 kRatioMin, kRatioMax, kRatioBuckets);
214 } // namespace nacl