status.c

Go to the documentation of this file.
00001 /*
00002 ** 2008 June 18
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 *************************************************************************
00012 **
00013 ** This module implements the sqlite3_status() interface and related
00014 ** functionality.
00015 **
00016 ** $Id: status.c,v 1.9 2008/09/02 00:52:52 drh Exp $
00017 */
00018 #include "sqliteInt.h"
00019 
00020 /*
00021 ** Variables in which to record status information.
00022 */
00023 typedef struct sqlite3StatType sqlite3StatType;
00024 static SQLITE_WSD struct sqlite3StatType {
00025   int nowValue[9];         /* Current value */
00026   int mxValue[9];          /* Maximum value */
00027 } sqlite3Stat = { {0,}, {0,} };
00028 
00029 
00030 /* The "wsdStat" macro will resolve to the status information
00031 ** state vector.  If writable static data is unsupported on the target,
00032 ** we have to locate the state vector at run-time.  In the more common
00033 ** case where writable static data is supported, wsdStat can refer directly
00034 ** to the "sqlite3Stat" state vector declared above.
00035 */
00036 #ifdef SQLITE_OMIT_WSD
00037 # define wsdStatInit  sqlite3StatType *x = &GLOBAL(sqlite3StatType,sqlite3Stat)
00038 # define wsdStat x[0]
00039 #else
00040 # define wsdStatInit
00041 # define wsdStat sqlite3Stat
00042 #endif
00043 
00044 /*
00045 ** Return the current value of a status parameter.
00046 */
00047 int sqlite3StatusValue(int op){
00048   wsdStatInit;
00049   assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
00050   return wsdStat.nowValue[op];
00051 }
00052 
00053 /*
00054 ** Add N to the value of a status record.  It is assumed that the
00055 ** caller holds appropriate locks.
00056 */
00057 void sqlite3StatusAdd(int op, int N){
00058   wsdStatInit;
00059   assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
00060   wsdStat.nowValue[op] += N;
00061   if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
00062     wsdStat.mxValue[op] = wsdStat.nowValue[op];
00063   }
00064 }
00065 
00066 /*
00067 ** Set the value of a status to X.
00068 */
00069 void sqlite3StatusSet(int op, int X){
00070   wsdStatInit;
00071   assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
00072   wsdStat.nowValue[op] = X;
00073   if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
00074     wsdStat.mxValue[op] = wsdStat.nowValue[op];
00075   }
00076 }
00077 
00078 /*
00079 ** Query status information.
00080 **
00081 ** This implementation assumes that reading or writing an aligned
00082 ** 32-bit integer is an atomic operation.  If that assumption is not true,
00083 ** then this routine is not threadsafe.
00084 */
00085 int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
00086   wsdStatInit;
00087   if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
00088     return SQLITE_MISUSE;
00089   }
00090   *pCurrent = wsdStat.nowValue[op];
00091   *pHighwater = wsdStat.mxValue[op];
00092   if( resetFlag ){
00093     wsdStat.mxValue[op] = wsdStat.nowValue[op];
00094   }
00095   return SQLITE_OK;
00096 }
00097 
00098 /*
00099 ** Query status information for a single database connection
00100 */
00101 int sqlite3_db_status(
00102   sqlite3 *db,          /* The database connection whose status is desired */
00103   int op,               /* Status verb */
00104   int *pCurrent,        /* Write current value here */
00105   int *pHighwater,      /* Write high-water mark here */
00106   int resetFlag         /* Reset high-water mark if true */
00107 ){
00108   switch( op ){
00109     case SQLITE_DBSTATUS_LOOKASIDE_USED: {
00110       *pCurrent = db->lookaside.nOut;
00111       *pHighwater = db->lookaside.mxOut;
00112       if( resetFlag ){
00113         db->lookaside.mxOut = db->lookaside.nOut;
00114       }
00115       break;
00116     }
00117     default: {
00118       return SQLITE_ERROR;
00119     }
00120   }
00121   return SQLITE_OK;
00122 }

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1