src/core/stats.h

Go to the documentation of this file.
00001 
00008 #ifndef _TXC_STATS_H
00009 #define _TXC_STATS_H
00010 
00011 #include <misc/generic_types.h>
00012 #include <core/config.h>
00013 
00015 #define FOREACH_STAT_XCALL(ACTION)                                           \
00016   ACTION(x_close)                                                            \
00017   ACTION(x_create)                                                           \
00018   ACTION(x_dup)                                                              \
00019   ACTION(x_fsync)                                                            \
00020   ACTION(x_lseek)                                                            \
00021   ACTION(x_open)                                                             \
00022   ACTION(x_pipe)                                                             \
00023   ACTION(x_printf)                                                           \
00024   ACTION(x_read)                                                             \
00025   ACTION(x_read_pipe)                                                        \
00026   ACTION(x_recvmsg)                                                          \
00027   ACTION(x_rename)                                                           \
00028   ACTION(x_sendmsg)                                                          \
00029   ACTION(x_socket)                                                           \
00030   ACTION(x_unlink)                                                           \
00031   ACTION(x_write_ovr)                                                        \
00032   ACTION(x_write_ovr_ignore)                                                 \
00033   ACTION(x_write_pipe)                                                       \
00034   ACTION(x_write_seq)
00035 
00036 
00037 #ifdef _TXC_STATS_BUILD
00038 
00047 # define FOREACH_STAT(ACTION)                                                \
00048     FOREACH_STAT_XCALL (ACTION)
00049 
00050 # define FOREACH_STATPROBE(ACTION)                                           \
00051     ACTION(XCALL)
00052 
00053 # define FOREACH_VOIDSTATPROBE(ACTION)                                           
00054 
00055 
00056 #else /* !_TXC_STATS_BUILD */
00057 
00058 # define FOREACH_STAT(ACTION)          /* do nothing */
00059 # define FOREACH_STATPROBE(ACTION)     /* do nothing */
00060 # define FOREACH_VOIDSTATPROBE(ACTION) /* do nothing */
00061 
00062 #endif /* !_TXC_STATS_BUILD */
00063 
00064 typedef enum {
00065 #define STATENTRY(name) txc_stats_##name##_stat,
00066         FOREACH_STAT (STATENTRY)
00067 #undef STATENTRY        
00068         txc_stats_numofstats
00069 } txc_stats_statentry_t; 
00070 
00071 typedef unsigned int txc_stats_statcounter_t;
00072 typedef struct txc_stats_threadstat_s txc_stats_threadstat_t;
00073 typedef struct txc_statsmgr_s txc_statsmgr_t;
00074 typedef struct txc_stats_txstat_s txc_stats_txstat_t;
00075 typedef struct txc_stats_stat_s txc_stats_stat_t;
00076 
00077 /* 
00078  * Break the abstraction and make txc_stats_stat_s and txc_stats_txstat_s
00079  * visible to others to enable fast inline statistics processing. 
00080  */
00081 
00082 
00083 #include <core/tx.h>
00084 #include <core/txdesc.h>
00085 
00087 struct txc_stats_stat_s
00088 {
00089         txc_stats_statcounter_t max;   
00090         txc_stats_statcounter_t min;   
00091         txc_stats_statcounter_t total; 
00092 }; 
00093 
00094 
00096 struct txc_stats_txstat_s {
00097         const char               *srcloc_str; 
00098         txc_tx_srcloc_t          srcloc;      
00099         txc_stats_statcounter_t  count;       
00100         txc_stats_stat_t         total_stats[txc_stats_numofstats]; 
00101 }; 
00102 
00103 
00105 inline
00106 void
00107 txc_stats_txstat_set(txc_tx_t *txd, 
00108                      txc_stats_statentry_t entry,
00109                      txc_stats_statcounter_t val)
00110 {
00111         txd->txstat->total_stats[entry].total = val;    
00112 }
00113 
00114 
00116 inline
00117 txc_stats_statcounter_t
00118 txc_stats_txstat_get(txc_tx_t *txd, 
00119                      txc_stats_statentry_t entry)
00120 {
00121         return txd->txstat->total_stats[entry].total;
00122 }
00123 
00124 
00125 #define GENERATE_STATPROBES(stat_provider)                                   \
00126 inline                                                                       \
00127 void                                                                         \
00128 txc_stats_txstat_increment_##stat_provider(txc_tx_t *txd,                    \
00129                                            txc_stats_statentry_t entry,      \
00130                                            txc_stats_statcounter_t val)      \
00131 {                                                                            \
00132     if (txc_runtime_settings.statistics == TXC_BOOL_TRUE) {                  \
00133         txc_stats_txstat_set(txd,                                            \
00134                              entry,                                          \
00135                              txc_stats_txstat_get(txd, entry) + val);        \
00136     }                                                                                                \
00137 }                                                                                                                    \
00138                                                                              \
00139 inline                                                                       \
00140 void                                                                         \
00141 txc_stats_txstat_decrement_##stat_provider(txc_tx_t *txd,                    \
00142                                            txc_stats_statentry_t entry,      \
00143                                            txc_stats_statcounter_t val)      \
00144 {                                                                            \
00145         if (txc_runtime_settings.statistics == TXC_BOOL_TRUE) {                  \
00146         txc_stats_txstat_set(txd,                                            \
00147                              entry,                                          \
00148                              txc_stats_txstat_get(txd, entry) - val);        \
00149     }                                                                                                \
00150 }                                                                                                                    \
00151 
00152 
00153 
00154 #define GENERATE_VOIDSTATPROBES(stat_provider)                               \
00155 inline                                                                       \
00156 void                                                                         \
00157 txc_stats_txstat_increment_##stat_provider(txc_tx_t *txd,                    \
00158                                            txc_stats_statentry_t entry,      \
00159                                            txc_stats_statcounter_t val)      \
00160 {                                                                            \
00161         return ;                                                                 \
00162 }                                                                                                                    \
00163                                                                              \
00164 inline                                                                       \
00165 void                                                                         \
00166 txc_stats_txstat_increment_##stat_provider(txc_tx_t *txd,                    \
00167                                            txc_stats_statentry_t entry,      \
00168                                            txc_stats_statcounter_t val)      \
00169 {                                                                            \
00170         return ;                                                                 \
00171 }                                                                                                                    \
00172 
00173 
00174 FOREACH_STATPROBE (GENERATE_STATPROBES)
00175 FOREACH_VOIDSTATPROBE (GENERATE_VOIDSTATPROBES)
00176 
00177 
00178 #define txc_stats_txstat_increment(txd, stat_provider, stat, val)            \
00179   txc_stats_txstat_increment_##stat_provider(txd,                            \
00180                                              txc_stats_##stat##_stat,        \
00181                                              val);
00182 
00183 #define txc_stats_txstat_decrement(txd, stat_provider, stat, val)            \
00184   txc_stats_txstat_decrement_##stat_provider(txd,                            \
00185                                              txc_stats_##stat##_stat,        \
00186                                              val);
00187 
00188 
00189 txc_result_t txc_statsmgr_create(txc_statsmgr_t **statsmgrp);
00190 txc_result_t txc_statsmgr_destroy(txc_statsmgr_t **statsmgrp);
00191 txc_result_t txc_stats_threadstat_create(txc_statsmgr_t *statsmgr, txc_stats_threadstat_t **threadstatp, txc_tx_t *txd);
00192 txc_result_t txc_stats_txstat_create(txc_stats_txstat_t **txstatp);
00193 txc_result_t txc_stats_txstat_destroy(txc_stats_txstat_t **txstatp);
00194 txc_result_t txc_stats_txstat_init(txc_stats_txstat_t *txstat, const char *srcloc_str, txc_tx_srcloc_t *srcloc);
00195 void txc_stats_register_statsmgr_commit_action(txc_tx_t *txd);
00196 void txc_stats_register_statsmgr_undo_action(txc_tx_t *txd);
00197 void txc_stats_transaction_postbegin(txc_tx_t *txd);
00198 void txc_stats_print(txc_statsmgr_t *statsmgr);
00199 
00200 #endif /* _TXC_STATS_H */

Generated on Wed Dec 9 20:32:39 2009 for xCalls by  doxygen 1.4.7