← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename/home/mickey/git_tree/PONAPI/Server/lib/PONAPI/Builder/Document.pm
StatementsExecuted 4058633 statements in 13.7s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
100001118.03s58.8sPONAPI::Builder::Document::::buildPONAPI::Builder::Document::build
183655114.56s40.6sPONAPI::Builder::Document::::add_resourcePONAPI::Builder::Document::add_resource
233411212.35s3.45sPONAPI::Builder::Document::::has_resourcePONAPI::Builder::Document::has_resource
100001111.40s3.27sPONAPI::Builder::Document::::add_self_linkPONAPI::Builder::Document::add_self_link
86592111.28s15.1sPONAPI::Builder::Document::::add_includedPONAPI::Builder::Document::add_included
5024511424ms693msPONAPI::Builder::Document::::convert_to_collectionPONAPI::Builder::Document::convert_to_collection
10000111264ms264msPONAPI::Builder::Document::::__ANON__[lib/PONAPI/Builder/Document.pm:70]PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:70]
10000121214ms214msPONAPI::Builder::Document::::__ANON__[lib/PONAPI/Builder/Document.pm:56]PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:56]
10000111205ms205msPONAPI::Builder::Document::::__ANON__[lib/PONAPI/Builder/Document.pm:25]PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:25]
111758µs435msPONAPI::Builder::Document::::BEGIN@6PONAPI::Builder::Document::BEGIN@6
111310µs25.0msPONAPI::Builder::Document::::BEGIN@8PONAPI::Builder::Document::BEGIN@8
111200µs8.97msPONAPI::Builder::Document::::BEGIN@7PONAPI::Builder::Document::BEGIN@7
11117µs2.94msPONAPI::Builder::Document::::BEGIN@4PONAPI::Builder::Document::BEGIN@4
11110µs88µsPONAPI::Builder::Document::::BEGIN@205PONAPI::Builder::Document::BEGIN@205
0000s0sPONAPI::Builder::Document::::__ANON__[lib/PONAPI/Builder/Document.pm:34]PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:34]
0000s0sPONAPI::Builder::Document::::__ANON__[lib/PONAPI/Builder/Document.pm:40]PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:40]
0000s0sPONAPI::Builder::Document::::_build_errors_builderPONAPI::Builder::Document::_build_errors_builder
0000s0sPONAPI::Builder::Document::::add_null_resourcePONAPI::Builder::Document::add_null_resource
0000s0sPONAPI::Builder::Document::::has_errorsPONAPI::Builder::Document::has_errors
0000s0sPONAPI::Builder::Document::::has_resourcesPONAPI::Builder::Document::has_resources
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# ABSTRACT: document builder class
2package PONAPI::Builder::Document;
3
4240µs25.86ms
# spent 2.94ms (17µs+2.92) within PONAPI::Builder::Document::BEGIN@4 which was called: # once (17µs+2.92ms) by PONAPI::DAO::Request::BEGIN@7 at line 4
use Moose;
# spent 2.94ms making 1 call to PONAPI::Builder::Document::BEGIN@4 # spent 2.92ms making 1 call to Moose::import
5
62111µs1435ms
# spent 435ms (758µs+434) within PONAPI::Builder::Document::BEGIN@6 which was called: # once (758µs+434ms) by PONAPI::DAO::Request::BEGIN@7 at line 6
use PONAPI::Builder::Resource;
# spent 435ms making 1 call to PONAPI::Builder::Document::BEGIN@6
72117µs18.97ms
# spent 8.97ms (200µs+8.77) within PONAPI::Builder::Document::BEGIN@7 which was called: # once (200µs+8.77ms) by PONAPI::DAO::Request::BEGIN@7 at line 7
use PONAPI::Builder::Resource::Null;
# spent 8.97ms making 1 call to PONAPI::Builder::Document::BEGIN@7
82740µs125.0ms
# spent 25.0ms (310µs+24.7) within PONAPI::Builder::Document::BEGIN@8 which was called: # once (310µs+24.7ms) by PONAPI::DAO::Request::BEGIN@7 at line 8
use PONAPI::Builder::Errors;
# spent 25.0ms making 1 call to PONAPI::Builder::Document::BEGIN@8
9
1013µs124.7mswith 'PONAPI::Builder',
# spent 24.7ms making 1 call to Moose::with
11 'PONAPI::Builder::Role::HasLinksBuilder',
12 'PONAPI::Builder::Role::HasMeta',
13 'PONAPI::Builder::Role::HasPagination';
14
1514µs11.70mshas version => (
# spent 1.70ms making 1 call to Moose::has
16 is => 'ro',
17 isa => 'Str',
18 required => 1,
19);
20
21has status => (
22 init_arg => undef,
23 is => 'ro',
24 isa => 'Num',
25100001559ms
# spent 205ms within PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:25] which was called 100001 times, avg 2µs/call: # 100001 times (205ms+0s) by PONAPI::Builder::Document::status at line 12 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call
default => sub { 200 },
2614µs13.33ms writer => 'set_status',
# spent 3.33ms making 1 call to Moose::has
27 lazy => 1,
28 predicate => 'has_status',
29);
30
31has req_base => (
32 is => 'ro',
33 isa => 'Str',
34 default => sub { '/' },
3515µs11.30ms);
# spent 1.30ms making 1 call to Moose::has
36
37has req_path => (
38 is => 'ro',
39 isa => 'Str',
40 default => sub { '/' },
4114µs11.25ms);
# spent 1.25ms making 1 call to Moose::has
42
4311µs12.23mshas is_collection => (
# spent 2.23ms making 1 call to Moose::has
44 is => 'ro',
45 writer => '_set_is_collection',
46 isa => 'Bool',
47 default => 0
48);
49
50has _included => (
51 init_arg => undef,
52 traits => [ 'Array' ],
53 is => 'ro',
54 isa => 'ArrayRef[ PONAPI::Builder::Resource ]',
55 lazy => 1,
56100001535ms
# spent 214ms within PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:56] which was called 100001 times, avg 2µs/call: # 55431 times (118ms+0s) by PONAPI::Builder::Document::has_included at line 14 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call # 44570 times (96.6ms+0s) by PONAPI::Builder::Document::_add_included at line 13 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call
default => sub { +[] },
5717µs16.48ms handles => {
# spent 6.48ms making 1 call to Moose::has
58 'has_included' => 'count',
59 # private ...
60 '_add_included' => 'push',
61 }
62);
63
64has _resource_builders => (
65 init_arg => undef,
66 traits => [ 'Array' ],
67 is => 'ro',
68 isa => 'ArrayRef[ PONAPI::Builder::Resource | PONAPI::Builder::Resource::Null ]',
69 lazy => 1,
70100001628ms
# spent 264ms within PONAPI::Builder::Document::__ANON__[lib/PONAPI/Builder/Document.pm:70] which was called 100001 times, avg 3µs/call: # 100001 times (264ms+0s) by PONAPI::Builder::Document::_add_resource_builder at line 13 of (eval 45)[Eval/Closure.pm:144], avg 3µs/call
default => sub { +[] },
7119µs115.7ms predicate => 'has_resource_builders',
# spent 15.7ms making 1 call to Moose::has
72 handles => {
73 '_num_resource_builders' => 'count',
74 # private ...
75 '_add_resource_builder' => 'push',
76 '_get_resource_builder' => 'get',
77 }
78);
79
8012µs12.55mshas errors_builder => (
# spent 2.55ms making 1 call to Moose::has
81 init_arg => undef,
82 is => 'ro',
83 isa => 'PONAPI::Builder::Errors',
84 lazy => 1,
85 predicate => 'has_errors_builder',
86 builder => '_build_errors_builder',
87);
88
89sub _build_errors_builder { PONAPI::Builder::Errors->new( parent => $_[0] ) }
90
9150245381ms50245270ms
# spent 693ms (424+270) within PONAPI::Builder::Document::convert_to_collection which was called 50245 times, avg 14µs/call: # 50245 times (424ms+270ms) by PONAPI::DAO::Request::RetrieveAll::execute at line 19 of lib/PONAPI/DAO/Request/RetrieveAll.pm, avg 14µs/call
sub convert_to_collection { $_[0]->_set_is_collection(1) }
# spent 270ms making 50245 calls to PONAPI::Builder::Document::_set_is_collection, avg 5µs/call
92
93sub has_errors {
94 my $self = shift;
95 return $self->errors_builder->has_errors
96 if $self->has_errors_builder and $self->errors_builder->has_errors;
97 return 0;
98}
99
100
# spent 3.45s (2.35+1.11) within PONAPI::Builder::Document::has_resource which was called 233411 times, avg 15µs/call: # 183655 times (1.82s+862ms) by PONAPI::Builder::Document::add_resource at line 113, avg 15µs/call # 49756 times (524ms+243ms) by PONAPI::Builder::Document::build at line 160, avg 15µs/call
sub has_resource {
101233411101ms my $self = shift;
1022334111.70s3668211.11s $self->has_resource_builders && $self->_num_resource_builders > 0;
# spent 557ms making 233411 calls to PONAPI::Builder::Document::has_resource_builders, avg 2µs/call # spent 548ms making 133410 calls to PONAPI::Builder::Document::_num_resource_builders, avg 4µs/call
103}
104
105sub has_resources {
106 my $self = shift;
107 $self->has_resource_builders && $self->_num_resource_builders > 1;
108}
109
110
# spent 40.6s (4.56+36.0) within PONAPI::Builder::Document::add_resource which was called 183655 times, avg 221µs/call: # 183655 times (4.56s+36.0s) by Test::PONAPI::Repository::MockDB::_add_resources at line 563 of lib/Test/PONAPI/Repository/MockDB.pm, avg 221µs/call
sub add_resource {
111183655319ms my ($self, %args) = @_;
112
113183655589ms2673092.91s die 'Cannot add more then one resource unless the Document is in collection mode'
# spent 2.69s making 183655 calls to PONAPI::Builder::Document::has_resource, avg 15µs/call # spent 224ms making 83654 calls to PONAPI::Builder::Document::is_collection, avg 3µs/call
114 if $self->has_resource && !$self->is_collection;
115
1161836551.08s18365527.4s my $builder = PONAPI::Builder::Resource->new( %args, parent => $self );
# spent 27.4s making 183655 calls to PONAPI::Builder::Resource::new, avg 149µs/call
117183655429ms1836555.77s $self->_add_resource_builder( $builder );
# spent 5.77s making 183655 calls to PONAPI::Builder::Document::_add_resource_builder, avg 31µs/call
118183655969ms return $builder;
119}
120
121sub add_null_resource {
122 my $self = shift;
123
124 my $builder = PONAPI::Builder::Resource::Null->new( parent => $self );
125 $self->_add_resource_builder( $builder );
126 return $builder;
127}
128
129
# spent 15.1s (1.28+13.9) within PONAPI::Builder::Document::add_included which was called 86592 times, avg 175µs/call: # 86592 times (1.28s+13.9s) by Test::PONAPI::Repository::MockDB::_add_included at line 686 of lib/Test/PONAPI/Repository/MockDB.pm, avg 175µs/call
sub add_included {
13086592140ms my ($self, %args) = @_;
13186592313ms8659211.6s my $builder = PONAPI::Builder::Resource->new( parent => $self, %args );
# spent 11.6s making 86592 calls to PONAPI::Builder::Resource::new, avg 134µs/call
13286592191ms865922.22s $self->_add_included( $builder );
# spent 2.22s making 86592 calls to PONAPI::Builder::Document::_add_included, avg 26µs/call
13386592408ms return $builder;
134}
135
136
# spent 3.27s (1.40+1.87) within PONAPI::Builder::Document::add_self_link which was called 100001 times, avg 33µs/call: # 100001 times (1.40s+1.87s) by PONAPI::DAO::Request::response at line 140 of lib/PONAPI/DAO/Request.pm, avg 33µs/call
sub add_self_link {
13710000144.6ms my $self = shift;
138100001463ms3000031.87s $self->links_builder->add_link( self => $self->req_path );
# spent 1.40s making 100001 calls to PONAPI::Builder::Links::add_link, avg 14µs/call # spent 297ms making 100001 calls to PONAPI::Builder::Document::req_path, avg 3µs/call # spent 167ms making 100001 calls to PONAPI::Builder::Document::links_builder, avg 2µs/call
139100001423ms return $self;
140}
141
142
# spent 58.8s (8.03+50.8) within PONAPI::Builder::Document::build which was called 100001 times, avg 588µs/call: # 100001 times (8.03s+50.8s) by PONAPI::DAO::Request::response at line 144 of lib/PONAPI/DAO/Request.pm, avg 588µs/call
sub build {
14310000151.0ms my $self = shift;
14410000171.4ms my %args = @_;
145100001420ms100001264ms my $result = +{ jsonapi => { version => $self->version } };
# spent 264ms making 100001 calls to PONAPI::Builder::Document::version, avg 3µs/call
146
147100001272ms100001238ms if ( ! $self->has_errors_builder ) {
# spent 238ms making 100001 calls to PONAPI::Builder::Document::has_errors_builder, avg 2µs/call
148100001231ms100001372ms $result->{meta} = $self->_meta if $self->has_meta;
# spent 372ms making 100001 calls to PONAPI::Builder::Document::has_meta, avg 4µs/call
149100001555ms3000032.95s $result->{links} = $self->links_builder->build if $self->has_links_builder;
# spent 2.58s making 100001 calls to PONAPI::Builder::Links::build, avg 26µs/call # spent 229ms making 100001 calls to PONAPI::Builder::Document::has_links_builder, avg 2µs/call # spent 146ms making 100001 calls to PONAPI::Builder::Document::links_builder, avg 1µs/call
150
151100001221ms100001169ms if ( $self->has_resource_builders ) {
# spent 169ms making 100001 calls to PONAPI::Builder::Document::has_resource_builders, avg 2µs/call
152100001261ms100001254ms if ( $self->is_collection ) {
# spent 254ms making 100001 calls to PONAPI::Builder::Document::is_collection, avg 3µs/call
153 # if it is a collection, then
154 # call build on each one ...
155184144449ms18414425.2s $result->{data} = [ map { $_->build( %args ) } @{ $self->_resource_builders } ];
# spent 25.0s making 133899 calls to PONAPI::Builder::Resource::build, avg 187µs/call # spent 182ms making 50245 calls to PONAPI::Builder::Document::_resource_builders, avg 4µs/call
156 }
157 else {
158 # if it is a single resource,
159 # just use that one
16049756340ms14926812.0s $result->{data} = $self->_get_resource_builder(0)->build( %args )
# spent 10.7s making 49756 calls to PONAPI::Builder::Resource::build, avg 215µs/call # spent 767ms making 49756 calls to PONAPI::Builder::Document::has_resource, avg 15µs/call # spent 562ms making 49756 calls to PONAPI::Builder::Document::_get_resource_builder, avg 11µs/call
161 if $self->has_resource;
162 }
163
164
165 # http://jsonapi.org/format/#document-compound-documents
166 # "A compound document MUST NOT include more than one resource
167 # object for each type and id pair."
168 # So in short, we need to check that we don't have any duplicates.
169100001307ms1000011.72s if ( $self->has_included ) {
# spent 1.72s making 100001 calls to PONAPI::Builder::Document::has_included, avg 17µs/call
17044570106ms44570162ms my $included_builders = $self->_included;
# spent 162ms making 44570 calls to PONAPI::Builder::Document::_included, avg 4µs/call
1714457015.2ms my (@included, %seen);
1724457055.5ms foreach my $builder ( @$included_builders ) {
17386592186ms next if $seen{$builder->{type}}{$builder->{id}}++;
17478113165ms781137.32s push @included, $builder->build( %args );
# spent 7.32s making 78113 calls to PONAPI::Builder::Resource::build, avg 94µs/call
175 }
1764457095.8ms $result->{included} = \@included;
177 }
178 }
179 else {
180 if ( $self->is_collection ) {
181 $result->{data} = [];
182 }
183 else {
184 die "[PANIC] OH NOES, THIS SHOULD NEVER HAPPEN!!!!!"
185 if ! $self->has_meta;
186 }
187 }
188 }
189
190100001200ms100001171ms if ( $self->has_errors_builder ) {
# spent 171ms making 100001 calls to PONAPI::Builder::Document::has_errors_builder, avg 2µs/call
191 my $errors = $self->errors_builder->build;
192 if ( $errors ) {
193 $_->{status} //= $self->status for @$errors;
194 }
195 return +{
196 jsonapi => +{ version => $self->version },
197 errors => $errors,
198 };
199 }
200
201100001469ms return $result;
202}
203
20414µs24.79ms__PACKAGE__->meta->make_immutable;
# spent 4.77ms making 1 call to Class::MOP::Class::make_immutable # spent 12µs making 1 call to PONAPI::Builder::Document::meta
205393µs2167µs
# spent 88µs (10+78) within PONAPI::Builder::Document::BEGIN@205 which was called: # once (10µs+78µs) by PONAPI::DAO::Request::BEGIN@7 at line 205
no Moose; 1;
# spent 88µs making 1 call to PONAPI::Builder::Document::BEGIN@205 # spent 78µs making 1 call to Moose::unimport
206
207__END__