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"
11 void HistogramCustomCounts(const std::string
& name
,
15 uint32_t bucket_count
) {
16 base::HistogramBase
* counter
=
17 base::Histogram::FactoryGet(
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.
29 void HistogramEnumerate(const std::string
& name
,
31 int32_t boundary_value
) {
32 base::HistogramBase
* counter
=
33 base::LinearHistogram::FactoryGet(
38 base::HistogramBase::kUmaTargetedHistogramFlag
);
42 void HistogramEnumerateLoadStatus(PP_NaClError error_code
,
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
) {
68 NaClOSArch os_arch
= kNaClOSArchMax
;
70 os_arch
= kNaClLinux32
;
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
) {
91 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
93 base::TimeDelta::FromMilliseconds(1),
94 base::TimeDelta::FromMilliseconds(20000),
96 base::HistogramBase::kUmaTargetedHistogramFlag
);
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
) {
105 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
107 base::TimeDelta::FromMilliseconds(10),
108 base::TimeDelta::FromMilliseconds(200000),
110 base::HistogramBase::kUmaTargetedHistogramFlag
);
112 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample
));
115 // Records values up to 33 minutes.
116 void HistogramTimeLarge(const std::string
& name
, int64_t sample
) {
119 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
121 base::TimeDelta::FromMilliseconds(100),
122 base::TimeDelta::FromMilliseconds(2000000),
124 base::HistogramBase::kUmaTargetedHistogramFlag
);
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
) {
133 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
135 base::TimeDelta::FromMilliseconds(10),
136 base::TimeDelta::FromMilliseconds(720000),
138 base::HistogramBase::kUmaTargetedHistogramFlag
);
140 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample_ms
));
143 void HistogramStartupTimeSmall(const std::string
& name
,
146 HistogramTimeSmall(name
, static_cast<int64_t>(td
.InMilliseconds()));
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
,
157 HistogramTimeMedium(name
, static_cast<int64_t>(td
.InMilliseconds()));
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
,
170 512 * 1024, // A very large .nexe.
174 void HistogramHTTPStatusCode(const std::string
& name
,
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
180 // Note: installed files may have "0" for a status code.
181 if (status
< 0 || status
>= 600)
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
,
197 30 * 1000, // max of 30 MB/sec.
201 void HistogramRatio(const std::string
& name
,
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)
209 HistogramCustomCounts(name
,
210 static_cast<int32_t>(100 * numerator
/ denominator
),
211 kRatioMin
, kRatioMax
, kRatioBuckets
);