summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-11-28 00:54:22 -0500
committerEliot Horowitz <eliot@10gen.com>2011-11-28 00:54:29 -0500
commit87f77a220c051a35c611d5d2a46b1d215e579552 (patch)
tree69923a2e1871bc7767264ee58095bb0435988cbc /tools
parent18fb262f9e2c8ccf6da776d1208d706eb333937b (diff)
downloadmongo-87f77a220c051a35c611d5d2a46b1d215e579552.tar.gz
fix indentation
Diffstat (limited to 'tools')
-rw-r--r--tools/stat_util.cpp318
-rw-r--r--tools/stat_util.h28
2 files changed, 173 insertions, 173 deletions
diff --git a/tools/stat_util.cpp b/tools/stat_util.cpp
index 511030721a8..cbf4fbfa126 100644
--- a/tools/stat_util.cpp
+++ b/tools/stat_util.cpp
@@ -1,20 +1,20 @@
// stat_util.cpp
/**
-* Copyright (C) 2008 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/>.
-*/
+ * Copyright (C) 2008 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/>.
+ */
#include "stat_util.h"
#include "../util/mongoutils/str.h"
@@ -32,154 +32,154 @@ namespace mongo {
}
BSONObj StatUtil::doRow( const BSONObj& a , const BSONObj& b ) {
- BSONObjBuilder result;
+ BSONObjBuilder result;
- bool isMongos = b["shardCursorType"].type() == Object; // TODO: should have a better check
+ bool isMongos = b["shardCursorType"].type() == Object; // TODO: should have a better check
- if ( a["opcounters"].isABSONObj() && b["opcounters"].isABSONObj() ) {
- BSONObj ax = a["opcounters"].embeddedObject();
- BSONObj bx = b["opcounters"].embeddedObject();
+ if ( a["opcounters"].isABSONObj() && b["opcounters"].isABSONObj() ) {
+ BSONObj ax = a["opcounters"].embeddedObject();
+ BSONObj bx = b["opcounters"].embeddedObject();
- BSONObj ar = a["opcountersRepl"].isABSONObj() ? a["opcountersRepl"].embeddedObject() : BSONObj();
- BSONObj br = b["opcountersRepl"].isABSONObj() ? b["opcountersRepl"].embeddedObject() : BSONObj();
+ BSONObj ar = a["opcountersRepl"].isABSONObj() ? a["opcountersRepl"].embeddedObject() : BSONObj();
+ BSONObj br = b["opcountersRepl"].isABSONObj() ? b["opcountersRepl"].embeddedObject() : BSONObj();
- BSONObjIterator i( bx );
- while ( i.more() ) {
- BSONElement e = i.next();
- if ( ar.isEmpty() || br.isEmpty() ) {
- _append( result , e.fieldName() , 6 , (int)diff( e.fieldName() , ax , bx ) );
+ BSONObjIterator i( bx );
+ while ( i.more() ) {
+ BSONElement e = i.next();
+ if ( ar.isEmpty() || br.isEmpty() ) {
+ _append( result , e.fieldName() , 6 , (int)diff( e.fieldName() , ax , bx ) );
+ }
+ else {
+ string f = e.fieldName();
+
+ int m = (int)diff( f , ax , bx );
+ int r = (int)diff( f , ar , br );
+
+ string myout;
+
+ if ( f == "command" ) {
+ myout = str::stream() << m << "|" << r;
+ }
+ else if ( f == "getmore" ) {
+ myout = str::stream() << m;
+ }
+ else if ( m && r ) {
+ // this is weird...
+ myout = str::stream() << m << "|" << r;
+ }
+ else if ( m ) {
+ myout = str::stream() << m;
+ }
+ else if ( r ) {
+ myout = str::stream() << "*" << r;
}
else {
- string f = e.fieldName();
-
- int m = (int)diff( f , ax , bx );
- int r = (int)diff( f , ar , br );
-
- string myout;
-
- if ( f == "command" ) {
- myout = str::stream() << m << "|" << r;
- }
- else if ( f == "getmore" ) {
- myout = str::stream() << m;
- }
- else if ( m && r ) {
- // this is weird...
- myout = str::stream() << m << "|" << r;
- }
- else if ( m ) {
- myout = str::stream() << m;
- }
- else if ( r ) {
- myout = str::stream() << "*" << r;
- }
- else {
- myout = "*0";
- }
-
- _append( result , f , 6 , myout );
+ myout = "*0";
}
+
+ _append( result , f , 6 , myout );
}
}
+ }
- if ( b["backgroundFlushing"].type() == Object ) {
- BSONObj ax = a["backgroundFlushing"].embeddedObject();
- BSONObj bx = b["backgroundFlushing"].embeddedObject();
- _append( result , "flushes" , 6 , (int)diff( "flushes" , ax , bx ) );
- }
+ if ( b["backgroundFlushing"].type() == Object ) {
+ BSONObj ax = a["backgroundFlushing"].embeddedObject();
+ BSONObj bx = b["backgroundFlushing"].embeddedObject();
+ _append( result , "flushes" , 6 , (int)diff( "flushes" , ax , bx ) );
+ }
- if ( b.getFieldDotted("mem.supported").trueValue() ) {
- BSONObj bx = b["mem"].embeddedObject();
- BSONObjIterator i( bx );
- if (!isMongos)
- _appendMem( result , "mapped" , 6 , bx["mapped"].numberInt() );
- _appendMem( result , "vsize" , 6 , bx["virtual"].numberInt() );
- _appendMem( result , "res" , 6 , bx["resident"].numberInt() );
+ if ( b.getFieldDotted("mem.supported").trueValue() ) {
+ BSONObj bx = b["mem"].embeddedObject();
+ BSONObjIterator i( bx );
+ if (!isMongos)
+ _appendMem( result , "mapped" , 6 , bx["mapped"].numberInt() );
+ _appendMem( result , "vsize" , 6 , bx["virtual"].numberInt() );
+ _appendMem( result , "res" , 6 , bx["resident"].numberInt() );
- if ( !isMongos && _all )
- _appendMem( result , "non-mapped" , 6 , bx["virtual"].numberInt() - bx["mapped"].numberInt() );
- }
+ if ( !isMongos && _all )
+ _appendMem( result , "non-mapped" , 6 , bx["virtual"].numberInt() - bx["mapped"].numberInt() );
+ }
- if ( b["extra_info"].type() == Object ) {
- BSONObj ax = a["extra_info"].embeddedObject();
- BSONObj bx = b["extra_info"].embeddedObject();
- if ( ax["page_faults"].type() || ax["page_faults"].type() )
- _append( result , "faults" , 6 , (int)diff( "page_faults" , ax , bx ) );
- }
+ if ( b["extra_info"].type() == Object ) {
+ BSONObj ax = a["extra_info"].embeddedObject();
+ BSONObj bx = b["extra_info"].embeddedObject();
+ if ( ax["page_faults"].type() || ax["page_faults"].type() )
+ _append( result , "faults" , 6 , (int)diff( "page_faults" , ax , bx ) );
+ }
- if (!isMongos) {
- _append( result , "locked %" , 8 , percent( "globalLock.totalTime" , "globalLock.lockTime" , a , b ) );
- _append( result , "idx miss %" , 8 , percent( "indexCounters.btree.accesses" , "indexCounters.btree.misses" , a , b ) );
- }
+ if (!isMongos) {
+ _append( result , "locked %" , 8 , percent( "globalLock.totalTime" , "globalLock.lockTime" , a , b ) );
+ _append( result , "idx miss %" , 8 , percent( "indexCounters.btree.accesses" , "indexCounters.btree.misses" , a , b ) );
+ }
- if ( b.getFieldDotted( "globalLock.currentQueue" ).type() == Object ) {
- int r = b.getFieldDotted( "globalLock.currentQueue.readers" ).numberInt();
- int w = b.getFieldDotted( "globalLock.currentQueue.writers" ).numberInt();
- stringstream temp;
- temp << r << "|" << w;
- _append( result , "qr|qw" , 9 , temp.str() );
- }
+ if ( b.getFieldDotted( "globalLock.currentQueue" ).type() == Object ) {
+ int r = b.getFieldDotted( "globalLock.currentQueue.readers" ).numberInt();
+ int w = b.getFieldDotted( "globalLock.currentQueue.writers" ).numberInt();
+ stringstream temp;
+ temp << r << "|" << w;
+ _append( result , "qr|qw" , 9 , temp.str() );
+ }
- if ( b.getFieldDotted( "globalLock.activeClients" ).type() == Object ) {
- int r = b.getFieldDotted( "globalLock.activeClients.readers" ).numberInt();
- int w = b.getFieldDotted( "globalLock.activeClients.writers" ).numberInt();
- stringstream temp;
- temp << r << "|" << w;
- _append( result , "ar|aw" , 7 , temp.str() );
- }
+ if ( b.getFieldDotted( "globalLock.activeClients" ).type() == Object ) {
+ int r = b.getFieldDotted( "globalLock.activeClients.readers" ).numberInt();
+ int w = b.getFieldDotted( "globalLock.activeClients.writers" ).numberInt();
+ stringstream temp;
+ temp << r << "|" << w;
+ _append( result , "ar|aw" , 7 , temp.str() );
+ }
- if ( a["network"].isABSONObj() && b["network"].isABSONObj() ) {
- BSONObj ax = a["network"].embeddedObject();
- BSONObj bx = b["network"].embeddedObject();
- _appendNet( result , "netIn" , diff( "bytesIn" , ax , bx ) );
- _appendNet( result , "netOut" , diff( "bytesOut" , ax , bx ) );
- }
+ if ( a["network"].isABSONObj() && b["network"].isABSONObj() ) {
+ BSONObj ax = a["network"].embeddedObject();
+ BSONObj bx = b["network"].embeddedObject();
+ _appendNet( result , "netIn" , diff( "bytesIn" , ax , bx ) );
+ _appendNet( result , "netOut" , diff( "bytesOut" , ax , bx ) );
+ }
- _append( result , "conn" , 5 , b.getFieldDotted( "connections.current" ).numberInt() );
+ _append( result , "conn" , 5 , b.getFieldDotted( "connections.current" ).numberInt() );
- if ( b["repl"].type() == Object ) {
+ if ( b["repl"].type() == Object ) {
- BSONObj x = b["repl"].embeddedObject();
- bool isReplSet = x["setName"].type() == String;
+ BSONObj x = b["repl"].embeddedObject();
+ bool isReplSet = x["setName"].type() == String;
- stringstream ss;
+ stringstream ss;
- if ( isReplSet ) {
- string setName = x["setName"].String();
- _append( result , "set" , setName.size() , setName );
- }
+ if ( isReplSet ) {
+ string setName = x["setName"].String();
+ _append( result , "set" , setName.size() , setName );
+ }
- if ( x["ismaster"].trueValue() )
- ss << "PRI";
- else if ( x["secondary"].trueValue() )
- ss << "SEC";
- else if ( x["isreplicaset"].trueValue() )
- ss << "REC";
- else if ( isReplSet )
- ss << "UNK";
- else
- ss << "SLV";
+ if ( x["ismaster"].trueValue() )
+ ss << "PRI";
+ else if ( x["secondary"].trueValue() )
+ ss << "SEC";
+ else if ( x["isreplicaset"].trueValue() )
+ ss << "REC";
+ else if ( isReplSet )
+ ss << "UNK";
+ else
+ ss << "SLV";
- _append( result , "repl" , 4 , ss.str() );
+ _append( result , "repl" , 4 , ss.str() );
- }
- else if ( isMongos ) {
- _append( result , "repl" , 4 , "RTR" );
- }
+ }
+ else if ( isMongos ) {
+ _append( result , "repl" , 4 , "RTR" );
+ }
- {
- struct tm t;
- time_t_to_Struct( time(0), &t , true );
- stringstream temp;
- temp << setfill('0') << setw(2) << t.tm_hour
- << ":"
- << setfill('0') << setw(2) << t.tm_min
- << ":"
- << setfill('0') << setw(2) << t.tm_sec;
- _append( result , "time" , 10 , temp.str() );
- }
- return result.obj();
+ {
+ struct tm t;
+ time_t_to_Struct( time(0), &t , true );
+ stringstream temp;
+ temp << setfill('0') << setw(2) << t.tm_hour
+ << ":"
+ << setfill('0') << setw(2) << t.tm_min
+ << ":"
+ << setfill('0') << setw(2) << t.tm_sec;
+ _append( result , "time" , 10 , temp.str() );
}
+ return result.obj();
+ }
@@ -196,39 +196,39 @@ namespace mongo {
double StatUtil::diff( const string& name , const BSONObj& a , const BSONObj& b ) {
- BSONElement x = a.getFieldDotted( name.c_str() );
- BSONElement y = b.getFieldDotted( name.c_str() );
- if ( ! x.isNumber() || ! y.isNumber() )
- return -1;
- return ( y.number() - x.number() ) / _seconds;
- }
+ BSONElement x = a.getFieldDotted( name.c_str() );
+ BSONElement y = b.getFieldDotted( name.c_str() );
+ if ( ! x.isNumber() || ! y.isNumber() )
+ return -1;
+ return ( y.number() - x.number() ) / _seconds;
+ }
void StatUtil::_appendNet( BSONObjBuilder& result , const string& name , double diff ) {
- // I think 1000 is correct for megabit, but I've seen conflicting things (ERH 11/2010)
- const double div = 1000;
-
- string unit = "b";
+ // I think 1000 is correct for megabit, but I've seen conflicting things (ERH 11/2010)
+ const double div = 1000;
- if ( diff >= div ) {
- unit = "k";
- diff /= div;
- }
+ string unit = "b";
- if ( diff >= div ) {
- unit = "m";
- diff /= div;
- }
+ if ( diff >= div ) {
+ unit = "k";
+ diff /= div;
+ }
- if ( diff >= div ) {
- unit = "g";
- diff /= div;
- }
+ if ( diff >= div ) {
+ unit = "m";
+ diff /= div;
+ }
- string out = str::stream() << (int)diff << unit;
- _append( result , name , 6 , out );
+ if ( diff >= div ) {
+ unit = "g";
+ diff /= div;
}
+ string out = str::stream() << (int)diff << unit;
+ _append( result , name , 6 , out );
+ }
+
void StatUtil::_appendMem( BSONObjBuilder& result , const string& name , unsigned width , double sz ) {
diff --git a/tools/stat_util.h b/tools/stat_util.h
index a777b5f1f85..8ebaca4eefc 100644
--- a/tools/stat_util.h
+++ b/tools/stat_util.h
@@ -1,20 +1,20 @@
// stat_util.h
/**
-* Copyright (C) 2008 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/>.
-*/
+ * Copyright (C) 2008 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