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.
5 #include "net/base/file_stream_metrics.h"
9 #include "base/basictypes.h"
20 // The error range list is extracted from WinError.h.
22 // NOTE: The gaps between the ranges need to be recorded too.
23 // They will have odd-numbered buckets.
24 const Range kErrorRangeList[] = {
110 { 65535, 65536 } // 2 * kNumErrorRanges.
112 const size_t kNumErrorRanges = ARRAYSIZE_UNSAFE(kErrorRangeList);
116 // Windows has very many errors. We're not interested in most of them, but we
117 // don't know which ones are significant.
118 // This function maps error ranges to specific buckets.
119 // If we get hits on the buckets, we can add those values to the values we
120 // record individually.
121 // If we get values *between* the buckets, we record those as buckets too.
122 int GetFileErrorUmaBucket(int error) {
123 error = HRESULT_CODE(error);
125 // This is a linear search, but of a short fixed-size array.
126 // It also gets called infrequently, on errors.
127 for (size_t n = 0; n < kNumErrorRanges; ++n) {
128 if (error < kErrorRangeList[n].low)
129 return (2 * (n + 1)) - 1; // In gap before the range.
130 if (error <= kErrorRangeList[n].high)
131 return 2 * (n + 1); // In the range.
134 // After the last bucket.
135 return 2 * kNumErrorRanges + 1;
138 int MaxFileErrorUmaBucket() {
139 return 2 * kNumErrorRanges + 2;
142 int MaxFileErrorUmaValue() {
143 return kErrorRangeList[0].high + 1;