diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-02-20 09:34:25 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-02-20 09:34:25 -0500 |
commit | 3f5102bf27fd120b696c78d16668c4ba2a5f0475 (patch) | |
tree | 681380deb679a5ef108511b5c1eb067a3739c8cd | |
parent | b911ce8b250e3df57e8dd6e72cabd212972ef808 (diff) | |
download | mongo-3f5102bf27fd120b696c78d16668c4ba2a5f0475.tar.gz |
processinfo class and meminfo command, only works on darwin for the moment
-rw-r--r-- | SConstruct | 5 | ||||
-rw-r--r-- | db/dbcommands.cpp | 25 | ||||
-rw-r--r-- | jstests/_runner_leak.js | 33 | ||||
-rw-r--r-- | util/processinfo.h | 31 | ||||
-rw-r--r-- | util/processinfo_darwin.cpp | 78 | ||||
-rw-r--r-- | util/processinfo_none.cpp | 28 |
6 files changed, 200 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct index 4a942ba148f..d8a242ded3a 100644 --- a/SConstruct +++ b/SConstruct @@ -129,6 +129,11 @@ elif os.sys.platform == "win32": else: commonFiles += [ "util/mmap_posix.cpp" ] +if os.path.exists( "util/processinfo_" + os.sys.platform + ".cpp" ): + commonFiles += [ "util/processinfo_" + os.sys.platform + ".cpp" ] +else: + commonFiles += [ "util/processinfo_none.cpp" ] + coreDbFiles = Split( "" ) serverOnlyFiles = Split( "db/query.cpp db/introspect.cpp db/btree.cpp db/clientcursor.cpp db/javajs.cpp db/tests.cpp db/repl.cpp db/btreecursor.cpp db/cloner.cpp db/namespace.cpp db/matcher.cpp db/dbcommands.cpp db/dbeval.cpp db/dbwebserver.cpp db/dbinfo.cpp db/dbhelpers.cpp db/instance.cpp db/pdfile.cpp db/cursor.cpp db/security_commands.cpp db/security.cpp util/miniwebserver.cpp db/storage.cpp db/reccache.cpp db/queryoptimizer.cpp" ) diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 44718cf858b..85c21d25f95 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -25,6 +25,7 @@ #include "btree.h" #include "../util/lruishmap.h" #include "../util/md5.hpp" +#include "../util/processinfo.h" #include "json.h" #include "repl.h" #include "replset.h" @@ -405,6 +406,30 @@ namespace mongo { time_t started; } cmdTimeInfo; + class CmdMemInfo : public Command { + public: + virtual bool slaveOk() { + return true; + } + CmdMemInfo() : Command("meminfo") { + started = time(0); + } + bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + result.append("uptime",(double) (time(0)-started)); + + ProcessInfo p; + if ( ! p.supported() ){ + errmsg = "ProcessInfo not supported on this platform"; + return false; + } + + result << "resident" << p.getResidentSize(); + result << "virtual" << p.getVirtualMemorySize(); + return true; + } + time_t started; + } cmdMemInfo; + /* just to check if the db has asserted */ class CmdAssertInfo : public Command { public: diff --git a/jstests/_runner_leak.js b/jstests/_runner_leak.js new file mode 100644 index 00000000000..f4ed85f33c0 --- /dev/null +++ b/jstests/_runner_leak.js @@ -0,0 +1,33 @@ +// +// simple runner to run toplevel tests in jstests +// +var files = listFiles("jstests"); + +db.runCommand( "closeAllDatabases" ); + +prev = db.runCommand( "meminfo" ); + +files.forEach( + function(x) { + + if ( /_runner/.test(x.name) || + /_lodeRunner/.test(x.name) || + ! /\.js$/.test(x.name ) ){ + print(" >>>>>>>>>>>>>>> skipping " + x.name); + return; + } + + + print(" *******************************************"); + print(" Test : " + x.name + " ..."); + print(" " + Date.timeFunc( function() { load(x.name); }, 1) + "ms"); + + assert( db.getSisterDB( "admin" ).runCommand( "closeAllDatabases" ).ok == 1 , "closeAllDatabases failed" ); + var now = db.runCommand( "meminfo" ); + if ( now.virtual > prev.virtual ) + print( " LEAK : " + prev.virtual + " -->> " + now.virtual ); + prev = now; + } +); + + diff --git a/util/processinfo.h b/util/processinfo.h new file mode 100644 index 00000000000..f9c7c375b27 --- /dev/null +++ b/util/processinfo.h @@ -0,0 +1,31 @@ +// processinfo.h + +#pragma once + +#include <sys/types.h> +#include <unistd.h> + +namespace mongo { + + class ProcessInfo { + public: + ProcessInfo( pid_t pid = getpid() ); + ~ProcessInfo(); + + /** + * @return mbytes + */ + int getVirtualMemorySize(); + + /** + * @return mbytes + */ + int getResidentSize(); + + bool supported(); + + private: + pid_t _pid; + }; + +} diff --git a/util/processinfo_darwin.cpp b/util/processinfo_darwin.cpp new file mode 100644 index 00000000000..e6660ca2686 --- /dev/null +++ b/util/processinfo_darwin.cpp @@ -0,0 +1,78 @@ +// processinfo_darwin.cpp + +#include "processinfo.h" + + + +#include <mach/task_info.h> + +#include <mach/mach_init.h> +#include <mach/mach_host.h> +#include <mach/mach_traps.h> +#include <mach/task.h> +#include <mach/vm_map.h> +#include <mach/shared_memory_server.h> +#include <iostream> + +using namespace std; + +namespace mongo { + + ProcessInfo::ProcessInfo( pid_t pid ) : _pid( pid ){ + } + + ProcessInfo::~ProcessInfo(){ + } + + bool ProcessInfo::supported(){ + return true; + } + + int ProcessInfo::getVirtualMemorySize(){ + task_t result; + + mach_port_t task; + + if ( ( result = task_for_pid( mach_task_self() , _pid , &task) ) != KERN_SUCCESS ){ + cout << "error getting task\n"; + return 0; + } + +#if !defined(__LP64__) + task_basic_info_32 ti; +#else + task_basic_info_64 ti; +#endif + mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT; + if ( ( result = task_info( task , TASK_BASIC_INFO , (task_info_t)&ti, &count ) ) != KERN_SUCCESS ){ + cout << "error getting task_info: " << result << endl; + return 0; + } + return (int)((double)ti.virtual_size / (1024.0 * 1024 * 2 ) ); + } + + int ProcessInfo::getResidentSize(){ + task_t result; + + mach_port_t task; + + if ( ( result = task_for_pid( mach_task_self() , _pid , &task) ) != KERN_SUCCESS ){ + cout << "error getting task\n"; + return 0; + } + + +#if !defined(__LP64__) + task_basic_info_32 ti; +#else + task_basic_info_64 ti; +#endif + mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT; + if ( ( result = task_info( task , TASK_BASIC_INFO , (task_info_t)&ti, &count ) ) != KERN_SUCCESS ){ + cout << "error getting task_info: " << result << endl; + return 0; + } + return (int)( ti.resident_size / (1024 * 1024 ) ); + } + +} diff --git a/util/processinfo_none.cpp b/util/processinfo_none.cpp new file mode 100644 index 00000000000..7ccedf760e8 --- /dev/null +++ b/util/processinfo_none.cpp @@ -0,0 +1,28 @@ +// processinfo_none.cpp + +#include "processinfo.h" + +#include <iostream> +using namespace std; + +namespace mongo { + + ProcessInfo::ProcessInfo( pid_t pid ){ + } + + ProcessInfo::~ProcessInfo(){ + } + + bool ProcessInfo::supported(){ + return false; + } + + int ProcessInfo::getVirtualMemorySize(){ + return -1; + } + + int ProcessInfo::getResidentSize(){ + return -1; + } + +} |