From 1b2c0b92423d19ab22c4502bd240ee51b809d860 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Feb 2013 23:37:44 -0800 Subject: [PATCH] Add database memory usage to 'get_counts' output. --- src/cpp/database/SqliteDatabase.cpp | 4 ++++ src/cpp/database/SqliteDatabase.h | 2 ++ src/cpp/database/database.h | 1 + src/cpp/ripple/RPCHandler.cpp | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index 5de22db964..390711bab7 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -196,6 +196,10 @@ uint64 SqliteDatabase::getBigInt(int colIndex) return(sqlite3_column_int64(mCurrentStmt, colIndex)); } +int SqliteDatabase::getKBUsed() +{ + return static_cast(sqlite3_memory_used() / 1024); +} static int SqliteWALHook(void *s, sqlite3* dbCon, const char *dbName, int walSize) { diff --git a/src/cpp/database/SqliteDatabase.h b/src/cpp/database/SqliteDatabase.h index 5b4cfa048d..0a9ca590af 100644 --- a/src/cpp/database/SqliteDatabase.h +++ b/src/cpp/database/SqliteDatabase.h @@ -57,6 +57,8 @@ public: void runWal(); void doHook(const char *db, int walSize); + + int getKBUsed(); }; class SqliteStatement diff --git a/src/cpp/database/database.h b/src/cpp/database/database.h index 05f9e87700..579ed2929d 100644 --- a/src/cpp/database/database.h +++ b/src/cpp/database/database.h @@ -89,6 +89,7 @@ public: virtual bool setupCheckpointing(JobQueue*) { return false; } virtual SqliteDatabase* getSqliteDB() { return NULL; } + virtual int getKBUsed() { return -1; } }; #endif diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 85ab661a70..8fa825b86a 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1803,6 +1803,10 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest) BOOST_FOREACH(InstanceType::InstanceCount& it, count) ret[it.first] = it.second; + int dbKB = theApp->getLedgerDB()->getDB()->getKBUsed(); + if (dbKB > 0) + ret["dbKB"] = dbKB; + return ret; }