Files
mongo/db/introspect.cpp

89 lines
2.9 KiB
C++
Raw Normal View History

2008-12-28 20:28:49 -05:00
// introspect.cpp
2008-06-06 09:43:15 -04:00
/**
* Copyright (C) 2008 10gen Inc.
2008-12-28 20:28:49 -05:00
*
* 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.
2008-12-28 20:28:49 -05:00
*
* 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.
2008-12-28 20:28:49 -05:00
*
* 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-04-27 15:27:52 -04:00
#include "pch.h"
2008-06-06 09:43:15 -04:00
#include "introspect.h"
2010-04-24 18:25:58 -04:00
#include "../bson/util/builder.h"
2008-06-06 09:43:15 -04:00
#include "../util/goodies.h"
#include "pdfile.h"
#include "jsobj.h"
#include "pdfile.h"
#include "curop.h"
2008-06-06 09:43:15 -04:00
2009-01-14 17:09:51 -05:00
namespace mongo {
BufBuilder profileBufBuilder; // reused, instead of allocated every time - avoids a malloc/free cycle
void profile( const Client& c , CurOp& currentOp ) {
assertInWriteLock();
Database *db = c.database();
DEV assert( db );
const char *ns = db->profileName.c_str();
// build object
profileBufBuilder.reset();
BSONObjBuilder b(profileBufBuilder);
b.appendDate("ts", jsTime());
2011-08-08 12:25:38 -04:00
currentOp.debug().append( currentOp , b );
2011-05-08 17:29:09 -04:00
b.append("client", c.clientAddress() );
if ( c.getAuthenticationInfo() )
b.append( "user" , c.getAuthenticationInfo()->getUser( nsToDatabase( ns ) ) );
BSONObj p = b.done();
if (p.objsize() > 100*1024){
string small = p.toString(/*isArray*/false, /*full*/false);
warning() << "can't add full line to system.profile: " << small;
// rebuild with limited info
BSONObjBuilder b(profileBufBuilder);
b.appendDate("ts", jsTime());
b.append("client", c.clientAddress() );
if ( c.getAuthenticationInfo() )
b.append( "user" , c.getAuthenticationInfo()->getUser( nsToDatabase( ns ) ) );
b.append("err", "profile line too large (max is 100KB)");
if (small.size() < 100*1024){ // should be much smaller but if not don't break anything
b.append("abbreviated", small);
}
p = b.done();
}
// write: not replicated
NamespaceDetails *d = db->namespaceIndex.details(ns);
if( d ) {
int len = p.objsize();
Record *r = theDataFileMgr.fast_oplog_insert(d, ns, len);
memcpy(getDur().writingPtr(r->data, len), p.objdata(), len);
}
else {
static time_t last;
if( time(0) > last+10 ) {
log() << "profile: warning ns " << ns << " does not exist" << endl;
last = time(0);
}
}
2008-12-28 20:28:49 -05:00
}
2009-01-14 17:09:51 -05:00
} // namespace mongo