Filename | /usr/local/lib/perl/5.14.2/MongoDB/Database.pm |
Statements | Executed 24 statements in 796µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.20ms | 27.8ms | BEGIN@26 | MongoDB::Database::
2 | 2 | 2 | 44µs | 5.85s | run_command | MongoDB::Database::
3 | 2 | 2 | 28µs | 91µs | get_collection | MongoDB::Database::
1 | 1 | 1 | 13µs | 3.52ms | BEGIN@25 | MongoDB::Database::
1 | 1 | 1 | 8µs | 33µs | BEGIN@27 | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | AUTOLOAD | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | collection_names | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | drop | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | eval | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | get_gridfs | MongoDB::Database::
0 | 0 | 0 | 0s | 0s | last_error | MongoDB::Database::
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 | |||||
17 | package MongoDB::Database; | ||||
18 | { | ||||
19 | 2 | 1µs | $MongoDB::Database::VERSION = '0.702.2'; | ||
20 | } | ||||
21 | |||||
22 | |||||
23 | # ABSTRACT: A MongoDB Database | ||||
24 | |||||
25 | 2 | 35µs | 2 | 7.03ms | # spent 3.52ms (13µs+3.51) within MongoDB::Database::BEGIN@25 which was called:
# once (13µs+3.51ms) by MongoDB::BEGIN@30 at line 25 # spent 3.52ms making 1 call to MongoDB::Database::BEGIN@25
# spent 3.51ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:519] |
26 | 2 | 137µs | 1 | 27.8ms | # spent 27.8ms (1.20+26.6) within MongoDB::Database::BEGIN@26 which was called:
# once (1.20ms+26.6ms) by MongoDB::BEGIN@30 at line 26 # spent 27.8ms making 1 call to MongoDB::Database::BEGIN@26 |
27 | 2 | 527µs | 2 | 58µs | # spent 33µs (8+25) within MongoDB::Database::BEGIN@27 which was called:
# once (8µs+25µs) by MongoDB::BEGIN@30 at line 27 # spent 33µs making 1 call to MongoDB::Database::BEGIN@27
# spent 25µs making 1 call to Exporter::import |
28 | |||||
29 | 1 | 2µs | 1 | 1.49ms | has _client => ( # spent 1.49ms making 1 call to Moose::has |
30 | is => 'ro', | ||||
31 | isa => 'MongoDB::MongoClient', | ||||
32 | required => 1, | ||||
33 | ); | ||||
34 | |||||
35 | 1 | 2µs | 1 | 1.44ms | has name => ( # spent 1.44ms making 1 call to Moose::has |
36 | is => 'ro', | ||||
37 | isa => 'Str', | ||||
38 | required => 1, | ||||
39 | ); | ||||
40 | |||||
41 | |||||
42 | sub 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 | |||||
55 | sub 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 91µs (28+63) within MongoDB::Database::get_collection which was called 3 times, avg 30µs/call:
# 2 times (24µs+47µs) by MongoDB::Database::run_command at line 109, avg 36µs/call
# once (4µs+16µs) by Mentat::Storage::Mongo::reconnect at line 586 of Mentat/Storage/Mongo.pm | ||||
67 | 3 | 3µs | my ($self, $collection_name) = @_; | ||
68 | 3 | 13µs | 3 | 63µs | return MongoDB::Collection->new( # spent 63µs making 3 calls to MongoDB::Collection::new, avg 21µs/call |
69 | _database => $self, | ||||
70 | name => $collection_name, | ||||
71 | ); | ||||
72 | } | ||||
73 | |||||
74 | |||||
75 | sub 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 | |||||
86 | sub drop { | ||||
87 | my ($self) = @_; | ||||
88 | return $self->run_command({ 'dropDatabase' => 1 }); | ||||
89 | } | ||||
90 | |||||
91 | |||||
92 | sub 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.85s (44µs+5.85) within MongoDB::Database::run_command which was called 2 times, avg 2.92s/call:
# once (20µs+5.85s) by MongoDB::Cursor::count at line 286 of MongoDB/Cursor.pm
# once (24µs+797µs) by MongoDB::MongoClient::_get_max_bson_size at line 285 of MongoDB/MongoClient.pm | ||||
108 | 2 | 1µs | my ($self, $command) = @_; | ||
109 | 2 | 16µs | 4 | 5.85s | my $obj = $self->get_collection('$cmd')->find_one($command); # spent 5.85s making 2 calls to MongoDB::Collection::find_one, avg 2.92s/call
# spent 71µs making 2 calls to MongoDB::Database::get_collection, avg 36µs/call |
110 | 2 | 38µs | 10 | 49µs | return $obj if $obj->{ok}; # spent 25µs making 2 calls to MongoDB::Cursor::DESTROY, avg 13µs/call
# spent 16µs making 2 calls to MongoDB::Collection::DESTROY, avg 8µ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 | |||||
115 | sub 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 | |||||
131 | 1 | 3µs | 2 | 3.47ms | __PACKAGE__->meta->make_immutable; # spent 3.46ms making 1 call to Class::MOP::Class::make_immutable
# spent 13µs making 1 call to MongoDB::Database::meta |
132 | |||||
133 | 1 | 19µs | 1; | ||
134 | |||||
135 | __END__ |