← 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/Database.pm
StatementsExecuted 23 statements in 1.03ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
100000011741ms741msMongoDB::Database::::_connectionMongoDB::Database::_connection (xsub)
1111.46ms160msMongoDB::Database::::BEGIN@23MongoDB::Database::BEGIN@23
11116µs417µsMongoDB::Database::::BEGIN@22MongoDB::Database::BEGIN@22
11113µs127µsMongoDB::Database::::AUTOLOADMongoDB::Database::AUTOLOAD
11112µs154µsMongoDB::Database::::BEGIN@328MongoDB::Database::BEGIN@328
1117µs110µsMongoDB::Database::::get_collectionMongoDB::Database::get_collection
1116µs4.07msMongoDB::Database::::BUILDMongoDB::Database::BUILD
1114µs4µsMongoDB::Database::::CORE:substMongoDB::Database::CORE:subst (opcode)
111800ns800nsMongoDB::Database::::nameMongoDB::Database::name (xsub)
0000s0sMongoDB::Database::::collection_namesMongoDB::Database::collection_names
0000s0sMongoDB::Database::::dropMongoDB::Database::drop
0000s0sMongoDB::Database::::evalMongoDB::Database::eval
0000s0sMongoDB::Database::::get_gridfsMongoDB::Database::get_gridfs
0000s0sMongoDB::Database::::last_errorMongoDB::Database::last_error
0000s0sMongoDB::Database::::run_commandMongoDB::Database::run_command
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::Database;
181900nsour $VERSION = '0.42';
19
20# ABSTRACT: A Mongo Database
21
22336µs2818µs
# spent 417µs (16+401) within MongoDB::Database::BEGIN@22 which was called: # once (16µs+401µs) by MongoDB::Connection::BEGIN@2 at line 22
use Any::Moose;
# spent 417µs making 1 call to MongoDB::Database::BEGIN@22 # spent 401µs making 1 call to Any::Moose::import
233849µs1160ms
# spent 160ms (1.46+159) within MongoDB::Database::BEGIN@23 which was called: # once (1.46ms+159ms) by MongoDB::Connection::BEGIN@2 at line 23
use MongoDB::GridFS;
# spent 160ms making 1 call to MongoDB::Database::BEGIN@23
24
2512µs1214µshas _connection => (
# spent 214µs making 1 call to Mouse::has
26 is => 'ro',
27 isa => 'MongoDB::Connection',
28 required => 1,
29);
30
31=head1 NAME
32
- -
5712µs1197µshas name => (
# spent 197µs making 1 call to Mouse::has
58 is => 'ro',
59 isa => 'Str',
60 required => 1,
61);
62
63
64
# spent 127µs (13+114) within MongoDB::Database::AUTOLOAD which was called: # once (13µs+114µs) by main::RUNTIME at line 16 of mongo_pain.pl
sub AUTOLOAD {
651600ns my $self = shift @_;
661200ns our $AUTOLOAD;
67
681400ns my $coll = $AUTOLOAD;
6919µs14µs $coll =~ s/.*:://;
# spent 4µs making 1 call to MongoDB::Database::CORE:subst
70
7116µs1110µs return $self->get_collection($coll);
# spent 110µs making 1 call to MongoDB::Database::get_collection
72}
73
74
# spent 4.07ms (6µs+4.06) within MongoDB::Database::BUILD which was called: # once (6µs+4.06ms) by Mouse::Object::new at line 531 of MongoDB/Connection.pm
sub BUILD {
751800ns my ($self) = @_;
7614µs14.06ms Any::Moose::load_class("MongoDB::Collection");
# spent 4.06ms making 1 call to Mouse::Util::load_class
77}
78
79=head1 METHODS
80
- -
89sub collection_names {
90 my ($self) = @_;
91 my $it = $self->get_collection('system.namespaces')->query({});
92 return map {
93 substr($_, length($self->name) + 1)
94 } map { $_->{name} } $it->all;
95}
96
97=head2 get_collection ($name)
98
- -
106
# spent 110µs (7+103) within MongoDB::Database::get_collection which was called: # once (7µs+103µs) by MongoDB::Database::AUTOLOAD at line 71
sub get_collection {
10711µs my ($self, $collection_name) = @_;
108159µs7159µs return MongoDB::Collection->new(
# spent 103µs making 1 call to Mouse::Object::new # spent 49µs making 1 call to Mouse::Meta::Class::_calculate_all_attributes # spent 2µs making 1 call to Mouse::Meta::Class::strict_constructor # spent 2µs making 2 calls to Mouse::Meta::TypeConstraint::_compiled_type_constraint, avg 1µs/call # spent 1µs making 1 call to Mouse::Meta::Class::is_immutable # spent 900ns making 1 call to Mouse::Meta::Class::is_anon_class
109 _database => $self,
110 name => $collection_name,
111 );
112}
113
114=head2 get_gridfs ($prefix?)
115
- -
126sub get_gridfs {
127 my ($self, $prefix) = @_;
128 $prefix = "fs" unless $prefix;
129
130 return MongoDB::GridFS->new(
131 _database => $self,
132 prefix => $prefix
133 );
134}
135
136=head2 drop
137
- -
144sub drop {
145 my ($self) = @_;
146 return $self->run_command({ 'dropDatabase' => 1 });
147}
148
149
150=head2 last_error($options?)
151
- -
256sub last_error {
257 my ($self, $options) = @_;
258
259 my $cmd = Tie::IxHash->new("getlasterror" => 1);
260 if ($options) {
261 $cmd->Push("w", $options->{w}) if $options->{w};
262 $cmd->Push("wtimeout", $options->{wtimeout}) if $options->{wtimeout};
263 $cmd->Push("fsync", $options->{fsync}) if $options->{fsync};
264 }
265
266 return $self->run_command($cmd);
267}
268
269
270=head2 run_command ($command)
271
- -
288sub run_command {
289 my ($self, $command) = @_;
290 my $obj = $self->get_collection('$cmd')->find_one($command);
291 return $obj if $obj->{ok};
292 $obj->{'errmsg'};
293}
294
295
296=head2 eval ($code, $args?)
297
- -
312sub eval {
313 my ($self, $code, $args) = @_;
314
315 my $cmd = tie(my %hash, 'Tie::IxHash');
316 %hash = ('$eval' => $code,
317 'args' => $args);
318
319 my $result = $self->run_command($cmd);
320 if (ref $result eq 'HASH' && exists $result->{'retval'}) {
321 return $result->{'retval'};
322 }
323 else {
324 return $result;
325 }
326}
327
328343µs2296µs
# spent 154µs (12+142) within MongoDB::Database::BEGIN@328 which was called: # once (12µs+142µs) by MongoDB::Connection::BEGIN@2 at line 328
no Any::Moose;
# spent 154µs making 1 call to MongoDB::Database::BEGIN@328 # spent 142µs making 1 call to Any::Moose::unimport
32917µs2130µs__PACKAGE__->meta->make_immutable;
# spent 119µs making 1 call to Mouse::Meta::Class::make_immutable # spent 11µs making 1 call to MongoDB::Database::meta
330
33119µs1;
332
333=head1 AUTHOR
 
# spent 4µs within MongoDB::Database::CORE:subst which was called: # once (4µs+0s) by MongoDB::Database::AUTOLOAD at line 69
sub MongoDB::Database::CORE:subst; # opcode
# spent 741ms within MongoDB::Database::_connection which was called 1000000 times, avg 741ns/call: # 1000000 times (741ms+0s) by MongoDB::Collection::batch_insert at line 303 of MongoDB/Collection.pm, avg 741ns/call
sub MongoDB::Database::_connection; # xsub
# spent 800ns within MongoDB::Database::name which was called: # once (800ns+0s) by MongoDB::Collection::_build_full_name at line 88 of MongoDB/Collection.pm
sub MongoDB::Database::name; # xsub