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. 4 5 #include "net/base/file_stream_metrics.h" 6 7 #include "base/basictypes.h" 8 #include "base/logging.h" 9 #include "base/metrics/histogram.h" 10 11 namespace net { 12 13 namespace { 14 15 const char* FileErrorSourceStrings[] = { 16 "OPEN", 17 "WRITE", 18 "READ", 19 "SEEK", 20 "FLUSH", 21 "SET_EOF", 22 "GET_SIZE", 23 "CLOSE" 24 }; 25 26 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(FileErrorSourceStrings) == 27 FILE_ERROR_SOURCE_COUNT, 28 file_error_source_enum_has_changed); 29 30 void RecordFileErrorTypeCount(FileErrorSource source) { 31 UMA_HISTOGRAM_ENUMERATION( 32 "Net.FileErrorType_Counts", source, FILE_ERROR_SOURCE_COUNT); 33 } 34 35 } // namespace 36 37 void RecordFileError(int error, FileErrorSource source, bool record) { 38 if (!record) 39 return; 40 41 RecordFileErrorTypeCount(source); 42 43 int bucket = GetFileErrorUmaBucket(error); 44 45 // Fixed values per platform. 46 static const int max_bucket = MaxFileErrorUmaBucket(); 47 static const int max_error = MaxFileErrorUmaValue(); 48 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; 54 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; 59 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; 64 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; 69 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; 74 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; 80 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; 86 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; 92 93 default: 94 break; 95 } 96 } 97 98 const char* GetFileErrorSourceName(FileErrorSource source) { 99 DCHECK_NE(FILE_ERROR_SOURCE_COUNT, source); 100 return FileErrorSourceStrings[source]; 101 } 102 103 } // namespace net 104