usermode/library/common/stats_generic.h

00001 /*
00002     Copyright (C) 2011 Computer Sciences Department, 
00003     University of Wisconsin -- Madison
00004 
00005     ----------------------------------------------------------------------
00006 
00007     This file is part of Mnemosyne: Lightweight Persistent Memory, 
00008     originally developed at the University of Wisconsin -- Madison.
00009 
00010     Mnemosyne was originally developed primarily by Haris Volos
00011     with contributions from Andres Jaan Tack.
00012 
00013     ----------------------------------------------------------------------
00014 
00015     Mnemosyne is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU General Public License
00017     as published by the Free Software Foundation, version 2
00018     of the License.
00019  
00020     Mnemosyne is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024 
00025     You should have received a copy of the GNU General Public License
00026     along with this program; if not, write to the Free Software
00027     Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00028     Boston, MA  02110-1301, USA.
00029 
00030 ### END HEADER ###
00031 */
00032 
00047 #ifndef _M_STATS_H
00048 #define _M_STATS_H
00049 
00050 #include "result.h"
00051 
00052 
00054 #define FOREACH_STAT_XACT(ACTION)                                           \
00055   ACTION(aborts)                                                            \
00056 
00057 
00058 #ifdef _M_STATS_BUILD
00059 
00067 # define FOREACH_STAT(ACTION)                                                \
00068     FOREACH_STAT_XACT (ACTION)
00069 
00070 # define FOREACH_STATPROBE(ACTION)                                           \
00071     ACTION(XACT)
00072 
00073 # define FOREACH_VOIDSTATPROBE(ACTION)                                           
00074 
00075 
00076 #else /* !_M_STATS_BUILD */
00077 
00078 # define FOREACH_STAT(ACTION)          /* do nothing */
00079 # define FOREACH_STATPROBE(ACTION)     /* do nothing */
00080 # define FOREACH_VOIDSTATPROBE(ACTION) /* do nothing */
00081 
00082 #endif /* !_M_STATS_BUILD */
00083 
00084 typedef enum {
00085 #define STATENTRY(name) m_stats_##name##_stat,
00086         FOREACH_STAT (STATENTRY)
00087 #undef STATENTRY        
00088         m_stats_numofstats
00089 } m_stats_statentry_t; 
00090 
00091 typedef unsigned int m_stats_statcounter_t;
00092 typedef struct m_stats_threadstat_s m_stats_threadstat_t;
00093 typedef struct m_statsmgr_s m_statsmgr_t;
00094 typedef struct m_stats_statset_s m_stats_statset_t;
00095 typedef struct m_stats_stat_s m_stats_stat_t;
00096 
00097 
00099 struct m_stats_stat_s
00100 {
00101         m_stats_statcounter_t max;   
00102         m_stats_statcounter_t min;   
00103         m_stats_statcounter_t total; 
00104 }; 
00105 
00106 
00108 struct m_stats_statset_s {
00109         const char             *name;       
00110         m_stats_statcounter_t  count;       
00111         m_stats_stat_t         stats[m_stats_numofstats]; 
00112 }; 
00113 
00114 
00116 static inline
00117 void
00118 m_stats_statset_set_val(m_stats_statset_t *statset, 
00119                         m_stats_statentry_t entry,
00120                         m_stats_statcounter_t val)
00121 {
00122         statset->stats[entry].total = val;      
00123 }
00124 
00125 
00127 static inline
00128 m_stats_statcounter_t
00129 m_stats_statset_get_val(m_stats_statset_t *statset, 
00130                         m_stats_statentry_t entry)
00131 {
00132         return statset->stats[entry].total;
00133 }
00134 
00135 
00136 #define GENERATE_STATPROBES(stat_provider)                                     \
00137 static inline                                                                  \
00138 void                                                                           \
00139 m_stats_statset_increment_##stat_provider(m_statsmgr_t *statsmgr,              \
00140                                           m_stats_statset_t *statset,          \
00141                                           m_stats_statentry_t entry,           \
00142                                           m_stats_statcounter_t val)           \
00143 {                                                                              \
00144     if (statsmgr) {                                                            \
00145         m_stats_statset_set_val(statset,                                       \
00146                                 entry,                                         \
00147                                 m_stats_statset_get_val(statset, entry) + val);\
00148     }                                                                                                  \
00149 }                                                                                                                      \
00150                                                                                \
00151 static inline                                                                  \
00152 void                                                                           \
00153 m_stats_statset_decrement_##stat_provider(m_statsmgr_t *statsmgr,              \
00154                                           m_stats_statset_t *statset,          \
00155                                           m_stats_statentry_t entry,           \
00156                                           m_stats_statcounter_t val)           \
00157 {                                                                              \
00158         if (statsmgr) {                                                            \
00159         m_stats_statset_set_val(statset,                                       \
00160                                 entry,                                         \
00161                                 m_stats_statset_get_val(statset, entry) - val);\
00162     }                                                                                                  \
00163 }                                                                                                                      \
00164 
00165 
00166 #define GENERATE_VOIDSTATPROBES(stat_provider)                               \
00167 static inline                                                                \
00168 void                                                                         \
00169 m_stats_statset_increment_##stat_provider(m_statsmgr_t *statsmgr,            \
00170                                           m_stats_statset_t *statset,        \
00171                                           m_stats_statentry_t entry,         \
00172                                           m_stats_statcounter_t val)         \
00173 {                                                                            \
00174         return ;                                                                 \
00175 }                                                                                                                    \
00176                                                                              \
00177 static inline                                                                \
00178 void                                                                         \
00179 m_stats_statset_decrement_##stat_provider(m_statsmgr_t *statsmgr,            \
00180                                           m_stats_statset_t *statset,        \
00181                                           m_stats_statentry_t entry,         \
00182                                           m_stats_statcounter_t val)         \
00183 {                                                                            \
00184         return ;                                                                 \
00185 }                                                                                                                    \
00186 
00187 
00188 FOREACH_STATPROBE (GENERATE_STATPROBES)
00189 FOREACH_VOIDSTATPROBE (GENERATE_VOIDSTATPROBES)
00190 
00191 
00192 #define m_stats_statset_increment(statsmgr, statset, stat_provider, stat, val) \
00193   m_stats_statset_increment_##stat_provider(statsmgr,                          \
00194                                             statset,                           \
00195                                                                                         m_stats_##stat##_stat,             \
00196                                             val);
00197 
00198 #define m_stats_statset_decrement(statsmgr, statset, stat_provider, stat, val) \
00199   m_stats_statset_decrement_##stat_provider(statsmgr,                          \
00200                                             statset,                           \
00201                                             m_stats_##stat##_stat,             \
00202                                             val);
00203 
00204 
00205 m_result_t m_statsmgr_create(m_statsmgr_t **statsmgrp, char *output_file);
00206 m_result_t m_statsmgr_destroy(m_statsmgr_t **statsmgrp);
00207 m_result_t m_stats_threadstat_create(m_statsmgr_t *statsmgr, unsigned int tid, m_stats_threadstat_t **threadstatp);
00208 m_result_t m_stats_statset_create(m_stats_statset_t **statsetp);
00209 m_result_t m_stats_statset_destroy(m_stats_statset_t **statsetp);
00210 m_result_t m_stats_statset_init(m_stats_statset_t *statset, const char *name);
00211 void m_stats_print(m_statsmgr_t *statsmgr);
00212 
00213 #endif /* _M_STATS_H */

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7