• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 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 // This file contains macros to simplify histogram reporting from the disk
6 // cache. The main issue is that we want to have separate histograms for each
7 // type of cache (regular vs. media, etc), without adding the complexity of
8 // keeping track of a potentially large number of histogram objects that have to
9 // survive the backend object that created them.
10 
11 #ifndef NET_DISK_CACHE_HISTOGRAM_MACROS_H_
12 #define NET_DISK_CACHE_HISTOGRAM_MACROS_H_
13 
14 // HISTOGRAM_HOURS will collect time related data with a granularity of hours
15 // and normal values of a few months.
16 #define UMA_HISTOGRAM_HOURS UMA_HISTOGRAM_COUNTS_10000
17 
18 // HISTOGRAM_AGE will collect time elapsed since |initial_time|, with a
19 // granularity of hours and normal values of a few months.
20 #define UMA_HISTOGRAM_AGE(name, initial_time)\
21     UMA_HISTOGRAM_COUNTS_10000(name, (Time::Now() - initial_time).InHours())
22 
23 // HISTOGRAM_AGE_MS will collect time elapsed since |initial_time|, with the
24 // normal resolution of the UMA_HISTOGRAM_TIMES.
25 #define UMA_HISTOGRAM_AGE_MS(name, initial_time)\
26     UMA_HISTOGRAM_TIMES(name, Time::Now() - initial_time)
27 
28 #define UMA_HISTOGRAM_CACHE_ERROR(name, sample) \
29     UMA_HISTOGRAM_ENUMERATION(name, sample, 50)
30 
31 #ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_
32 #define BACKEND_OBJ this
33 #else
34 #define BACKEND_OBJ backend_
35 #endif
36 
37 // Generates a UMA histogram of the given type, generating the proper name for
38 // it (asking backend_->HistogramName), and adding the provided sample.
39 // For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would
40 // be used as:
41 //  CACHE_UMA(COUNTS, "MyName", 0, 20);
42 //  CACHE_UMA(COUNTS, "MyExperiment", 530, 55);
43 // which roughly translates to:
44 //  UMA_HISTOGRAM_COUNTS("DiskCache.2.MyName", 20);  // "2" is the CacheType.
45 //  UMA_HISTOGRAM_COUNTS("DiskCache.2.MyExperiment_530", 55);
46 //
47 #define CACHE_UMA(type, name, experiment, sample) {\
48     const std::string my_name = BACKEND_OBJ->HistogramName(name, experiment);\
49     switch (BACKEND_OBJ->cache_type()) {\
50       case net::DISK_CACHE:\
51         UMA_HISTOGRAM_##type(my_name.data(), sample);\
52         break;\
53       case net::MEDIA_CACHE:\
54         UMA_HISTOGRAM_##type(my_name.data(), sample);\
55         break;\
56       default:\
57         NOTREACHED();\
58         break;\
59     }\
60   }
61 
62 #endif  // NET_DISK_CACHE_HISTOGRAM_MACROS_H_
63