Beispiel #1
0
        /*
        ** Usage:   btree_pager_stats ID
        **
        ** Returns pager statistics
        */
        static int btree_pager_stats(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            Btree pBt;
            int   i;

            int[] a;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());

            /* Normally in this file, with a b-tree handle opened using the
            ** [btree_open] command it is safe to call sqlite3BtreeEnter() directly.
            ** But this function is sometimes called with a btree handle obtained
            ** from an open SQLite connection (using [btree_from_db]). In this case
            ** we need to obtain the mutex for the controlling SQLite handle before
            ** it is safe to call sqlite3BtreeEnter().
            */
            sqlite3_mutex_enter(pBt.db.mutex);

            sqlite3BtreeEnter(pBt);
            a = sqlite3PagerStats(sqlite3BtreePager(pBt));
            for (i = 0; i < 11; i++)
            {
                string[] zName = new string[] {
                    "ref", "page", "max", "size", "state", "err",
                    "hit", "miss", "ovfl", "read", "write"
                };
                string zBuf = "";//char zBuf[100];
                TCL.Tcl_AppendElement(interp, zName[i]);
                sqlite3_snprintf(100, ref zBuf, "%d", a[i]);
                TCL.Tcl_AppendElement(interp, zBuf);
            }
            sqlite3BtreeLeave(pBt);
            /* Release the mutex on the SQLite handle that controls this b-tree */
            sqlite3_mutex_leave(pBt.db.mutex);
            return(TCL.TCL_OK);
        }