00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014
00015 #include <string.h>
00016 #endif
00017
00018 #include "db_int.h"
00019 #include "dbinc/db_page.h"
00020 #include "dbinc/db_am.h"
00021 #include "dbinc/log.h"
00022
00023 #ifdef HAVE_STATISTICS
00024 static int __log_print_all __P((DB_ENV *, u_int32_t));
00025 static int __log_print_stats __P((DB_ENV *, u_int32_t));
00026 static int __log_stat __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
00027
00028
00029
00030
00031
00032
00033
00034 int
00035 __log_stat_pp(dbenv, statp, flags)
00036 DB_ENV *dbenv;
00037 DB_LOG_STAT **statp;
00038 u_int32_t flags;
00039 {
00040 DB_THREAD_INFO *ip;
00041 int ret;
00042
00043 PANIC_CHECK(dbenv);
00044 ENV_REQUIRES_CONFIG(dbenv,
00045 dbenv->lg_handle, "DB_ENV->log_stat", DB_INIT_LOG);
00046
00047 if ((ret = __db_fchk(dbenv,
00048 "DB_ENV->log_stat", flags, DB_STAT_CLEAR)) != 0)
00049 return (ret);
00050
00051 ENV_ENTER(dbenv, ip);
00052 REPLICATION_WRAP(dbenv, (__log_stat(dbenv, statp, flags)), ret);
00053 ENV_LEAVE(dbenv, ip);
00054 return (ret);
00055 }
00056
00057
00058
00059
00060
00061 static int
00062 __log_stat(dbenv, statp, flags)
00063 DB_ENV *dbenv;
00064 DB_LOG_STAT **statp;
00065 u_int32_t flags;
00066 {
00067 DB_LOG *dblp;
00068 DB_LOG_STAT *stats;
00069 LOG *lp;
00070 int ret;
00071
00072 *statp = NULL;
00073
00074 dblp = dbenv->lg_handle;
00075 lp = dblp->reginfo.primary;
00076
00077 if ((ret = __os_umalloc(dbenv, sizeof(DB_LOG_STAT), &stats)) != 0)
00078 return (ret);
00079
00080
00081 LOG_SYSTEM_LOCK(dbenv);
00082 *stats = lp->stat;
00083 if (LF_ISSET(DB_STAT_CLEAR))
00084 memset(&lp->stat, 0, sizeof(lp->stat));
00085
00086 stats->st_magic = lp->persist.magic;
00087 stats->st_version = lp->persist.version;
00088 stats->st_mode = lp->filemode;
00089 stats->st_lg_bsize = lp->buffer_size;
00090 stats->st_lg_size = lp->log_nsize;
00091
00092 __mutex_set_wait_info(dbenv, lp->mtx_region,
00093 &stats->st_region_wait, &stats->st_region_nowait);
00094 if (LF_ISSET(DB_STAT_CLEAR))
00095 __mutex_clear(dbenv, lp->mtx_region);
00096 stats->st_regsize = dblp->reginfo.rp->size;
00097
00098 stats->st_cur_file = lp->lsn.file;
00099 stats->st_cur_offset = lp->lsn.offset;
00100 stats->st_disk_file = lp->s_lsn.file;
00101 stats->st_disk_offset = lp->s_lsn.offset;
00102
00103 LOG_SYSTEM_UNLOCK(dbenv);
00104
00105 *statp = stats;
00106 return (0);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 int
00116 __log_stat_print_pp(dbenv, flags)
00117 DB_ENV *dbenv;
00118 u_int32_t flags;
00119 {
00120 DB_THREAD_INFO *ip;
00121 int ret;
00122
00123 PANIC_CHECK(dbenv);
00124 ENV_REQUIRES_CONFIG(dbenv,
00125 dbenv->lg_handle, "DB_ENV->log_stat_print", DB_INIT_LOG);
00126
00127 if ((ret = __db_fchk(dbenv, "DB_ENV->log_stat_print",
00128 flags, DB_STAT_ALL | DB_STAT_CLEAR)) != 0)
00129 return (ret);
00130
00131 ENV_ENTER(dbenv, ip);
00132 REPLICATION_WRAP(dbenv, (__log_stat_print(dbenv, flags)), ret);
00133 ENV_LEAVE(dbenv, ip);
00134 return (ret);
00135 }
00136
00137
00138
00139
00140
00141
00142
00143 int
00144 __log_stat_print(dbenv, flags)
00145 DB_ENV *dbenv;
00146 u_int32_t flags;
00147 {
00148 u_int32_t orig_flags;
00149 int ret;
00150
00151 orig_flags = flags;
00152 LF_CLR(DB_STAT_CLEAR);
00153 if (flags == 0 || LF_ISSET(DB_STAT_ALL)) {
00154 ret = __log_print_stats(dbenv, orig_flags);
00155 if (flags == 0 || ret != 0)
00156 return (ret);
00157 }
00158
00159 if (LF_ISSET(DB_STAT_ALL) &&
00160 (ret = __log_print_all(dbenv, orig_flags)) != 0)
00161 return (ret);
00162
00163 return (0);
00164 }
00165
00166
00167
00168
00169
00170 static int
00171 __log_print_stats(dbenv, flags)
00172 DB_ENV *dbenv;
00173 u_int32_t flags;
00174 {
00175 DB_LOG_STAT *sp;
00176 int ret;
00177
00178 if ((ret = __log_stat(dbenv, &sp, flags)) != 0)
00179 return (ret);
00180
00181 if (LF_ISSET(DB_STAT_ALL))
00182 __db_msg(dbenv, "Default logging region information:");
00183 STAT_HEX("Log magic number", sp->st_magic);
00184 STAT_ULONG("Log version number", sp->st_version);
00185 __db_dlbytes(dbenv, "Log record cache size",
00186 (u_long)0, (u_long)0, (u_long)sp->st_lg_bsize);
00187 __db_msg(dbenv, "%#o\tLog file mode", sp->st_mode);
00188 if (sp->st_lg_size % MEGABYTE == 0)
00189 __db_msg(dbenv, "%luMb\tCurrent log file size",
00190 (u_long)sp->st_lg_size / MEGABYTE);
00191 else if (sp->st_lg_size % 1024 == 0)
00192 __db_msg(dbenv, "%luKb\tCurrent log file size",
00193 (u_long)sp->st_lg_size / 1024);
00194 else
00195 __db_msg(dbenv, "%lu\tCurrent log file size",
00196 (u_long)sp->st_lg_size);
00197 __db_dl(dbenv, "Records entered into the log", (u_long)sp->st_record);
00198 __db_dlbytes(dbenv, "Log bytes written",
00199 (u_long)0, (u_long)sp->st_w_mbytes, (u_long)sp->st_w_bytes);
00200 __db_dlbytes(dbenv, "Log bytes written since last checkpoint",
00201 (u_long)0, (u_long)sp->st_wc_mbytes, (u_long)sp->st_wc_bytes);
00202 __db_dl(dbenv, "Total log file I/O writes", (u_long)sp->st_wcount);
00203 __db_dl(dbenv, "Total log file I/O writes due to overflow",
00204 (u_long)sp->st_wcount_fill);
00205 __db_dl(dbenv, "Total log file flushes", (u_long)sp->st_scount);
00206 __db_dl(dbenv, "Total log file I/O reads", (u_long)sp->st_rcount);
00207 STAT_ULONG("Current log file number", sp->st_cur_file);
00208 STAT_ULONG("Current log file offset", sp->st_cur_offset);
00209 STAT_ULONG("On-disk log file number", sp->st_disk_file);
00210 STAT_ULONG("On-disk log file offset", sp->st_disk_offset);
00211
00212 __db_dl(dbenv,
00213 "Maximum commits in a log flush", (u_long)sp->st_maxcommitperflush);
00214 __db_dl(dbenv,
00215 "Minimum commits in a log flush", (u_long)sp->st_mincommitperflush);
00216
00217 __db_dlbytes(dbenv, "Log region size",
00218 (u_long)0, (u_long)0, (u_long)sp->st_regsize);
00219 __db_dl_pct(dbenv,
00220 "The number of region locks that required waiting",
00221 (u_long)sp->st_region_wait, DB_PCT(sp->st_region_wait,
00222 sp->st_region_wait + sp->st_region_nowait), NULL);
00223
00224 __os_ufree(dbenv, sp);
00225
00226 return (0);
00227 }
00228
00229
00230
00231
00232
00233 static int
00234 __log_print_all(dbenv, flags)
00235 DB_ENV *dbenv;
00236 u_int32_t flags;
00237 {
00238 static const FN fn[] = {
00239 { DBLOG_RECOVER, "DBLOG_RECOVER" },
00240 { DBLOG_FORCE_OPEN, "DBLOG_FORCE_OPEN" },
00241 { 0, NULL }
00242 };
00243 DB_LOG *dblp;
00244 LOG *lp;
00245
00246 dblp = dbenv->lg_handle;
00247 lp = (LOG *)dblp->reginfo.primary;
00248
00249 LOG_SYSTEM_LOCK(dbenv);
00250
00251 __db_print_reginfo(dbenv, &dblp->reginfo, "Log");
00252
00253 __db_msg(dbenv, "%s", DB_GLOBAL(db_line));
00254 __db_msg(dbenv, "DB_LOG handle information:");
00255 __mutex_print_debug_single(
00256 dbenv, "DB_LOG handle mutex", dblp->mtx_dbreg, flags);
00257 STAT_ULONG("Log file name", dblp->lfname);
00258 __db_print_fh(dbenv, "Log file handle", dblp->lfhp, flags);
00259 __db_prflags(dbenv, NULL, dblp->flags, fn, NULL, "\tFlags");
00260
00261 __db_msg(dbenv, "%s", DB_GLOBAL(db_line));
00262 __db_msg(dbenv, "LOG handle information:");
00263 __mutex_print_debug_single(
00264 dbenv, "LOG region mutex", lp->mtx_region, flags);
00265 __mutex_print_debug_single(
00266 dbenv, "File name list mutex", lp->mtx_filelist, flags);
00267
00268 STAT_HEX("persist.magic", lp->persist.magic);
00269 STAT_ULONG("persist.version", lp->persist.version);
00270 __db_dlbytes(dbenv,
00271 "persist.log_size", (u_long)0, (u_long)0, lp->persist.log_size);
00272 STAT_FMT("log file permissions mode", "%#lo", u_long, lp->filemode);
00273 STAT_LSN("current file offset LSN", &lp->lsn);
00274 STAT_LSN("first buffer byte LSN", &lp->lsn);
00275 STAT_ULONG("current buffer offset", lp->b_off);
00276 STAT_ULONG("current file write offset", lp->w_off);
00277 STAT_ULONG("length of last record", lp->len);
00278 STAT_LONG("log flush in progress", lp->in_flush);
00279 __mutex_print_debug_single(
00280 dbenv, "Log flush mutex", lp->mtx_flush, flags);
00281
00282 STAT_LSN("last sync LSN", &lp->s_lsn);
00283
00284
00285
00286
00287
00288
00289 STAT_LSN("cached checkpoint LSN", &lp->cached_ckp_lsn);
00290
00291 __db_dlbytes(dbenv,
00292 "log buffer size", (u_long)0, (u_long)0, lp->buffer_size);
00293 __db_dlbytes(dbenv,
00294 "log file size", (u_long)0, (u_long)0, lp->log_size);
00295 __db_dlbytes(dbenv,
00296 "next log file size", (u_long)0, (u_long)0, lp->log_nsize);
00297
00298 STAT_ULONG("transactions waiting to commit", lp->ncommit);
00299 STAT_LSN("LSN of first commit", &lp->t_lsn);
00300
00301 LOG_SYSTEM_UNLOCK(dbenv);
00302
00303 return (0);
00304 }
00305
00306 #else
00307
00308 int
00309 __log_stat_pp(dbenv, statp, flags)
00310 DB_ENV *dbenv;
00311 DB_LOG_STAT **statp;
00312 u_int32_t flags;
00313 {
00314 COMPQUIET(statp, NULL);
00315 COMPQUIET(flags, 0);
00316
00317 return (__db_stat_not_built(dbenv));
00318 }
00319
00320 int
00321 __log_stat_print_pp(dbenv, flags)
00322 DB_ENV *dbenv;
00323 u_int32_t flags;
00324 {
00325 COMPQUIET(flags, 0);
00326
00327 return (__db_stat_not_built(dbenv));
00328 }
00329 #endif