Example #1
0
    BSONObj ClusteredCursor::explain(){
        // Note: by default we filter out allPlans and oldPlan in the shell's
        // explain() function. If you add any recursive structures, make sure to
        // edit the JS to make sure everything gets filtered.

        BSONObjBuilder b;
        b.append( "clusteredType" , type() );

        long long millis = 0;
        double numExplains = 0;

        map<string,long long> counters;

        map<string,list<BSONObj> > out;
        {
            _explain( out );
            
            BSONObjBuilder x( b.subobjStart( "shards" ) );
            for ( map<string,list<BSONObj> >::iterator i=out.begin(); i!=out.end(); ++i ){
                string shard = i->first;
                list<BSONObj> l = i->second;
                BSONArrayBuilder y( x.subarrayStart( shard ) );
                for ( list<BSONObj>::iterator j=l.begin(); j!=l.end(); ++j ){
                    BSONObj temp = *j;
                    y.append( temp );
                    
                    BSONObjIterator k( temp );
                    while ( k.more() ){
                        BSONElement z = k.next();
                        if ( z.fieldName()[0] != 'n' )
                            continue;
                        long long& c = counters[z.fieldName()];
                        c += z.numberLong();
                    }
                    
                    millis += temp["millis"].numberLong();
                    numExplains++;
                }
                y.done();
            }
            x.done();
        }

        for ( map<string,long long>::iterator i=counters.begin(); i!=counters.end(); ++i )
            b.appendNumber( i->first , i->second );

        b.appendNumber( "millisTotal" , millis );
        b.append( "millisAvg" , (int)((double)millis / numExplains ) );
        b.append( "numQueries" , (int)numExplains );
        b.append( "numShards" , (int)out.size() );

        return b.obj();
    }
Example #2
0
    BSONObj ClusteredCursor::explain(){
        BSONObjBuilder b;
        b.append( "clusteredType" , type() );

        long long nscanned = 0;
        long long nscannedObjects = 0;
        long long n = 0;
        long long millis = 0;
        double numExplains = 0;
        
        map<string,list<BSONObj> > out;
        {
            _explain( out );
            
            BSONObjBuilder x( b.subobjStart( "shards" ) );
            for ( map<string,list<BSONObj> >::iterator i=out.begin(); i!=out.end(); ++i ){
                string shard = i->first;
                list<BSONObj> l = i->second;
                BSONArrayBuilder y( x.subarrayStart( shard.c_str() ) );
                for ( list<BSONObj>::iterator j=l.begin(); j!=l.end(); ++j ){
                    BSONObj temp = *j;
                    y.append( temp );

                    nscanned += temp["nscanned"].numberLong();
                    nscannedObjects += temp["nscannedObjects"].numberLong();
                    n += temp["n"].numberLong();
                    millis += temp["millis"].numberLong();
                    numExplains++;
                }
                y.done();
            }
            x.done();
        }

        b.appendNumber( "nscanned" , nscanned );
        b.appendNumber( "nscannedObjects" , nscannedObjects );
        b.appendNumber( "n" , n );
        b.appendNumber( "millisTotal" , millis );
        b.append( "millisAvg" , (int)((double)millis / numExplains ) );
        b.append( "numQueries" , (int)numExplains );
        b.append( "numShards" , (int)out.size() );

        return b.obj();
    }