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 // These constants MUST match those in
89 // ppapi/native_client/src/trusted/plugin/plugin.cc
90 void HistogramTimeSmall(const std::string
& name
, int64_t sample
) {
93 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
95 base::TimeDelta::FromMilliseconds(1),
96 base::TimeDelta::FromMilliseconds(20000),
98 base::HistogramBase::kUmaTargetedHistogramFlag
);
100 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample
));
103 // Records values up to 3 minutes, 20 seconds.
104 // These constants MUST match those in
105 // ppapi/native_client/src/trusted/plugin/plugin.cc
106 void HistogramTimeMedium(const std::string
& name
, int64_t sample
) {
109 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
111 base::TimeDelta::FromMilliseconds(10),
112 base::TimeDelta::FromMilliseconds(200000),
114 base::HistogramBase::kUmaTargetedHistogramFlag
);
116 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample
));
119 // Records values up to 33 minutes.
120 // These constants MUST match those in
121 // ppapi/native_client/src/trusted/plugin/plugin.cc
122 void HistogramTimeLarge(const std::string
& name
, int64_t sample
) {
125 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
127 base::TimeDelta::FromMilliseconds(100),
128 base::TimeDelta::FromMilliseconds(2000000),
130 base::HistogramBase::kUmaTargetedHistogramFlag
);
132 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample
));
135 // Records values up to 12 minutes.
136 void HistogramTimeTranslation(const std::string
& name
, int64_t sample_ms
) {
139 base::HistogramBase
* counter
= base::Histogram::FactoryTimeGet(
141 base::TimeDelta::FromMilliseconds(10),
142 base::TimeDelta::FromMilliseconds(720000),
144 base::HistogramBase::kUmaTargetedHistogramFlag
);
146 counter
->AddTime(base::TimeDelta::FromMilliseconds(sample_ms
));
149 void HistogramStartupTimeSmall(const std::string
& name
,
152 HistogramTimeSmall(name
, static_cast<int64_t>(td
.InMilliseconds()));
154 float size_in_MB
= static_cast<float>(nexe_size
) / (1024.f
* 1024.f
);
155 HistogramTimeSmall(name
+ "PerMB",
156 static_cast<int64_t>(td
.InMilliseconds() / size_in_MB
));
160 void HistogramStartupTimeMedium(const std::string
& name
,
163 HistogramTimeMedium(name
, static_cast<int64_t>(td
.InMilliseconds()));
165 float size_in_MB
= static_cast<float>(nexe_size
) / (1024.f
* 1024.f
);
166 HistogramTimeMedium(name
+ "PerMB",
167 static_cast<int64_t>(td
.InMilliseconds() / size_in_MB
));
171 void HistogramSizeKB(const std::string
& name
, int32_t sample
) {
172 if (sample
< 0) return;
173 HistogramCustomCounts(name
,
176 512 * 1024, // A very large .nexe.
180 void HistogramHTTPStatusCode(const std::string
& name
,
182 // Log the status codes in rough buckets - 1XX, 2XX, etc.
183 int sample
= status
/ 100;
184 // HTTP status codes only go up to 5XX, using "6" to indicate an internal
186 // Note: installed files may have "0" for a status code.
187 if (status
< 0 || status
>= 600)
189 HistogramEnumerate(name
, sample
, 7);
192 void HistogramEnumerateManifestIsDataURI(bool is_data_uri
) {
193 HistogramEnumerate("NaCl.Manifest.IsDataURI", is_data_uri
, 2);
196 void HistogramKBPerSec(const std::string
& name
, int64_t kb
, int64_t us
) {
197 if (kb
< 0 || us
<= 0) return;
198 static const double kMaxRate
= 30 * 1000.0; // max of 30MB/sec.
199 int32_t rate
= std::min(kb
/ (us
/ 1000000.0), kMaxRate
);
200 HistogramCustomCounts(name
,
203 30 * 1000, // max of 30 MB/sec.