summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2015-03-04 09:52:40 -0500
committerJames Wahlin <james.wahlin@10gen.com>2015-04-03 12:56:05 -0400
commit998cf155edc16019758d163e8f844c0986996bcf (patch)
tree8931c9c39fc7aa8faa781cb73a6d70e431bb29ec /src/mongo/db/stats
parentbda47f627831f32f4928f30e04bcac52ad856f12 (diff)
downloadmongo-998cf155edc16019758d163e8f844c0986996bcf.tar.gz
SERVER-15395 Remove lock stats from web interface
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r--src/mongo/db/stats/snapshots.cpp48
-rw-r--r--src/mongo/db/stats/snapshots.h30
-rw-r--r--src/mongo/db/stats/snapshots_webplugins.cpp25
3 files changed, 46 insertions, 57 deletions
diff --git a/src/mongo/db/stats/snapshots.cpp b/src/mongo/db/stats/snapshots.cpp
index ccae800a0f5..addf361bcb6 100644
--- a/src/mongo/db/stats/snapshots.cpp
+++ b/src/mongo/db/stats/snapshots.cpp
@@ -62,7 +62,8 @@ namespace mongo {
verify( _newer._created > _older._created );
Top::UsageMap u;
- for ( Top::UsageMap::const_iterator i=_newer._usage.begin(); i != _newer._usage.end(); ++i ) {
+ for ( Top::UsageMap::const_iterator i=_newer._usage.begin();
+ i != _newer._usage.end(); ++i ) {
Top::UsageMap::const_iterator j = _older._usage.find(i->first);
if (j != _older._usage.end())
u[i->first] = Top::CollectionData( j->second , i->second );
@@ -72,55 +73,52 @@ namespace mongo {
return u;
}
- Snapshots::Snapshots(int n)
- : _n(n)
- , _snapshots(new SnapshotData[n])
- , _loc(0)
+ Snapshots::Snapshots()
+ : _loc(0)
, _stored(0)
{}
const SnapshotData* Snapshots::takeSnapshot() {
boost::lock_guard<boost::mutex> lk(_lock);
- _loc = ( _loc + 1 ) % _n;
+ _loc = ( _loc + 1 ) % kNumSnapshots;
_snapshots[_loc].takeSnapshot();
- if ( _stored < _n )
+ if ( _stored < kNumSnapshots )
_stored++;
return &_snapshots[_loc];
}
- auto_ptr<SnapshotDelta> Snapshots::computeDelta( int numBack ) {
+ StatusWith<SnapshotDiff> Snapshots::computeDelta() {
boost::lock_guard<boost::mutex> lk(_lock);
- auto_ptr<SnapshotDelta> p;
- if ( numBack < numDeltas() )
- p.reset( new SnapshotDelta( getPrev(numBack+1) , getPrev(numBack) ) );
- return p;
- }
- const SnapshotData& Snapshots::getPrev( int numBack ) {
- int x = _loc - numBack;
- if ( x < 0 )
- x += _n;
- return _snapshots[x];
+ // We need 2 snapshots to calculate a delta
+ if (_stored < 2) {
+ return StatusWith<SnapshotDiff>(ErrorCodes::BadValue,
+ "Less than 2 snapshots exist");
+ }
+
+ // The following logic depends on there being exactly 2 stored snapshots
+ BOOST_STATIC_ASSERT(kNumSnapshots == 2);
+
+ // Current and previous napshot alternates between indexes 0 and 1
+ int currIdx = _loc;
+ int prevIdx = _loc > 0 ? 0 : 1;
+ SnapshotDelta delta(_snapshots[prevIdx], _snapshots[currIdx]);
+
+ return SnapshotDiff(delta.collectionUsageDiff(), delta.elapsed());
}
void SnapshotThread::run() {
Client::initThread("snapshot");
Client& client = cc();
- long long numLoops = 0;
-
- const SnapshotData* prev = 0;
-
while ( ! inShutdown() ) {
try {
- const SnapshotData* s = statsSnapshots.takeSnapshot();
- prev = s;
+ statsSnapshots.takeSnapshot();
}
catch ( std::exception& e ) {
log() << "ERROR in SnapshotThread: " << e.what() << endl;
}
- numLoops++;
sleepsecs(4);
}
diff --git a/src/mongo/db/stats/snapshots.h b/src/mongo/db/stats/snapshots.h
index 59240c9bfea..9c29e7d5eb6 100644
--- a/src/mongo/db/stats/snapshots.h
+++ b/src/mongo/db/stats/snapshots.h
@@ -29,9 +29,11 @@
*/
#pragma once
-#include "mongo/platform/basic.h"
+
+#include "mongo/base/status_with.h"
#include "mongo/db/jsobj.h"
-#include "top.h"
+#include "mongo/db/stats/top.h"
+#include "mongo/platform/basic.h"
#include "mongo/util/background.h"
/**
@@ -63,10 +65,6 @@ namespace mongo {
public:
SnapshotDelta( const SnapshotData& older , const SnapshotData& newer );
- unsigned long long start() const {
- return _older._created;
- }
-
unsigned long long elapsed() const {
return _elapsed;
}
@@ -80,21 +78,27 @@ namespace mongo {
unsigned long long _elapsed;
};
+ struct SnapshotDiff {
+ Top::UsageMap usageDiff;
+ unsigned long long timeElapsed;
+
+ SnapshotDiff() = default;
+ SnapshotDiff(Top::UsageMap map, unsigned long long elapsed)
+ : usageDiff(std::move(map)), timeElapsed(elapsed) {}
+ };
+
class Snapshots {
public:
- Snapshots(int n=100);
+ Snapshots();
const SnapshotData* takeSnapshot();
- int numDeltas() const { return _stored-1; }
-
- const SnapshotData& getPrev( int numBack = 0 );
- std::auto_ptr<SnapshotDelta> computeDelta( int numBack = 0 );
+ StatusWith<SnapshotDiff> computeDelta();
private:
mongo::mutex _lock;
- int _n;
- boost::scoped_array<SnapshotData> _snapshots;
+ static const int kNumSnapshots = 2;
+ SnapshotData _snapshots[kNumSnapshots];
int _loc;
int _stored;
};
diff --git a/src/mongo/db/stats/snapshots_webplugins.cpp b/src/mongo/db/stats/snapshots_webplugins.cpp
index 281ed1dbf5c..cc604c6e983 100644
--- a/src/mongo/db/stats/snapshots_webplugins.cpp
+++ b/src/mongo/db/stats/snapshots_webplugins.cpp
@@ -38,26 +38,11 @@ namespace {
using namespace html;
- using std::auto_ptr;
using std::fixed;
using std::setprecision;
using std::string;
using std::stringstream;
- class WriteLockStatus : public WebStatusPlugin {
- public:
- WriteLockStatus() : WebStatusPlugin( "write lock" , 51 , "% time in write lock, by 4 sec periods" ) {}
- virtual void init() {}
-
- virtual void run(OperationContext* txn, stringstream& ss) {
- ss << "<a "
- "href=\"http://dochub.mongodb.org/core/concurrency\" "
- "title=\"snapshot: was the db in the write lock when this page was generated?\">";
- ss << "write locked now:</a> " << (txn->lockState()->isW() ? "true" : "false") << "\n";
- }
-
- } writeLockStatus;
-
class DBTopStatus : public WebStatusPlugin {
public:
DBTopStatus() : WebStatusPlugin( "dbtop" , 50 , "(occurrences|percent of elapsed)" ) {}
@@ -95,8 +80,9 @@ namespace {
}
void run(OperationContext* txn, stringstream& ss) {
- auto_ptr<SnapshotDelta> delta = statsSnapshots.computeDelta();
- if ( ! delta.get() )
+ StatusWith<SnapshotDiff> diff = statsSnapshots.computeDelta();
+
+ if ( ! diff.isOK() )
return;
ss << "<table border=1 cellpadding=2 cellspacing=0>";
@@ -113,9 +99,10 @@ namespace {
"<th colspan=2>Removes</th>";
ss << "</tr>\n";
- Top::UsageMap usage = delta->collectionUsageDiff();
+ const Top::UsageMap& usage = diff.getValue().usageDiff;
+ unsigned long long elapsed = diff.getValue().timeElapsed;
for ( Top::UsageMap::const_iterator i=usage.begin(); i != usage.end(); ++i ) {
- display( ss , (double) delta->elapsed() , i->first , i->second );
+ display( ss , (double) elapsed , i->first , i->second );
}
ss << "</table>";