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

Side by Side Diff: base/android/record_histogram.cc

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 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 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 "base/android/record_histogram.h" 5 #include "base/android/record_histogram.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h"
13 #include "base/metrics/statistics_recorder.h" 14 #include "base/metrics/statistics_recorder.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "jni/RecordHistogram_jni.h" 17 #include "jni/RecordHistogram_jni.h"
17 18
18 namespace base { 19 namespace base {
19 namespace android { 20 namespace android {
20 namespace { 21 namespace {
21 22
22 // Simple thread-safe wrapper for caching histograms. This avoids 23 // Simple thread-safe wrapper for caching histograms. This avoids
(...skipping 30 matching lines...) Expand all
53 return histogram; 54 return histogram;
54 } 55 }
55 56
56 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); 57 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name);
57 histogram = 58 histogram =
58 LinearHistogram::FactoryGet(histogram_name, 1, boundary, boundary + 1, 59 LinearHistogram::FactoryGet(histogram_name, 1, boundary, boundary + 1,
59 HistogramBase::kUmaTargetedHistogramFlag); 60 HistogramBase::kUmaTargetedHistogramFlag);
60 return InsertLocked(j_histogram_key, histogram); 61 return InsertLocked(j_histogram_key, histogram);
61 } 62 }
62 63
63 HistogramBase* CountHistogram(JNIEnv* env, 64 HistogramBase* CustomCountHistogram(JNIEnv* env,
64 jstring j_histogram_name, 65 jstring j_histogram_name,
65 jint j_histogram_key) { 66 jint j_histogram_key,
66 // These values are based on the hard-coded constants in the 67 jint j_min,
67 // UMA_HISTOGRAM_COUNTS macro from base/metrics/histogram_macros.h. 68 jint j_max,
68 const int histogram_min = 1; 69 jint j_num_buckets) {
69 const int histogram_max = 1000000;
70 const int histogram_num_buckets = 50;
71
72 DCHECK(j_histogram_name); 70 DCHECK(j_histogram_name);
73 DCHECK(j_histogram_key); 71 DCHECK(j_histogram_key);
72 int64 min = static_cast<int64>(j_min);
73 int64 max = static_cast<int64>(j_max);
74 int num_buckets = static_cast<int>(j_num_buckets);
74 HistogramBase* histogram = FindLocked(j_histogram_key); 75 HistogramBase* histogram = FindLocked(j_histogram_key);
75 if (histogram) { 76 if (histogram) {
76 DCHECK(histogram->HasConstructionArguments(histogram_min, histogram_max, 77 DCHECK(histogram->HasConstructionArguments(min, max, num_buckets));
77 histogram_num_buckets));
78 return histogram; 78 return histogram;
79 } 79 }
80 80
81 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); 81 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name);
82 histogram = Histogram::FactoryGet(histogram_name, histogram_min, 82 histogram =
83 histogram_max, histogram_num_buckets, 83 Histogram::FactoryGet(histogram_name, min, max, num_buckets,
84 HistogramBase::kUmaTargetedHistogramFlag); 84 HistogramBase::kUmaTargetedHistogramFlag);
85 return InsertLocked(j_histogram_key, histogram); 85 return InsertLocked(j_histogram_key, histogram);
86 } 86 }
87 87
88 HistogramBase* SparseHistogram(JNIEnv* env,
89 jstring j_histogram_name,
90 jint j_histogram_key) {
91 DCHECK(j_histogram_name);
92 DCHECK(j_histogram_key);
93 HistogramBase* histogram = FindLocked(j_histogram_key);
94 if (histogram)
95 return histogram;
96
97 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name);
98 histogram = SparseHistogram::FactoryGet(
99 histogram_name, HistogramBase::kUmaTargetedHistogramFlag);
100 return InsertLocked(j_histogram_key, histogram);
101 }
102
88 HistogramBase* CustomTimesHistogram(JNIEnv* env, 103 HistogramBase* CustomTimesHistogram(JNIEnv* env,
89 jstring j_histogram_name, 104 jstring j_histogram_name,
90 jint j_histogram_key, 105 jint j_histogram_key,
91 jlong j_min, 106 jlong j_min,
92 jlong j_max, 107 jlong j_max,
93 jint j_bucket_count) { 108 jint j_bucket_count) {
94 DCHECK(j_histogram_name); 109 DCHECK(j_histogram_name);
95 DCHECK(j_histogram_key); 110 DCHECK(j_histogram_key);
96 HistogramBase* histogram = FindLocked(j_histogram_key); 111 HistogramBase* histogram = FindLocked(j_histogram_key);
97 int64 min = static_cast<int64>(j_min); 112 int64 min = static_cast<int64>(j_min);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 jint j_histogram_key, 166 jint j_histogram_key,
152 jint j_sample, 167 jint j_sample,
153 jint j_boundary) { 168 jint j_boundary) {
154 int sample = static_cast<int>(j_sample); 169 int sample = static_cast<int>(j_sample);
155 170
156 g_histograms.Get() 171 g_histograms.Get()
157 .EnumeratedHistogram(env, j_histogram_name, j_histogram_key, j_boundary) 172 .EnumeratedHistogram(env, j_histogram_name, j_histogram_key, j_boundary)
158 ->Add(sample); 173 ->Add(sample);
159 } 174 }
160 175
161 void RecordCountHistogram(JNIEnv* env, 176 void RecordCustomCountHistogram(JNIEnv* env,
162 jclass clazz, 177 jclass clazz,
163 jstring j_histogram_name, 178 jstring j_histogram_name,
164 jint j_histogram_key, 179 jint j_histogram_key,
165 jint j_sample) { 180 jint j_sample,
181 jint j_min,
182 jint j_max,
183 jint j_num_buckets) {
166 int sample = static_cast<int>(j_sample); 184 int sample = static_cast<int>(j_sample);
167 185
168 g_histograms.Get() 186 g_histograms.Get()
169 .CountHistogram(env, j_histogram_name, j_histogram_key) 187 .CustomCountHistogram(env, j_histogram_name, j_histogram_key, j_min,
188 j_max, j_num_buckets)
170 ->Add(sample); 189 ->Add(sample);
171 } 190 }
172 191
192 void RecordSparseHistogram(JNIEnv* env,
193 jclass clazz,
194 jstring j_histogram_name,
195 jint j_histogram_key,
196 jint j_sample) {
197 int sample = static_cast<int>(j_sample);
198 g_histograms.Get()
199 .SparseHistogram(env, j_histogram_name, j_histogram_key)
200 ->Add(sample);
201 }
202
173 void RecordCustomTimesHistogramMilliseconds(JNIEnv* env, 203 void RecordCustomTimesHistogramMilliseconds(JNIEnv* env,
174 jclass clazz, 204 jclass clazz,
175 jstring j_histogram_name, 205 jstring j_histogram_name,
176 jint j_histogram_key, 206 jint j_histogram_key,
177 jlong j_duration, 207 jlong j_duration,
178 jlong j_min, 208 jlong j_min,
179 jlong j_max, 209 jlong j_max,
180 jint j_num_buckets) { 210 jint j_num_buckets) {
181 g_histograms.Get() 211 g_histograms.Get()
182 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min, 212 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min,
(...skipping 23 matching lines...) Expand all
206 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); 236 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
207 return samples->GetCount(static_cast<int>(sample)); 237 return samples->GetCount(static_cast<int>(sample));
208 } 238 }
209 239
210 bool RegisterRecordHistogram(JNIEnv* env) { 240 bool RegisterRecordHistogram(JNIEnv* env) {
211 return RegisterNativesImpl(env); 241 return RegisterNativesImpl(env);
212 } 242 }
213 243
214 } // namespace android 244 } // namespace android
215 } // namespace base 245 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698