← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:13 2014

Filename/usr/local/lib/perl/5.14.2/MongoDB/Database.pm
StatementsExecuted 24 statements in 695µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.12ms31.3msMongoDB::Database::::BEGIN@26MongoDB::Database::BEGIN@26
22238µs5.74sMongoDB::Database::::run_commandMongoDB::Database::run_command
32212µs66µsMongoDB::Database::::get_collectionMongoDB::Database::get_collection
11112µs3.37msMongoDB::Database::::BEGIN@25MongoDB::Database::BEGIN@25
1117µs32µsMongoDB::Database::::BEGIN@27MongoDB::Database::BEGIN@27
0000s0sMongoDB::Database::::AUTOLOADMongoDB::Database::AUTOLOAD
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
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-2013 MongoDB, 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;
18{
1921µs $MongoDB::Database::VERSION = '0.702.2';
20}
21
22
23# ABSTRACT: A MongoDB Database
24
25233µs26.73ms
# spent 3.37ms (12µs+3.36) within MongoDB::Database::BEGIN@25 which was called: # once (12µs+3.36ms) by MongoDB::BEGIN@30 at line 25
use Moose;
# spent 3.37ms making 1 call to MongoDB::Database::BEGIN@25 # spent 3.36ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:519]
262118µs131.3ms
# spent 31.3ms (1.12+30.2) within MongoDB::Database::BEGIN@26 which was called: # once (1.12ms+30.2ms) by MongoDB::BEGIN@30 at line 26
use MongoDB::GridFS;
# spent 31.3ms making 1 call to MongoDB::Database::BEGIN@26
272468µs257µs
# spent 32µs (7+25) within MongoDB::Database::BEGIN@27 which was called: # once (7µs+25µs) by MongoDB::BEGIN@30 at line 27
use Carp 'carp';
# spent 32µs making 1 call to MongoDB::Database::BEGIN@27 # spent 25µs making 1 call to Exporter::import
28
2912µs11.48mshas _client => (
# spent 1.48ms making 1 call to Moose::has
30 is => 'ro',
31 isa => 'MongoDB::MongoClient',
32 required => 1,
33);
34
3512µs11.44mshas name => (
# spent 1.44ms making 1 call to Moose::has
36 is => 'ro',
37 isa => 'Str',
38 required => 1,
39);
40
41
42sub AUTOLOAD {
43 my $self = shift @_;
44 our $AUTOLOAD;
45
46 my $coll = $AUTOLOAD;
47 $coll =~ s/.*:://;
48
49 carp sprintf q{AUTOLOADed collection method names are deprecated and will be removed in a future release. Use $db->get_collection( '%s' ) instead.}, $coll;
50
51 return $self->get_collection($coll);
52}
53
54
55sub collection_names {
56 my ($self) = @_;
57 my $it = $self->get_collection('system.namespaces')->query({});
58 return grep {
59 not ( index( $_, '$' ) >= 0 && index( $_, '.oplog.$' ) < 0 )
60 } map {
61 substr $_->{name}, length( $self->name ) + 1
62 } $it->all;
63}
64
65
66
# spent 66µs (12+54) within MongoDB::Database::get_collection which was called 3 times, avg 22µs/call: # 2 times (9µs+38µs) by MongoDB::Database::run_command at line 109, avg 23µs/call # once (4µs+16µs) by Mentat::Storage::Mongo::reconnect at line 586 of Mentat/Storage/Mongo.pm
sub get_collection {
67613µs my ($self, $collection_name) = @_;
68354µs return MongoDB::Collection->new(
# spent 54µs making 3 calls to MongoDB::Collection::new, avg 18µs/call
69 _database => $self,
70 name => $collection_name,
71 );
72}
73
74
75sub get_gridfs {
76 my ($self, $prefix) = @_;
77 $prefix = "fs" unless $prefix;
78
79 return MongoDB::GridFS->new(
80 _database => $self,
81 prefix => $prefix
82 );
83}
84
85
86sub drop {
87 my ($self) = @_;
88 return $self->run_command({ 'dropDatabase' => 1 });
89}
90
91
92sub last_error {
93 my ($self, $options) = @_;
94
95 my $cmd = Tie::IxHash->new("getlasterror" => 1);
96 if ($options) {
97 $cmd->Push("w", $options->{w}) if $options->{w};
98 $cmd->Push("wtimeout", $options->{wtimeout}) if $options->{wtimeout};
99 $cmd->Push("fsync", $options->{fsync}) if $options->{fsync};
100 $cmd->Push("j", 1) if $options->{j};
101 }
102
103 return $self->run_command($cmd);
104}
105
106
107
# spent 5.74s (38µs+5.74) within MongoDB::Database::run_command which was called 2 times, avg 2.87s/call: # once (20µs+5.74s) by MongoDB::Cursor::count at line 286 of MongoDB/Cursor.pm # once (18µs+631µs) by MongoDB::MongoClient::_get_max_bson_size at line 285 of MongoDB/MongoClient.pm
sub run_command {
108624µs my ($self, $command) = @_;
10945.74s my $obj = $self->get_collection('$cmd')->find_one($command);
# spent 5.74s making 2 calls to MongoDB::Collection::find_one, avg 2.87s/call # spent 47µs making 2 calls to MongoDB::Database::get_collection, avg 23µs/call
110124µs1045µs return $obj if $obj->{ok};
# spent 24µs making 2 calls to MongoDB::Cursor::DESTROY, avg 12µs/call # spent 14µs making 2 calls to MongoDB::Collection::DESTROY, avg 7µs/call # spent 5µs making 4 calls to MongoDB::Cursor::_client, avg 1µs/call # spent 2µs making 2 calls to MongoDB::Cursor::_request_id, avg 1µs/call
111 $obj->{'errmsg'};
112}
113
114
115sub eval {
116 my ($self, $code, $args) = @_;
117
118 my $cmd = tie(my %hash, 'Tie::IxHash');
119 %hash = ('$eval' => $code,
120 'args' => $args);
121
122 my $result = $self->run_command($cmd);
123 if (ref $result eq 'HASH' && exists $result->{'retval'}) {
124 return $result->{'retval'};
125 }
126 else {
127 return $result;
128 }
129}
130
13113µs23.14ms__PACKAGE__->meta->make_immutable;
# spent 3.13ms making 1 call to Class::MOP::Class::make_immutable # spent 13µs making 1 call to MongoDB::Database::meta
132
13317µs1;
134
135__END__