0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/db/stats/counters.h

159 lines
4.1 KiB
C
Raw Normal View History

2010-02-01 16:38:00 +01:00
// counters.h
/*
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2010-01-16 06:50:02 +01:00
2010-04-27 21:33:27 +02:00
#include "../../pch.h"
2010-02-02 02:50:14 +01:00
#include "../jsobj.h"
2010-02-01 16:38:00 +01:00
#include "../../util/message.h"
#include "../../util/processinfo.h"
2010-11-09 06:14:52 +01:00
#include "../../util/concurrency/spin_lock.h"
2010-01-16 06:50:02 +01:00
namespace mongo {
/**
* for storing operation counters
* note: not thread safe. ok with that for speed
*/
class OpCounters {
public:
2011-01-04 06:40:41 +01:00
2010-01-16 06:50:02 +01:00
OpCounters();
2011-01-04 06:40:41 +01:00
AtomicUInt * getInsert() { return _insert; }
AtomicUInt * getQuery() { return _query; }
AtomicUInt * getUpdate() { return _update; }
AtomicUInt * getDelete() { return _delete; }
AtomicUInt * getGetMore() { return _getmore; }
AtomicUInt * getCommand() { return _command; }
2011-01-14 03:23:12 +01:00
void incInsertInWriteLock(int n) { _insert->x += n; }
2011-01-04 06:40:41 +01:00
void gotInsert() { _insert[0]++; }
void gotQuery() { _query[0]++; }
void gotUpdate() { _update[0]++; }
void gotDelete() { _delete[0]++; }
void gotGetMore() { _getmore[0]++; }
void gotCommand() { _command[0]++; }
2010-01-16 06:50:02 +01:00
2010-02-11 18:52:26 +01:00
void gotOp( int op , bool isCommand );
2010-01-16 06:50:02 +01:00
BSONObj& getObj();
2010-01-16 06:50:02 +01:00
private:
BSONObj _obj;
2011-01-14 03:23:12 +01:00
// todo: there will be a lot of cache line contention on these. need to do something
// else eventually.
2010-05-05 22:27:43 +02:00
AtomicUInt * _insert;
AtomicUInt * _query;
AtomicUInt * _update;
AtomicUInt * _delete;
AtomicUInt * _getmore;
AtomicUInt * _command;
2010-01-16 06:50:02 +01:00
};
2011-01-04 06:40:41 +01:00
2010-01-16 06:50:02 +01:00
extern OpCounters globalOpCounters;
2010-11-09 23:01:58 +01:00
extern OpCounters replOpCounters;
2010-01-16 06:50:02 +01:00
class IndexCounters {
public:
IndexCounters();
2011-01-04 06:40:41 +01:00
void btree( char * node ) {
if ( ! _memSupported )
return;
if ( _sampling++ % _samplingrate )
return;
btree( _pi.blockInMemory( node ) );
}
2011-01-04 06:40:41 +01:00
void btree( bool memHit ) {
if ( memHit )
_btreeMemHits++;
else
_btreeMemMisses++;
_btreeAccesses++;
}
2011-01-04 06:40:41 +01:00
void btreeHit() { _btreeMemHits++; _btreeAccesses++; }
void btreeMiss() { _btreeMemMisses++; _btreeAccesses++; }
void append( BSONObjBuilder& b );
2011-01-04 06:40:41 +01:00
private:
ProcessInfo _pi;
bool _memSupported;
int _sampling;
int _samplingrate;
2011-01-04 06:40:41 +01:00
int _resets;
long long _maxAllowed;
2011-01-04 06:40:41 +01:00
long long _btreeMemMisses;
long long _btreeMemHits;
long long _btreeAccesses;
};
extern IndexCounters globalIndexCounters;
2010-03-15 21:02:24 +01:00
class FlushCounters {
public:
FlushCounters();
void flushed(int ms);
2011-01-04 06:40:41 +01:00
2010-03-15 21:02:24 +01:00
void append( BSONObjBuilder& b );
private:
long long _total_time;
long long _flushes;
int _last_time;
Date_t _last;
};
extern FlushCounters globalFlushCounters;
class GenericCounter {
public:
2010-05-26 06:46:49 +02:00
GenericCounter() : _mutex("GenericCounter") { }
void hit( const string& name , int count=0 );
BSONObj getObj();
private:
map<string,long long> _counts; // TODO: replace with thread safe map
mongo::mutex _mutex;
};
class NetworkCounter {
public:
2011-01-04 06:40:41 +01:00
NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overflows(0) {}
void hit( long long bytesIn , long long bytesOut );
2010-11-09 06:14:52 +01:00
void append( BSONObjBuilder& b );
private:
long long _bytesIn;
long long _bytesOut;
2010-11-09 06:14:52 +01:00
long long _requests;
long long _overflows;
2010-11-09 06:14:52 +01:00
SpinLock _lock;
};
2011-01-04 06:40:41 +01:00
extern NetworkCounter networkCounter;
2010-01-16 06:50:02 +01:00
}