← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mongo_pain.pl
  Run on Fri Mar 25 17:00:29 2011
Reported on Fri Mar 25 17:07:09 2011

Filename/usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm
StatementsExecuted 30 statements in 1.82ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.64ms4.04msMongoDB::Cursor::::BEGIN@23MongoDB::Cursor::BEGIN@23
1112.96ms29.4msMongoDB::Cursor::::BEGIN@21MongoDB::Cursor::BEGIN@21
111780µs4.38msMongoDB::Cursor::::BEGIN@22MongoDB::Cursor::BEGIN@22
11111µs148µsMongoDB::Cursor::::BEGIN@487MongoDB::Cursor::BEGIN@487
0000s0sMongoDB::Cursor::::_do_queryMongoDB::Cursor::_do_query
0000s0sMongoDB::Cursor::::_ensure_specialMongoDB::Cursor::_ensure_special
0000s0sMongoDB::Cursor::::allMongoDB::Cursor::all
0000s0sMongoDB::Cursor::::countMongoDB::Cursor::count
0000s0sMongoDB::Cursor::::explainMongoDB::Cursor::explain
0000s0sMongoDB::Cursor::::fieldsMongoDB::Cursor::fields
0000s0sMongoDB::Cursor::::hintMongoDB::Cursor::hint
0000s0sMongoDB::Cursor::::limitMongoDB::Cursor::limit
0000s0sMongoDB::Cursor::::skipMongoDB::Cursor::skip
0000s0sMongoDB::Cursor::::snapshotMongoDB::Cursor::snapshot
0000s0sMongoDB::Cursor::::sortMongoDB::Cursor::sort
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1#
2# Copyright 2009 10gen, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17package MongoDB::Cursor;
181700nsour $VERSION = '0.42';
19
20# ABSTRACT: A cursor/iterator for Mongo query results
213133µs230.0ms
# spent 29.4ms (2.96+26.5) within MongoDB::Cursor::BEGIN@21 which was called: # once (2.96ms+26.5ms) by MongoDB::Connection::BEGIN@23 at line 21
use Any::Moose;
# spent 29.4ms making 1 call to MongoDB::Cursor::BEGIN@21 # spent 542µs making 1 call to Any::Moose::import
223123µs24.45ms
# spent 4.38ms (780µs+3.60) within MongoDB::Cursor::BEGIN@22 which was called: # once (780µs+3.60ms) by MongoDB::Connection::BEGIN@23 at line 22
use boolean;
# spent 4.38ms making 1 call to MongoDB::Cursor::BEGIN@22 # spent 64µs making 1 call to Exporter::import
2331.44ms14.04ms
# spent 4.04ms (3.64+407µs) within MongoDB::Cursor::BEGIN@23 which was called: # once (3.64ms+407µs) by MongoDB::Connection::BEGIN@23 at line 23
use Tie::IxHash;
# spent 4.04ms making 1 call to MongoDB::Cursor::BEGIN@23
24
25=head1 NAME
26
- -
48120µs$MongoDB::Cursor::_request_id = int(rand(1000000));
49
50=head1 STATIC ATTRIBUTES
51
- -
601200ns$MongoDB::Cursor::slave_okay = 0;
61
62=head2 timeout
63
- -
751200ns$MongoDB::Cursor::timeout = 30000;
76
77=head1 ATTRIBUTES
78
- -
8713µs1368µshas started_iterating => (
# spent 368µs making 1 call to Mouse::has
88 is => 'rw',
89 isa => 'Bool',
90 required => 1,
91 default => 0,
92);
93
9412µs1407µshas _connection => (
# spent 407µs making 1 call to Mouse::has
95 is => 'ro',
96 isa => 'MongoDB::Connection',
97 required => 1,
98);
99
10012µs1201µshas _ns => (
# spent 201µs making 1 call to Mouse::has
101 is => 'ro',
102 isa => 'Str',
103 required => 1,
104);
105
10612µs1162µshas _query => (
# spent 162µs making 1 call to Mouse::has
107 is => 'rw',
108 required => 1,
109);
110
11112µs1200µshas _fields => (
# spent 200µs making 1 call to Mouse::has
112 is => 'rw',
113 isa => 'HashRef',
114 required => 0,
115);
116
11712µs1196µshas _limit => (
# spent 196µs making 1 call to Mouse::has
118 is => 'rw',
119 isa => 'Int',
120 required => 0,
121 default => 0,
122);
123
12412µs1192µshas _skip => (
# spent 192µs making 1 call to Mouse::has
125 is => 'rw',
126 isa => 'Int',
127 required => 0,
128 default => 0,
129);
130
131=head2 immortal
132
- -
14412µs1193µshas immortal => (
# spent 193µs making 1 call to Mouse::has
145 is => 'rw',
146 isa => 'Bool',
147 required => 0,
148 default => 0,
149);
150
151=head2 tailable
152
- -
16512µs1192µshas tailable => (
# spent 192µs making 1 call to Mouse::has
166 is => 'rw',
167 isa => 'Bool',
168 required => 0,
169 default => 0,
170);
171
172=head2 slave_okay
173
- -
18212µs1192µshas slave_okay => (
# spent 192µs making 1 call to Mouse::has
183 is => 'rw',
184 isa => 'Bool',
185 required => 0,
186 default => 0,
187);
188
189
190# stupid hack for inconsistent database handling of queries
19112µs1207µshas _grrrr => (
# spent 207µs making 1 call to Mouse::has
192 is => 'rw',
193 isa => 'Bool',
194 default => 0,
195);
196
19712µs1199µshas _request_id => (
# spent 199µs making 1 call to Mouse::has
198 is => 'rw',
199 isa => 'Int',
200 default => 0,
201);
202
203=head1 METHODS
204
- -
207sub _ensure_special {
208 my ($self) = @_;
209
210 if ($self->_grrrr) {
211 return;
212 }
213
214 $self->_grrrr(1);
215 $self->_query({'query' => $self->_query})
216}
217
218# this does the query if it hasn't been done yet
219sub _do_query {
220 my ($self) = @_;
221
222 if ($self->started_iterating) {
223 return;
224 }
225
226 my $opts = $MongoDB::Cursor::slave_okay | ($self->tailable << 1) |
227 ($self->slave_okay << 2) | ($self->immortal << 4);
228
229 my ($query, $info) = MongoDB::write_query($self->_ns, $opts, $self->_skip, $self->_limit, $self->_query, $self->_fields);
230 $self->_request_id($info->{'request_id'});
231
232 $self->_connection->send($query);
233 $self->_connection->recv($self);
234
235 $self->started_iterating(1);
236}
237
238=head2 fields (\%f)
239
- -
251sub fields {
252 my ($self, $f) = @_;
253 confess "cannot set fields after querying"
254 if $self->started_iterating;
255 confess 'not a hash reference'
256 unless ref $f eq 'HASH';
257
258 $self->_fields($f);
259 return $self;
260}
261
262=head2 sort ($order)
263
- -
274sub sort {
275 my ($self, $order) = @_;
276 confess "cannot set sort after querying"
277 if $self->started_iterating;
278 confess 'not a hash reference'
279 unless ref $order eq 'HASH' || ref $order eq 'Tie::IxHash';
280
281 $self->_ensure_special;
282 $self->_query->{'orderby'} = $order;
283 return $self;
284}
285
286
287=head2 limit ($num)
288
- -
297sub limit {
298 my ($self, $num) = @_;
299 confess "cannot set limit after querying"
300 if $self->started_iterating;
301
302 $self->_limit($num);
303 return $self;
304}
305
306=head2 skip ($num)
307
- -
318sub skip {
319 my ($self, $num) = @_;
320 confess "cannot set skip after querying"
321 if $self->started_iterating;
322
323 $self->_skip($num);
324 return $self;
325}
326
327=head2 snapshot
328
- -
342sub snapshot {
343 my ($self) = @_;
344 confess "cannot set snapshot after querying"
345 if $self->started_iterating;
346
347 $self->_ensure_special;
348 $self->_query->{'$snapshot'} = 1;
349 return $self;
350}
351
352=head2 hint
353
- -
360sub hint {
361 my ($self, $index) = @_;
362 confess "cannot set hint after querying"
363 if $self->started_iterating;
364 confess 'not a hash reference'
365 unless ref $index eq 'HASH';
366
367 $self->_ensure_special;
368 $self->_query->{'$hint'} = $index;
369 return $self;
370}
371
372=head2 explain
373
- -
388sub explain {
389 my ($self) = @_;
390 my $temp = $self->_limit;
391 if ($self->_limit > 0) {
392 $self->_limit($self->_limit * -1);
393 }
394
395 $self->_ensure_special;
396 $self->_query->{'$explain'} = boolean::true;
397
398 my $retval = $self->reset->next;
399 $self->reset->limit($temp);
400
401 undef $self->_query->{'$explain'};
402
403 return $retval;
404}
405
406=head2 count($all?)
407
- -
417sub count {
418 my ($self, $all) = @_;
419
420 my ($db, $coll) = $self->_ns =~ m/^([^\.]+)\.(.*)/;
421 my $cmd = new Tie::IxHash(count => $coll);
422
423 if ($self->_grrrr) {
424 $cmd->Push(query => $self->_query->{'query'});
425 }
426 else {
427 $cmd->Push(query => $self->_query);
428 }
429
430 if ($all) {
431 $cmd->Push(limit => $self->_limit) if $self->_limit;
432 $cmd->Push(skip => $self->_skip) if $self->_skip;
433 }
434
435 my $result = $self->_connection->get_database($db)->run_command($cmd);
436
437 # returns "ns missing" if collection doesn't exist
438 return 0 unless ref $result eq 'HASH';
439 return $result->{'n'};
440}
441
442=head2 reset
443
- -
476sub all {
477 my ($self) = @_;
478 my @ret;
479
480 while (my $entry = $self->next) {
481 push @ret, $entry;
482 }
483
484 return @ret;
485}
486
487356µs2284µs
# spent 148µs (11+137) within MongoDB::Cursor::BEGIN@487 which was called: # once (11µs+137µs) by MongoDB::Connection::BEGIN@23 at line 487
no Any::Moose;
# spent 148µs making 1 call to MongoDB::Cursor::BEGIN@487 # spent 137µs making 1 call to Any::Moose::unimport
48816µs276µs__PACKAGE__->meta->make_immutable (inline_destructor => 0);
# spent 67µs making 1 call to Mouse::Meta::Class::make_immutable # spent 9µs making 1 call to MongoDB::Cursor::meta
489
490127µs1;
491
492=head1 AUTHOR