summaryrefslogtreecommitdiff
path: root/src/mongo/db/service_context.cpp
diff options
context:
space:
mode:
authorTyler Kaye <tyler.kaye@mongodb.com>2018-10-22 17:23:11 -0400
committerTyler Kaye <tyler.kaye@mongodb.com>2019-01-28 09:58:54 -0500
commitcdf319123d8e5d3cd169e2a11aec6aea0b951bf1 (patch)
treea8f046ca114f65812b7d01d5289c8aca327bb195 /src/mongo/db/service_context.cpp
parent82e05d6c201fa59223aa40340a5d4ad84b32ac65 (diff)
downloadmongo-cdf319123d8e5d3cd169e2a11aec6aea0b951bf1.tar.gz
SERVER-34422-ThreadMetrics: ServerStatus now returns the number of active client operations
Diffstat (limited to 'src/mongo/db/service_context.cpp')
-rw-r--r--src/mongo/db/service_context.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp
index 8ffa987a49d..f2f72ac6ed0 100644
--- a/src/mongo/db/service_context.cpp
+++ b/src/mongo/db/service_context.cpp
@@ -59,6 +59,8 @@ using ConstructorActionList = stdx::list<ServiceContext::ConstructorDestructorAc
ServiceContext* globalServiceContext = nullptr;
+AtomicWord<int> _numCurrentOps{0};
+
} // namespace
bool hasGlobalServiceContext() {
@@ -235,6 +237,10 @@ void ServiceContext::ClientDeleter::operator()(Client* client) const {
ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Client* client) {
auto opCtx = std::make_unique<OperationContext>(client, _nextOpId.fetchAndAdd(1));
+ if (client && client->session()) {
+ _numCurrentOps.addAndFetch(1);
+ }
+
onCreate(opCtx.get(), _clientObservers);
if (!opCtx->lockState()) {
opCtx->setLockState(std::make_unique<LockerNoop>());
@@ -252,6 +258,9 @@ ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Clie
void ServiceContext::OperationContextDeleter::operator()(OperationContext* opCtx) const {
auto client = opCtx->getClient();
+ if (client && client->session()) {
+ _numCurrentOps.subtractAndFetch(1);
+ }
auto service = client->getServiceContext();
{
stdx::lock_guard<Client> lk(*client);
@@ -342,6 +351,10 @@ void ServiceContext::notifyStartupComplete() {
_startupCompleteCondVar.notify_all();
}
+int ServiceContext::getActiveClientOperations() {
+ return _numCurrentOps.load();
+}
+
namespace {
/**