summaryrefslogtreecommitdiff
path: root/dbtests
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2011-03-25 14:48:46 -0400
committerDwight <dwight@10gen.com>2011-03-25 14:49:02 -0400
commitd7ded4842e6bfb454b501d0ef0e4d890566b5837 (patch)
treeb6289b099d43aaef3dc6e4af20aad082e5b6192a /dbtests
parent68d848fe4c036d2bc377e3b281ebae998d861b9c (diff)
downloadmongo-d7ded4842e6bfb454b501d0ef0e4d890566b5837.tar.gz
beginnings of recording some timing information for the c++ unit tests
Diffstat (limited to 'dbtests')
-rw-r--r--dbtests/perftests.cpp66
1 files changed, 62 insertions, 4 deletions
diff --git a/dbtests/perftests.cpp b/dbtests/perftests.cpp
index 7fb634c236d..187c1eb1cc2 100644
--- a/dbtests/perftests.cpp
+++ b/dbtests/perftests.cpp
@@ -34,6 +34,9 @@
#include "dbtests.h"
#include "../db/dur_stats.h"
#include "../util/checksum.h"
+#include "../util/version.h"
+
+using namespace bson;
namespace PerfTests {
typedef DBDirectClient DBClientType;
@@ -119,12 +122,65 @@ namespace PerfTests {
/* override if your test output doesn't need that */
virtual bool showDurStats() { return true; }
+ static DBClientConnection *conn;
+
public:
void say(unsigned long long n, int ms, string s) {
- cout << "stats " << setw(33) << left << s << ' ' << setw(8) << /*rps*/n*1000/ms << ' ' << right << setw(6) << ms << "ms ";
- if( showDurStats() )
- cout << dur::stats.curr->_asCSV();
- cout << endl;
+ unsigned long long rps = n*1000/ms;
+ cout << "stats " << setw(33) << left << s << ' ' << setw(8) << rps << ' ' << right << setw(6) << ms << "ms ";
+ if( showDurStats() )
+ cout << dur::stats.curr->_asCSV();
+ cout << endl;
+
+ /* if you want recording of the timings, place the password for the perf database
+ in a "pstats.login" text file in the current directory for the test binary
+ */
+ if( exists("pstats.login") ) {
+ try {
+ if( conn == 0 ) {
+ MemoryMappedFile f;
+ void *p = f.mapWithOptions("pstats.login", MongoFile::READONLY);
+ string pwd((const char *)p, (unsigned) f.length());
+ conn = new DBClientConnection(false, 0, 10);
+ string err;
+ if( conn->connect("mongo05.10gen.cust.cbici.net", err) ) {
+ if( !conn->auth("perf", "perf", pwd, err) ) {
+ cout << "info: authentication with stats before logging failed: " << err << endl;
+ assert(false);
+ }
+ }
+ else {
+ cout << err << " (to log pstats)" << endl;
+ }
+ }
+ if( conn && !conn->isFailed() ) {
+ bob b;
+ b.append("host", getHostName());
+ b.appendTimeT("when", time(0));
+ b.append("test", s);
+ b.append("rps", (int) rps);
+ b.append("millis", ms);
+ b.appendBool("dur", cmdLine.dur);
+ if( showDurStats() && cmdLine.dur )
+ b.append("durStats", dur::stats.curr->_asObj());
+ {
+ bob inf;
+ inf.append("version", versionString);
+ if( sizeof(int*) == 4 ) inf.append("bits", 32);
+ #if defined(_WIN32)
+ inf.append("os", "win");
+ #endif
+ inf.append("git", gitVersion());
+ inf.append("boost", BOOST_VERSION);
+ b.append("info", inf.obj());
+ }
+
+ conn->insert("perf.pstats", b.obj());
+ }
+ }
+ catch(...) {
+ }
+ }
}
void run() {
_ns = string("perftest.") + name();
@@ -188,6 +244,8 @@ namespace PerfTests {
}
};
+ DBClientConnection *B::conn;
+
unsigned dontOptimizeOutHopefully;
// test thread local speed