00001 /*<std-header orig-src='shore' incl-file-exclusion='SMSTATS_H'> 00002 00003 $Id: smstats.h,v 1.36 2010/09/21 14:26:20 nhall Exp $ 00004 00005 SHORE -- Scalable Heterogeneous Object REpository 00006 00007 Copyright (c) 1994-99 Computer Sciences Department, University of 00008 Wisconsin -- Madison 00009 All Rights Reserved. 00010 00011 Permission to use, copy, modify and distribute this software and its 00012 documentation is hereby granted, provided that both the copyright 00013 notice and this permission notice appear in all copies of the 00014 software, derivative works or modified versions, and any portions 00015 thereof, and that both notices appear in supporting documentation. 00016 00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY 00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS 00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND 00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 00021 00022 This software was developed with support by the Advanced Research 00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by 00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518. 00025 Further funding for this work was provided by DARPA through 00026 Rome Research Laboratory Contract No. F30602-97-2-0247. 00027 00028 */ 00029 00030 #ifndef SMSTATS_H 00031 #define SMSTATS_H 00032 00033 #include "w_defines.h" 00034 00035 /* -- do not edit anything above this line -- </std-header>*/ 00036 00037 // This file is included in sm.h in the middle of the class ss_m 00038 // declaration. Member functions are defined in sm.cpp 00039 00040 00041 /**\addtogroup SSMSTATS 00042 * 00043 * The storage manager API allows a server to gather statistics on 00044 * a per-transaction basis or on a global basis. 00045 * These counters are not segregated by the semantics of the counters. Rather, 00046 * they are segregated by the thread that performed the action being measured. 00047 * In other words, an action is attributed to a transaction if it was 00048 * performed by a thread while attached to that transaction. 00049 * This means that some actions, such as writing pages to disk, might not 00050 * be attributable to a transaction even though they are in some 00051 * sense logically 00052 * associated with that transaction. If the write is performed by a 00053 * page writer (background thread), it will show up in the global statistics 00054 * but not in any per-transaction statistics. On the other hand, if a write 00055 * is performed by ss_m::set_store_property (which flushes to disk 00056 * all pages for the store thus changed) it will be attributed to the 00057 * transaction. 00058 * 00059 * All statistics are collected on a per-smthread_t basis 00060 * (thus avoiding expensive atomic updates on a per-counter basis). 00061 * Each smthread has its own 00062 * local sm_stats_info_t structure for these statistics. 00063 * Any time this structure is cleared, 00064 * its contents are added to a single global statistics structure 00065 * (protected by a mutex) before it is cleared. 00066 * The clearing happens in two circumstances: 00067 * - when an smthread_t is destroyed (in its destructor) 00068 * - when an attached instrumented transaction collects the statistics from 00069 * the thread (see below). 00070 * 00071 * Thus, the single global statistics structure's contents reflect the 00072 * activities of finished threads and of instrumented transactions' collected 00073 * statistics, and all other activities are reflected in per-thread 00074 * statistics structures. 00075 * 00076 * A value-added server may collect the global statistics with the 00077 * ss_m::gather_stats method. This method first adds together all the 00078 * per-thread statistics, adds in the global statistics, and returns. 00079 * The global statistics cannot be reset, and, indeed, they survive 00080 * the storage manager so that they can be gathered after the 00081 * storage manager shuts down. This means that to determine incremental 00082 * statistics, the value-added server has to keep the prior copy of 00083 * statistics and diff the current statistics from the prior statistics. 00084 * The sm_stats_info_t has a difference operator to make this easy. 00085 * \attention Gathering the per-thread statistics from running threads is 00086 * not atomic; in other words, if threads are updating their counters 00087 * while the gathering of their counters is going on, some counts may 00088 * be missed (become stale). (In any case, they will be stale soon 00089 * after the statistics are gathered.) 00090 * 00091 * A transaction must be instrumented to collect its statistics. 00092 * 00093 * Instrumenting a transaction 00094 * consists in allocating a structure in which to store the collected 00095 * statistics, and passing in that structure to the storage manager using 00096 * using the variants of begin_xct, commit_xct, etc that take 00097 * an argument of this type. 00098 * 00099 * When a transaction is detached from a thread, 00100 * the statistics it gathered up to that point by the thread are 00101 * added to the per-transaction statistics, and the thread statistics are 00102 * cleared so they don't get over-counted. 00103 * 00104 * A server may gather the per-transaction statistics for the 00105 * attached running transaction with 00106 * ss_m::gather_xct_stats. 00107 * 00108 * A server may choose to reset the per-transaction statistics when it 00109 * gathers them; this facilitates gathering incremental statistics. 00110 * These counters aren't lost to the world, since their values were 00111 * added to the global statistics before they were gathered in the first place. 00112 * 00113 * \attention The per-transaction statistics structure is not 00114 * protected against concurrently-attached threads, so 00115 * its values are best collected and reset when the server 00116 * knows that only one thread is attached to the 00117 * transaction when making the call. 00118 */ 00119 00120 /**\brief Statistics (counters) for most of the storage manager. 00121 * \details 00122 * This structure holds most of the storage manager's statictics, 00123 * those not specific to the buffer-manager's hash table. 00124 * Those counters are in bf_htab_stats_t. 00125 */ 00126 class sm_stats_t { 00127 public: 00128 void compute(); 00129 #include "sm_stats_t_struct_gen.h" 00130 }; 00131 00132 /**\brief Statistics (counters) for the buffer-manager hash table. 00133 * \details 00134 * This structure holds counters 00135 * specific to the buffer-manager's hash table. 00136 * Although it is not necessary, 00137 * they are separated from the rest for ease of unit-testing. 00138 */ 00139 class bf_htab_stats_t { 00140 public: 00141 void compute(); 00142 #include "bf_htab_stats_t_struct_gen.h" 00143 }; 00144 00145 /**\brief Storage Manager Statistics 00146 * 00147 * The storage manager is instrumented; it collects the statistics 00148 * (mostly counters) that are described in *_stats.dat files (input 00149 * files to Perl scripts). 00150 * These statistics are incremented in per-thread structures, which 00151 * are gathered and available to the value-added server 00152 * under various circumstances, described in \ref SSMSTATS. 00153 */ 00154 class sm_stats_info_t { 00155 public: 00156 bf_htab_stats_t bfht; 00157 sm_stats_t sm; 00158 void compute() { 00159 bfht.compute(); 00160 sm.compute(); 00161 } 00162 friend ostream& operator<<(ostream&, const sm_stats_info_t& s); 00163 sm_stats_info_t() { 00164 memset(this, '\0', sizeof (*this)); 00165 } 00166 }; 00167 00168 extern sm_stats_info_t &operator+=(sm_stats_info_t &s, const sm_stats_info_t &t); 00169 extern sm_stats_info_t &operator-=(sm_stats_info_t &s, const sm_stats_info_t &t); 00170 00171 /**\brief Configuration Information 00172 * \details 00173 * The method ss_m::config_info lets a server to 00174 * pick up some useful configuration 00175 * information from the storage manager. 00176 * Several of these data depend on the compile-time page size; some 00177 * depend on run-time options. 00178 */ 00179 struct sm_config_info_t { 00180 /**\brief compile-time constant. Settable in 00181 * \code shore.def \endcode. 00182 * Default is 8K. 00183 */ 00184 u_long page_size; // bytes in page, including all headers 00185 /**\brief Maximum size of the first small record on a page */ 00186 u_long max_small_rec; // maximum number of bytes in a "small" 00187 // (ie. on one page) record. This is 00188 // align(header_len)+align(body_len). 00189 u_long small_rec_overhead; // size of rectag_t + sizeof slot_t 00190 /**\brief Data space available on a page of a large record */ 00191 u_long lg_rec_page_space; 00192 /**\brief Size in KB of buffer pool */ 00193 u_long buffer_pool_size; // buffer pool size in kilo-bytes 00194 /**\brief Largest permissible size in bytes of an index entry 00195 * (key,value pair) */ 00196 u_long max_btree_entry_size; 00197 /**\brief Number of extent links on an extent page */ 00198 u_long exts_on_page; 00199 /**\brief Number of pages per extent (compile-time constant) 00200 * \note The storage manager has not been tested with any value but 8. 00201 */ 00202 u_long pages_per_ext; 00203 00204 /**\brief True if logging is on. 00205 * \note The multi-threaded storage manager has not been 00206 * tested with logging turned off, so turning off logging is 00207 * not supported in this release. 00208 */ 00209 bool logging; 00210 00211 friend ostream& operator<<(ostream&, const sm_config_info_t& s); 00212 }; 00213 00214 /*<std-footer incl-file-exclusion='SMSTATS_H'> -- do not edit anything below this line -- */ 00215 00216 #endif /*</std-footer>*/