void profile( const Client& c , CurOp& currentOp ) { verify( Lock::somethingWriteLocked() ); Database *db = c.database(); DEV verify( db ); const char *ns = db->profileName.c_str(); // build object profileBufBuilder.reset(); BSONObjBuilder b(profileBufBuilder); const bool isQueryObjTooBig = !currentOp.debug().append(currentOp, b, MAX_PROFILE_DOC_SIZE_BYTES); b.appendDate("ts", jsTime()); b.append("client", c.clientAddress()); if (c.getAuthenticationInfo()) { b.append("user", c.getAuthenticationInfo()->getUser(nsToDatabase(ns))); } BSONObj p = b.done(); if (static_cast<size_t>(p.objsize()) > MAX_PROFILE_DOC_SIZE_BYTES || isQueryObjTooBig) { string small = p.toString(/*isArray*/false, /*full*/false); warning() << "can't add full line to system.profile: " << small << endl; // 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)"); // should be much smaller but if not don't break anything if (small.size() < MAX_PROFILE_DOC_SIZE_BYTES){ b.append("abbreviated", small); } p = b.done(); } // write: not replicated // get or create the profiling collection NamespaceDetails *details = getOrCreateProfileCollection(db); if (details) { int len = p.objsize(); Record *r = theDataFileMgr.fast_oplog_insert(details, ns, len); memcpy(getDur().writingPtr(r->data(), len), p.objdata(), len); } }
/** * @return if collection existed or was created */ static bool _profile(OperationContext* txn, const Client& c, Database* db, CurOp& currentOp, BufBuilder& profileBufBuilder) { dassert( db ); // build object BSONObjBuilder b(profileBufBuilder); const bool isQueryObjTooBig = !currentOp.debug().append(currentOp, b, MAX_PROFILE_DOC_SIZE_BYTES); b.appendDate("ts", jsTime()); b.append("client", c.clientAddress()); AuthorizationSession * authSession = c.getAuthorizationSession(); _appendUserInfo(currentOp, b, authSession); BSONObj p = b.done(); if (static_cast<size_t>(p.objsize()) > MAX_PROFILE_DOC_SIZE_BYTES || isQueryObjTooBig) { string small = p.toString(/*isArray*/false, /*full*/false); warning() << "can't add full line to system.profile: " << small << endl; // rebuild with limited info BSONObjBuilder b(profileBufBuilder); b.appendDate("ts", jsTime()); b.append("client", c.clientAddress() ); _appendUserInfo(currentOp, b, authSession); b.append("err", "profile line too large (max is 100KB)"); // should be much smaller but if not don't break anything if (small.size() < MAX_PROFILE_DOC_SIZE_BYTES){ b.append("abbreviated", small); } p = b.done(); } WriteUnitOfWork wunit(txn); // write: not replicated // get or create the profiling collection Collection* profileCollection = getOrCreateProfileCollection(txn, db); if ( !profileCollection ) { return false; } profileCollection->insertDocument( txn, p, false ); wunit.commit(); return true; }
static void _profile(const Client& c, CurOp& currentOp, BufBuilder& profileBufBuilder) { Database *db = c.database(); DEV verify( db ); const char *ns = db->profileName.c_str(); // build object BSONObjBuilder b(profileBufBuilder); b.appendDate("ts", jsTime()); currentOp.debug().append( currentOp , b ); 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 // get or create the profiling collection NamespaceDetails *details = getOrCreateProfileCollection(db); if (details) { int len = p.objsize(); Record *r = theDataFileMgr.fast_oplog_insert(details, ns, len); memcpy(getDur().writingPtr(r->data(), len), p.objdata(), len); } }
bool Database::setProfilingLevel( OperationContext* txn, int newLevel , string& errmsg ) { if ( _profile == newLevel ) return true; if ( newLevel < 0 || newLevel > 2 ) { errmsg = "profiling level has to be >=0 and <= 2"; return false; } if ( newLevel == 0 ) { _profile = 0; return true; } if (!getOrCreateProfileCollection(txn, this, true, &errmsg)) return false; _profile = newLevel; return true; }
bool Database::setProfilingLevel( int newLevel , string& errmsg ) { if ( _profile == newLevel ) return true; if ( newLevel < 0 || newLevel > 2 ) { errmsg = "profiling level has to be >=0 and <= 2"; return false; } if ( newLevel == 0 ) { _profile = 0; return true; } verify( cc().database() == this ); if (!getOrCreateProfileCollection(this, true, &errmsg)) return false; _profile = newLevel; return true; }