OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_uma_private_impl.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "ppapi/c/pp_var.h" | |
9 #include "ppapi/c/private/ppb_uma_private.h" | |
10 #include "ppapi/shared_impl/var.h" | |
11 #include "webkit/glue/webkit_glue.h" | |
12 | |
13 using ppapi::StringVar; | |
14 | |
15 namespace webkit { | |
16 namespace ppapi { | |
17 | |
18 namespace { | |
19 | |
20 #define RETURN_IF_BAD_ARGS(_name, _sample, _min, _max, _bucket_count) \ | |
21 do { \ | |
22 if (_name.type != PP_VARTYPE_STRING || _name.value.as_id == 0) \ | |
23 return; \ | |
24 if (_min >= _max) \ | |
25 return; \ | |
26 if (_bucket_count <= 1) \ | |
27 return; \ | |
28 } while (0) | |
29 | |
30 void HistogramCustomTimes(PP_Var name, | |
31 int64_t sample, | |
32 int64_t min, int64_t max, | |
33 uint32_t bucket_count) { | |
34 RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); | |
35 | |
36 StringVar* name_string = StringVar::FromPPVar(name); | |
37 if (name_string == NULL) | |
38 return; | |
39 base::HistogramBase* counter = | |
40 base::Histogram::FactoryTimeGet( | |
41 name_string->value(), | |
42 base::TimeDelta::FromMilliseconds(min), | |
43 base::TimeDelta::FromMilliseconds(max), | |
44 bucket_count, | |
45 base::HistogramBase::kUmaTargetedHistogramFlag); | |
46 counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); | |
47 } | |
48 | |
49 void HistogramCustomCounts(PP_Var name, | |
50 int32_t sample, | |
51 int32_t min, int32_t max, | |
52 uint32_t bucket_count) { | |
53 RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); | |
54 | |
55 StringVar* name_string = StringVar::FromPPVar(name); | |
56 if (name_string == NULL) | |
57 return; | |
58 base::HistogramBase* counter = | |
59 base::Histogram::FactoryGet( | |
60 name_string->value(), | |
61 min, | |
62 max, | |
63 bucket_count, | |
64 base::HistogramBase::kUmaTargetedHistogramFlag); | |
65 counter->Add(sample); | |
66 } | |
67 | |
68 void HistogramEnumeration(PP_Var name, | |
69 int32_t sample, | |
70 int32_t boundary_value) { | |
71 RETURN_IF_BAD_ARGS(name, sample, 1, boundary_value, boundary_value + 1); | |
72 | |
73 StringVar* name_string = StringVar::FromPPVar(name); | |
74 if (name_string == NULL) | |
75 return; | |
76 base::HistogramBase* counter = | |
77 base::LinearHistogram::FactoryGet( | |
78 name_string->value(), | |
79 1, | |
80 boundary_value, | |
81 boundary_value + 1, | |
82 base::HistogramBase::kUmaTargetedHistogramFlag); | |
83 counter->Add(sample); | |
84 } | |
85 | |
86 } // namespace | |
87 | |
88 const PPB_UMA_Private ppb_uma = { | |
89 &HistogramCustomTimes, | |
90 &HistogramCustomCounts, | |
91 &HistogramEnumeration, | |
92 }; | |
93 | |
94 // static | |
95 const PPB_UMA_Private* PPB_UMA_Private_Impl::GetInterface() { | |
96 return &ppb_uma; | |
97 } | |
98 | |
99 } // namespace ppapi | |
100 } // namespace webkit | |
OLD | NEW |