Move AsyncPolicyProvider, etc. to components/policy/.
[chromium-blink-merge.git] / net / base / file_stream_metrics.cc
blobbff7174a40b8eccd74dbb9a6d09b9b66e2a28f08
1 // Copyright (c) 2012 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"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
11 namespace net {
13 namespace {
15 const char* FileErrorSourceStrings[] = {
16 "OPEN",
17 "WRITE",
18 "READ",
19 "SEEK",
20 "FLUSH",
21 "SET_EOF",
22 "GET_SIZE",
23 "CLOSE"
26 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(FileErrorSourceStrings) ==
27 FILE_ERROR_SOURCE_COUNT,
28 file_error_source_enum_has_changed);
30 void RecordFileErrorTypeCount(FileErrorSource source) {
31 UMA_HISTOGRAM_ENUMERATION(
32 "Net.FileErrorType_Counts", source, FILE_ERROR_SOURCE_COUNT);
35 } // namespace
37 void RecordFileError(int error, FileErrorSource source, bool record) {
38 if (!record)
39 return;
41 RecordFileErrorTypeCount(source);
43 int bucket = GetFileErrorUmaBucket(error);
45 // Fixed values per platform.
46 static const int max_bucket = MaxFileErrorUmaBucket();
47 static const int max_error = MaxFileErrorUmaValue();
49 switch(source) {
50 case FILE_ERROR_SOURCE_OPEN:
51 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Open", error, max_error);
52 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Open", bucket, max_bucket);
53 break;
55 case FILE_ERROR_SOURCE_WRITE:
56 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Write", error, max_error);
57 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Write", bucket, max_bucket);
58 break;
60 case FILE_ERROR_SOURCE_READ:
61 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Read", error, max_error);
62 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Read", bucket, max_bucket);
63 break;
65 case FILE_ERROR_SOURCE_SEEK:
66 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Seek", error, max_error);
67 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Seek", bucket, max_bucket);
68 break;
70 case FILE_ERROR_SOURCE_FLUSH:
71 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Flush", error, max_error);
72 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Flush", bucket, max_bucket);
73 break;
75 case FILE_ERROR_SOURCE_SET_EOF:
76 UMA_HISTOGRAM_ENUMERATION("Net.FileError_SetEof", error, max_error);
77 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_SetEof", bucket,
78 max_bucket);
79 break;
81 case FILE_ERROR_SOURCE_GET_SIZE:
82 UMA_HISTOGRAM_ENUMERATION("Net.FileError_GetSize", error, max_error);
83 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_GetSize", bucket,
84 max_bucket);
85 break;
87 case FILE_ERROR_SOURCE_CLOSE:
88 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Close", error, max_error);
89 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Close", bucket,
90 max_bucket);
91 break;
93 default:
94 break;
98 const char* GetFileErrorSourceName(FileErrorSource source) {
99 DCHECK_NE(FILE_ERROR_SOURCE_COUNT, source);
100 return FileErrorSourceStrings[source];
103 } // namespace net