summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats/top.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-04-16 17:32:06 -0400
committerBenety Goh <benety@mongodb.com>2015-04-22 14:57:44 -0400
commit14d3b48316f6e2ed075d01c3a9e7dcb28c0f2b63 (patch)
tree7b87e9cbe6888a9ed964fefb921a9f50112730f7 /src/mongo/db/stats/top.cpp
parentec2f3505c4ef05a56fa3e76a5bb7cada4cd7a41c (diff)
downloadmongo-14d3b48316f6e2ed075d01c3a9e7dcb28c0f2b63.tar.gz
SERVER-17817 SERVER-17894 Make Top a decoration on ServiceContext
Diffstat (limited to 'src/mongo/db/stats/top.cpp')
-rw-r--r--src/mongo/db/stats/top.cpp52
1 files changed, 13 insertions, 39 deletions
diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp
index 01bc0ab3da8..dd40f8f702a 100644
--- a/src/mongo/db/stats/top.cpp
+++ b/src/mongo/db/stats/top.cpp
@@ -33,13 +33,10 @@
#include "mongo/db/stats/top.h"
-#include "mongo/db/auth/action_set.h"
-#include "mongo/db/auth/action_type.h"
-#include "mongo/db/auth/authorization_manager.h"
-#include "mongo/db/auth/privilege.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/db/service_context.h"
#include "mongo/util/log.h"
#include "mongo/util/net/message.h"
-#include "mongo/db/commands.h"
namespace mongo {
@@ -48,6 +45,12 @@ namespace mongo {
using std::stringstream;
using std::vector;
+namespace {
+
+ const auto getTop = ServiceContext::declareDecoration<Top>();
+
+} // namespace
+
Top::UsageData::UsageData( const UsageData& older, const UsageData& newer ) {
// this won't be 100% accurate on rollovers and drop(), but at least it won't be negative
time = (newer.time >= older.time) ? (newer.time - older.time) : newer.time;
@@ -67,6 +70,11 @@ namespace mongo {
}
+ // static
+ Top& Top::get(ServiceContext* service) {
+ return getTop(service);
+ }
+
void Top::record( StringData ns, int op, int lockType, long long micros, bool command ) {
if ( ns[0] == '?' )
return;
@@ -179,38 +187,4 @@ namespace mongo {
bb.done();
}
- class TopCmd : public Command {
- public:
- TopCmd() : Command( "top", true ) {}
-
- virtual bool slaveOk() const { return true; }
- virtual bool adminOnly() const { return true; }
- virtual bool isWriteCommandForConfigServer() const { return false; }
- virtual void help( stringstream& help ) const { help << "usage by collection, in micros "; }
- virtual void addRequiredPrivileges(const std::string& dbname,
- const BSONObj& cmdObj,
- std::vector<Privilege>* out) {
- ActionSet actions;
- actions.addAction(ActionType::top);
- out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
- }
- virtual bool run(OperationContext* txn,
- const string&,
- BSONObj& cmdObj,
- int,
- string& errmsg,
- BSONObjBuilder& result) {
- {
- BSONObjBuilder b( result.subobjStart( "totals" ) );
- b.append( "note", "all times in microseconds" );
- Top::global.append( b );
- b.done();
- }
- return true;
- }
-
- } topCmd;
-
- Top Top::global;
-
}