usermode/library/mtm/src/stats.h

Go to the documentation of this file.
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 
00040 #ifndef _M_STATS_H
00041 #define _M_STATS_H
00042 
00043 #include "result.h"
00044 
00045 /* 
00046  * TODO: Currently if statistics support is not built we get compilation errors
00047  * of undefined statistics when calling 'm_stats_statset_increment' family of
00048  * functions.  The currernt workaround is to wrap each call into _M_STATS_BUILD
00049  * but that's kind of ugly. 
00050  *
00051  * TODO: Make the statistics report output prettier by parsing the source location
00052  *
00053  * TODO: Currently if stats.[c|h] are used in multiple libraries we get symbol 
00054  * collision problems. Either make symbols hidden outside the library, or MACROFY 
00055  * them to add a per module extension, or make them static.
00056  */
00057 
00059 #define FOREACH_STAT_XACT(ACTION)                                           \
00060   ACTION(aborts)                                                            \
00061   ACTION(writes)                                                            \
00062   ACTION(writes_distinct)                                                   \
00063   ACTION(nvwrites)                                                          \
00064   ACTION(nvwrites_distinct)                                                 \
00065   ACTION(vwrites)                                                           \
00066   ACTION(vwrites_distinct)                                                  \
00067   ACTION(wbflush)                                                            
00068 
00069 
00070 #ifdef _M_STATS_BUILD
00071 
00079 # define FOREACH_STAT(ACTION)                                                \
00080     FOREACH_STAT_XACT (ACTION)
00081 
00082 # define FOREACH_STATPROBE(ACTION)                                           \
00083     ACTION(XACT)
00084 
00085 # define FOREACH_VOIDSTATPROBE(ACTION)                                           
00086 
00087 
00088 #else /* !_M_STATS_BUILD */
00089 
00090 # define FOREACH_STAT(ACTION)          /* do nothing */
00091 # define FOREACH_STATPROBE(ACTION)     /* do nothing */
00092 # define FOREACH_VOIDSTATPROBE(ACTION) /* do nothing */
00093 
00094 #endif /* !_M_STATS_BUILD */
00095 
00096 typedef enum {
00097 #define STATENTRY(name) m_stats_##name##_stat,
00098         FOREACH_STAT (STATENTRY)
00099 #undef STATENTRY        
00100         m_stats_numofstats
00101 } m_stats_statentry_t; 
00102 
00103 typedef unsigned int m_stats_statcounter_t;
00104 typedef struct m_stats_threadstat_s m_stats_threadstat_t;
00105 typedef struct m_statsmgr_s m_statsmgr_t;
00106 typedef struct m_stats_statset_s m_stats_statset_t;
00107 typedef struct m_stats_stat_s m_stats_stat_t;
00108 
00109 
00111 struct m_stats_stat_s
00112 {
00113         m_stats_statcounter_t max;   
00114         m_stats_statcounter_t min;   
00115         m_stats_statcounter_t total; 
00116 }; 
00117 
00118 
00120 struct m_stats_statset_s {
00121         const char             *name;       
00122         m_stats_statcounter_t  count;       
00123         m_stats_stat_t         stats[m_stats_numofstats]; 
00124 }; 
00125 
00126 
00128 static inline
00129 void
00130 m_stats_statset_set_val(m_stats_statset_t *statset, 
00131                         m_stats_statentry_t entry,
00132                         m_stats_statcounter_t val)
00133 {
00134         statset->stats[entry].total = val;      
00135 }
00136 
00137 
00139 static inline
00140 m_stats_statcounter_t
00141 m_stats_statset_get_val(m_stats_statset_t *statset, 
00142                         m_stats_statentry_t entry)
00143 {
00144         return statset->stats[entry].total;
00145 }
00146 
00147 
00148 #define GENERATE_STATPROBES(stat_provider)                                     \
00149 static inline                                                                  \
00150 void                                                                           \
00151 m_stats_statset_increment_##stat_provider(m_statsmgr_t *statsmgr,              \
00152                                           m_stats_statset_t *statset,          \
00153                                           m_stats_statentry_t entry,           \
00154                                           m_stats_statcounter_t val)           \
00155 {                                                                              \
00156     if (statsmgr) {                                                            \
00157         m_stats_statset_set_val(statset,                                       \
00158                                 entry,                                         \
00159                                 m_stats_statset_get_val(statset, entry) + val);\
00160     }                                                                                                  \
00161 }                                                                                                                      \
00162                                                                                \
00163 static inline                                                                  \
00164 void                                                                           \
00165 m_stats_statset_decrement_##stat_provider(m_statsmgr_t *statsmgr,              \
00166                                           m_stats_statset_t *statset,          \
00167                                           m_stats_statentry_t entry,           \
00168                                           m_stats_statcounter_t val)           \
00169 {                                                                              \
00170         if (statsmgr) {                                                            \
00171         m_stats_statset_set_val(statset,                                       \
00172                                 entry,                                         \
00173                                 m_stats_statset_get_val(statset, entry) - val);\
00174     }                                                                                                  \
00175 }                                                                                                                      \
00176 
00177 
00178 #define GENERATE_VOIDSTATPROBES(stat_provider)                               \
00179 static inline                                                                \
00180 void                                                                         \
00181 m_stats_statset_increment_##stat_provider(m_statsmgr_t *statsmgr,            \
00182                                           m_stats_statset_t *statset,        \
00183                                           m_stats_statentry_t entry,         \
00184                                           m_stats_statcounter_t val)         \
00185 {                                                                            \
00186         return ;                                                                 \
00187 }                                                                                                                    \
00188                                                                              \
00189 static inline                                                                \
00190 void                                                                         \
00191 m_stats_statset_decrement_##stat_provider(m_statsmgr_t *statsmgr,            \
00192                                           m_stats_statset_t *statset,        \
00193                                           m_stats_statentry_t entry,         \
00194                                           m_stats_statcounter_t val)         \
00195 {                                                                            \
00196         return ;                                                                 \
00197 }                                                                                                                    \
00198 
00199 
00200 FOREACH_STATPROBE (GENERATE_STATPROBES)
00201 FOREACH_VOIDSTATPROBE (GENERATE_VOIDSTATPROBES)
00202 
00203 
00204 #define m_stats_statset_increment(statsmgr, statset, stat_provider, stat, val) \
00205   m_stats_statset_increment_##stat_provider(statsmgr,                          \
00206                                             statset,                           \
00207                                                                                         m_stats_##stat##_stat,             \
00208                                             val);
00209 
00210 #define m_stats_statset_decrement(statsmgr, statset, stat_provider, stat, val) \
00211   m_stats_statset_decrement_##stat_provider(statsmgr,                          \
00212                                             statset,                           \
00213                                             m_stats_##stat##_stat,             \
00214                                             val);
00215 
00216 
00217 m_result_t m_statsmgr_create(m_statsmgr_t **statsmgrp, char *output_file);
00218 m_result_t m_statsmgr_destroy(m_statsmgr_t **statsmgrp);
00219 m_result_t m_stats_threadstat_create(m_statsmgr_t *statsmgr, unsigned int tid, m_stats_threadstat_t **threadstatp);
00220 m_result_t m_stats_statset_create(m_stats_statset_t **statsetp);
00221 m_result_t m_stats_statset_destroy(m_stats_statset_t **statsetp);
00222 m_result_t m_stats_statset_init(m_stats_statset_t *statset, const char *name);
00223 void m_stats_threadstat_aggregate(m_stats_threadstat_t *threadstat, m_stats_statset_t *source_statset);
00224 void m_stats_print(m_statsmgr_t *statsmgr);
00225 
00226 #endif /* _M_STATS_H */

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