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"
15 const char* FileErrorSourceStrings
[] = {
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
);
37 void RecordFileError(int error
, FileErrorSource source
, bool record
) {
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();
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
);
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
);
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
);
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
);
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
);
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
,
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
,
87 case FILE_ERROR_SOURCE_CLOSE
:
88 UMA_HISTOGRAM_ENUMERATION("Net.FileError_Close", error
, max_error
);
89 UMA_HISTOGRAM_ENUMERATION("Net.FileErrorRange_Close", bucket
,
98 const char* GetFileErrorSourceName(FileErrorSource source
) {
99 DCHECK_NE(FILE_ERROR_SOURCE_COUNT
, source
);
100 return FileErrorSourceStrings
[source
];