Files
mongo/db/stats/counters.cpp

110 lines
3.1 KiB
C++
Raw Normal View History

2010-02-01 10:38:00 -05:00
// counters.cpp
/*
* 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/>.
*/
2010-01-16 00:50:02 -05:00
2010-02-03 15:31:48 -05:00
#include "stdafx.h"
2010-02-01 10:38:00 -05:00
#include "../jsobj.h"
#include "counters.h"
2010-01-16 00:50:02 -05:00
namespace mongo {
OpCounters::OpCounters(){
int zero = 0;
BSONObjBuilder b;
b.append( "insert" , zero );
b.append( "query" , zero );
b.append( "update" , zero );
b.append( "delete" , zero );
b.append( "getmore" , zero );
2010-02-11 12:52:26 -05:00
b.append( "command" , zero );
2010-01-16 00:50:02 -05:00
_obj = b.obj();
_insert = (int*)_obj["insert"].value();
_query = (int*)_obj["query"].value();
_update = (int*)_obj["update"].value();
_delete = (int*)_obj["delete"].value();
_getmore = (int*)_obj["getmore"].value();
2010-02-11 12:52:26 -05:00
_command = (int*)_obj["command"].value();
2010-01-16 00:50:02 -05:00
}
2010-02-11 12:52:26 -05:00
void OpCounters::gotOp( int op , bool isCommand ){
2010-01-16 08:00:42 -05:00
switch ( op ){
case dbInsert: gotInsert(); break;
2010-02-11 12:52:26 -05:00
case dbQuery:
if ( isCommand )
gotCommand();
else
gotQuery();
break;
2010-01-16 08:00:42 -05:00
case dbUpdate: gotUpdate(); break;
case dbDelete: gotDelete(); break;
case dbGetMore: gotGetMore(); break;
case dbKillCursors:
case opReply:
case dbMsg:
break;
2010-01-18 11:06:10 -05:00
default: log() << "OpCounters::gotOp unknown op: " << op << endl;
2010-01-16 08:00:42 -05:00
}
}
IndexCounters::IndexCounters(){
_memSupported = _pi.blockCheckSupported();
_btreeMemHits = 0;
_btreeMemMisses = 0;
_btreeAccesses = 0;
_maxAllowed = ( numeric_limits< long long >::max() ) / 2;
_resets = 0;
2010-01-16 08:00:42 -05:00
_sampling = 0;
_samplingrate = 100;
}
void IndexCounters::append( BSONObjBuilder& b ){
if ( ! _memSupported ){
b.append( "note" , "not supported on this platform" );
return;
}
BSONObjBuilder bb( b.subobjStart( "btree" ) );
2010-02-01 13:56:52 -05:00
bb.appendIntOrLL( "accesses" , _btreeAccesses );
bb.appendIntOrLL( "hits" , _btreeMemHits );
bb.appendIntOrLL( "misses" , _btreeMemMisses );
bb.append( "resets" , _resets );
bb.append( "missRatio" , (_btreeAccesses ? (_btreeMemMisses / (double)_btreeAccesses) : 0) );
bb.done();
if ( _btreeAccesses > _maxAllowed ){
_btreeAccesses = 0;
_btreeMemMisses = 0;
_btreeMemHits = 0;
_resets++;
}
}
2010-01-16 08:00:42 -05:00
2010-01-16 00:50:02 -05:00
OpCounters globalOpCounters;
IndexCounters globalIndexCounters;
2010-01-16 00:50:02 -05:00
}