From 7d65d20f5aed286a418d6e9e0bcc12d8bcb75cb8 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Tue, 29 Dec 2009 12:27:27 -0500 Subject: [PATCH] --profile command line option SERVER-456 --- db/cmdline.h | 5 +++-- db/database.cpp | 11 ++++++++++- db/database.h | 8 +++++++- db/db.cpp | 4 +++- db/db.h | 3 ++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/db/cmdline.h b/db/cmdline.h index e9e249bd715..6daf1e175c7 100644 --- a/db/cmdline.h +++ b/db/cmdline.h @@ -37,7 +37,8 @@ namespace mongo { bool cpu; // --cpu show cpu time periodically long long oplogSize; // --oplogSize - + int defaultProfile; // --profile + enum { DefaultDBPort = 27017, ConfigServerPort = 27019, @@ -46,7 +47,7 @@ namespace mongo { CmdLine() : port(DefaultDBPort), quiet(false), notablescan(false), prealloc(true), smallfiles(false), - quota(false), quotaFiles(8), cpu(false), oplogSize(0) + quota(false), quotaFiles(8), cpu(false), oplogSize(0), defaultProfile(0) { } }; diff --git a/db/database.cpp b/db/database.cpp index fb243302083..6361e865fbf 100644 --- a/db/database.cpp +++ b/db/database.cpp @@ -40,7 +40,8 @@ namespace mongo { assert( cc().database() == this ); - if ( ! nsdetails( profileName.c_str() ) ){ + if ( ! namespaceIndex.details( profileName.c_str() ) ){ + log(1) << "creating profile ns: " << profileName << endl; BSONObjBuilder spec; spec.appendBool( "capped", true ); spec.append( "size", 131072.0 ); @@ -52,4 +53,12 @@ namespace mongo { return true; } + void Database::finishInit(){ + if ( cmdLine.defaultProfile == profile ) + return; + + string errmsg; + massert( 12506 , errmsg , setProfilingLevel( cmdLine.defaultProfile , errmsg ) ); + } + } // namespace mongo diff --git a/db/database.h b/db/database.h index 3fd162b6158..f951081c988 100644 --- a/db/database.h +++ b/db/database.h @@ -18,6 +18,8 @@ #pragma once +#include "cmdline.h" + /* Database represents a database database Each database database has its own set of files -- dbname.ns, dbname.0, dbname.1, ... */ @@ -48,11 +50,13 @@ namespace mongo { // If already exists, open. Otherwise behave as if empty until // there's a write, then open. - if ( !newDb ) { + if ( ! newDb || cmdLine.defaultProfile ) { namespaceIndex.init(); if( _openAllFiles ) openAllFiles(); + } + } ~Database() { @@ -170,6 +174,8 @@ namespace mongo { */ bool setProfilingLevel( int newLevel , string& errmsg ); + void finishInit(); + vector files; string name; // "alleyinsider" string path; diff --git a/db/db.cpp b/db/db.cpp index 3d4217d27c6..357ddafcaba 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -584,6 +584,7 @@ int main(int argc, char* argv[], char *envp[] ) ("repair", "run repair on all dbs") ("notablescan", "do not allow table scans") ("syncdelay",po::value(&dataFileSync._sleepsecs)->default_value(60), "seconds between disk syncs (0 for never)") + ("profile",po::value(), "0=off 1=slow, 2=all") #if defined(_WIN32) ("install", "install mongodb service") ("remove", "remove mongodb service") @@ -868,7 +869,8 @@ int main(int argc, char* argv[], char *envp[] ) if ( params.count("configsvr" ) && params.count( "diaglog" ) == 0 ){ _diaglog.level = 1; } - + if ( params.count( "profile" ) ) + cmdLine.defaultProfile = params["profile"].as(); Module::configAll( params ); dataFileSync.go(); diff --git a/db/db.h b/db/db.h index 4f98282a263..69128e35cd2 100644 --- a/db/db.h +++ b/db/db.h @@ -101,9 +101,10 @@ namespace mongo { bool justCreated; Database *newdb = new Database(cl, justCreated, path); databases[key] = newdb; - //newdb->finishInit(); cc().setns(ns, newdb); + newdb->finishInit(); + return justCreated; }