Exemple #1
0
        public bool statsTests(
            string sDbName,
            DbSystem dbSystem)
        {
            Db                  db    = null;
            DbSystemStats       stats = null;
            uint                uiNumDatabases;
            uint                uiStartTime;
            uint                uiStopTime;
            CS_XFLM_DB_STATS    dbStats    = null;
            CS_XFLM_LFILE_STATS lFileStats = null;

            beginTest("Start statistics");

            try
            {
                dbSystem.startStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "starting statistics");
                return(false);
            }
            endTest(false, true);

            // Open a database to make some statistics happen

            beginTest("Open Database Test (" + sDbName + ")");

            try
            {
                db = dbSystem.dbOpen(sDbName, null, null, null, false);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "opening database");
                return(false);
            }
            if (db != null)
            {
                db.close();
                db = null;
            }
            endTest(false, true);

            // Stop collecting statistics

            beginTest("Stop statistics");

            try
            {
                dbSystem.stopStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "stopping statistics");
                return(false);
            }
            endTest(false, true);

            // Get statistics

            beginTest("Get statistics");

            try
            {
                stats = dbSystem.getStats();
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "getting statistics");
                return(false);
            }
            endTest(false, true);

            // Get general statistics

            beginTest("Get general statistics");

            try
            {
                stats.getGeneralStats(out uiNumDatabases, out uiStartTime,
                                      out uiStopTime);
            }
            catch (XFlaimException ex)
            {
                endTest(false, ex, "getting statistics");
                return(false);
            }
            endTest(false, true);
            printUIntStat(0, "Databases", uiNumDatabases);
            printUIntStat(0, "Start Time", uiStartTime);
            printUIntStat(0, "Stop Time", uiStopTime);

            // Get Database statistics

            for (uint uiLoop = 0; uiLoop < uiNumDatabases; uiLoop++)
            {
                beginTest("Get database statistics for DB#" + uiLoop);

                try
                {
                    dbStats = stats.getDbStats(uiLoop, dbStats);
                }
                catch (XFlaimException ex)
                {
                    endTest(false, ex, "getting database statistics");
                    return(false);
                }
                endTest(false, true);
                printStrStat(0, "Database Name", dbStats.sDbName);
                printUIntStat(0, "Logical File Count", dbStats.uiNumLFiles);
                System.Console.WriteLine("Read Transactions");
                printCountTimeStat(1, "Committed Transactions", dbStats.ReadTransStats.CommittedTrans);
                printCountTimeStat(1, "Aborted Transactions", dbStats.ReadTransStats.AbortedTrans);
                System.Console.WriteLine("Update Transactions");
                printCountTimeStat(1, "Committed Transactions", dbStats.UpdateTransStats.CommittedTrans);
                printCountTimeStat(1, "Aborted Transactions", dbStats.UpdateTransStats.AbortedTrans);
                printCountTimeStat(1, "Group Completes", dbStats.UpdateTransStats.GroupCompletes);
                printULongStat(1, "Group Finished", dbStats.UpdateTransStats.ulGroupFinished);
                printBlockIOStats(0, "LFH Block Stats", dbStats.LFHBlockStats);
                printBlockIOStats(0, "Avail Block Stats", dbStats.AvailBlockStats);
                printDiskIOStats(0, "Database Header Writes", dbStats.DbHdrWrites);
                printDiskIOStats(0, "Log Block Writes", dbStats.LogBlockWrites);
                printDiskIOStats(0, "Log Block Restores", dbStats.LogBlockRestores);
                printDiskIOStats(0, "Log Block Reads", dbStats.LogBlockReads);
                printUIntStat(0, "Log Block Checksum Errors", dbStats.uiLogBlockChkErrs);
                printUIntStat(0, "Read Errors", dbStats.uiReadErrors);
                printCountTimeStat(0, "No Locks", dbStats.LockStats.NoLocks);
                printCountTimeStat(0, "Waiting For Lock", dbStats.LockStats.WaitingForLock);
                printCountTimeStat(0, "Held Lock", dbStats.LockStats.HeldLock);

                for (uint uiLoop2 = 0; uiLoop2 < dbStats.uiNumLFiles; uiLoop2++)
                {
                    beginTest("  Get database statistics for DB#" + uiLoop + ", LFile#" + uiLoop2);

                    try
                    {
                        lFileStats = stats.getLFileStats(uiLoop, uiLoop2, lFileStats);
                    }
                    catch (XFlaimException ex)
                    {
                        endTest(false, ex, "getting logical file statistics");
                        return(false);
                    }
                    endTest(false, true);
                    System.Console.WriteLine("  LOGICAL FILE {0} ({1})",
                                             lFileStats.uiLFileNum, lFileStats.eLfType);
                    printBlockIOStats(2, "Root Block Stats", lFileStats.RootBlockStats);
                    printBlockIOStats(2, "Middle Block Stats", lFileStats.MiddleBlockStats);
                    printBlockIOStats(2, "Leaf Block Stats", lFileStats.LeafBlockStats);
                    printULongStat(2, "Block Splits", lFileStats.ulBlockSplits);
                    printULongStat(2, "Block Combines", lFileStats.ulBlockCombines);
                }
            }

            return(true);
        }