00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef INCLUDE_BASE_STATS_H
00018 #define INCLUDE_BASE_STATS_H
00019
00020 #ifdef SHOW_STATS
00021
00022 #include "hash/tables.h"
00023
00024 namespace base
00025 {
00026 class Stats
00027 {
00028 public:
00029 Stats() {}
00030 ~Stats();
00031
00032 void count(const char *statName, const char *subStat = NULL);
00033
00034 struct stat_t
00035 {
00036 stat_t(const char *statName, stat_t *nxt)
00037 : name(statName), counter(1), next(nxt) {}
00038 ~stat_t() { delete next; }
00039
00040 const char *name;
00041 long counter;
00042 stat_t *next;
00043 };
00044
00045 struct entry_t : public hash::TableSingle<entry_t>::Bucket_t
00046 {
00047 entry_t(const char *name, stat_t *next = NULL)
00048 : stat(name, next) {}
00049
00050 stat_t stat;
00051 };
00052
00053 private:
00054 hash::TableSingle<entry_t> table;
00055 };
00056
00057 extern Stats stats;
00058 }
00059
00060
00061
00062 #define RECORD_STAT() base::stats.count(__PRETTY_FUNCTION__, NULL)
00063 #define RECORD_SUBSTAT(NAME) base::stats.count(__PRETTY_FUNCTION__, NAME)
00064 #define RECORD_NSTAT(ROOT, NAME)\
00065 base::stats.count(ROOT, NULL); \
00066 base::stats.count(ROOT, NAME)
00067
00068 #else
00069
00070 #define RECORD_STAT()
00071 #define RECORD_SUBSTAT(NAME)
00072 #define RECORD_NSTAT(ROOT, NAME)
00073
00074 #endif // SHOW_STATS
00075
00076 #endif // INCLUDE_BASE_STATS_H