← 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/Resource.pm
StatementsExecuted 17602241 statements in 37.0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
6075344241.7s125sPONAPI::Builder::Resource::::buildPONAPI::Builder::Resource::build
823661228.27s25.4sPONAPI::Builder::Resource::::add_attributePONAPI::Builder::Resource::add_attribute
172883115.52s60.9sPONAPI::Builder::Resource::::add_relationshipPONAPI::Builder::Resource::add_relationship
270247215.41s60.4sPONAPI::Builder::Resource::::add_self_linkPONAPI::Builder::Resource::add_self_link
86592112.12s11.2sPONAPI::Builder::Resource::::add_attributesPONAPI::Builder::Resource::add_attributes
27024711509ms509msPONAPI::Builder::Resource::::__ANON__[lib/PONAPI/Builder/Resource.pm:38]PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:38]
27024711452ms452msPONAPI::Builder::Resource::::__ANON__[lib/PONAPI/Builder/Resource.pm:21]PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:21]
111627µs370msPONAPI::Builder::Resource::::BEGIN@6PONAPI::Builder::Resource::BEGIN@6
11115µs7.08msPONAPI::Builder::Resource::::BEGIN@4PONAPI::Builder::Resource::BEGIN@4
11112µs96µsPONAPI::Builder::Resource::::BEGIN@131PONAPI::Builder::Resource::BEGIN@131
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 - resource
2package PONAPI::Builder::Resource;
3
4247µs214.1ms
# spent 7.08ms (15µs+7.06) within PONAPI::Builder::Resource::BEGIN@4 which was called: # once (15µs+7.06ms) by PONAPI::Builder::Document::BEGIN@6 at line 4
use Moose;
# spent 7.08ms making 1 call to PONAPI::Builder::Resource::BEGIN@4 # spent 7.06ms making 1 call to Moose::import
5
62625µs1370ms
# spent 370ms (627µs+369) within PONAPI::Builder::Resource::BEGIN@6 which was called: # once (627µs+369ms) by PONAPI::Builder::Document::BEGIN@6 at line 6
use PONAPI::Builder::Relationship;
# spent 370ms making 1 call to PONAPI::Builder::Resource::BEGIN@6
7
813µs111.3mswith 'PONAPI::Builder',
# spent 11.3ms making 1 call to Moose::with
9 'PONAPI::Builder::Role::HasLinksBuilder',
10 'PONAPI::Builder::Role::HasMeta';
11
1212µs11.38mshas id => ( is => 'ro', isa => 'Str', required => 1 );
# spent 1.38ms making 1 call to Moose::has
1312µs11.21mshas type => ( is => 'ro', isa => 'Str', required => 1 );
# spent 1.21ms making 1 call to Moose::has
14
15has _attributes => (
16 init_arg => undef,
17 traits => [ 'Hash' ],
18 is => 'ro',
19 isa => 'HashRef',
20 lazy => 1,
212702471.50s
# spent 452ms within PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:21] which was called 270247 times, avg 2µs/call: # 270247 times (452ms+0s) by PONAPI::Builder::Resource::_add_attribute at line 24 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call
default => sub { +{} },
2219µs113.4ms handles => {
# spent 13.4ms making 1 call to Moose::has
23 'has_attributes' => 'count',
24 'has_attribute_for' => 'exists',
25 # private ...
26 '_add_attribute' => 'set',
27 '_get_attribute' => 'get',
28 '_keys_attributes' => 'keys',
29 }
30);
31
32has _relationships => (
33 init_arg => undef,
34 traits => [ 'Hash' ],
35 is => 'ro',
36 isa => 'HashRef[ PONAPI::Builder::Relationship ]',
37 lazy => 1,
382702471.58s
# spent 509ms within PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:38] which was called 270247 times, avg 2µs/call: # 270247 times (509ms+0s) by PONAPI::Builder::Resource::has_relationship_for at line 20 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call
default => sub { +{} },
39110µs121.1ms handles => {
# spent 21.1ms making 1 call to Moose::has
40 'has_relationships' => 'count',
41 'has_relationship_for' => 'exists',
42 # private ...
43 '_add_relationship' => 'set',
44 '_get_relationship' => 'get',
45 '_keys_relationships' => 'keys',
46 }
47);
48
49
# spent 25.4s (8.27+17.1) within PONAPI::Builder::Resource::add_attribute which was called 823661 times, avg 31µs/call: # 468303 times (4.90s+11.3s) by Test::PONAPI::Repository::MockDB::_add_resources at line 564 of lib/Test/PONAPI/Repository/MockDB.pm, avg 35µs/call # 355358 times (3.36s+5.76s) by PONAPI::Builder::Resource::add_attributes at line 63, avg 26µs/call
sub add_attribute {
50823661388ms my ( $self, $key, $value ) = @_;
51
52823661904ms8236617.44s $self->raise_error( 400,
# spent 7.44s making 823661 calls to PONAPI::Builder::Resource::has_relationship_for, avg 9µs/call
53 title => 'Attribute key conflict, a relation already exists for key: ' . $key
54 ) if $self->has_relationship_for( $key );
55
568236611.09s8236619.64s $self->_add_attribute( $key, $value );
# spent 9.64s making 823661 calls to PONAPI::Builder::Resource::_add_attribute, avg 12µs/call
57
588236613.16s return $self;
59}
60
61
# spent 11.2s (2.12+9.12) within PONAPI::Builder::Resource::add_attributes which was called 86592 times, avg 130µs/call: # 86592 times (2.12s+9.12s) by Test::PONAPI::Repository::MockDB::_add_included at line 686 of lib/Test/PONAPI/Repository/MockDB.pm, avg 130µs/call
sub add_attributes {
6286592160ms my ( $self, %args ) = @_;
6386592686ms3553589.12s $self->add_attribute( $_, $args{ $_ } ) foreach keys %args;
# spent 9.12s making 355358 calls to PONAPI::Builder::Resource::add_attribute, avg 26µs/call
6486592402ms return $self;
65}
66
67
# spent 60.9s (5.52+55.4) within PONAPI::Builder::Resource::add_relationship which was called 172883 times, avg 352µs/call: # 172883 times (5.52s+55.4s) by Test::PONAPI::Repository::MockDB::_add_resource_relationships at line 653 of lib/Test/PONAPI/Repository/MockDB.pm, avg 352µs/call
sub add_relationship {
68172883119ms my ( $self, $key, $resource, $collection ) = @_;
69
70172883413ms172883832ms $self->raise_error( 400,
# spent 832ms making 172883 calls to PONAPI::Builder::Resource::has_attribute_for, avg 5µs/call
71 title => 'Relationship key conflict, an attribute already exists for key: ' . $key
72 ) if $self->has_attribute_for( $key );
73
74172883329ms my @resources =
75 ( ref $resource eq 'ARRAY' ) ? @$resource :
76 ( ref $resource eq 'HASH' ) ? $resource :
77 die 'Relationship resource information must be a reference (HASH or ARRAY)';
78
791728831.07s34576622.0s my $builder = $self->has_relationship_for($key)
# spent 21.4s making 158776 calls to PONAPI::Builder::Relationship::new, avg 135µs/call # spent 555ms making 172883 calls to PONAPI::Builder::Resource::has_relationship_for, avg 3µs/call # spent 38.6ms making 14107 calls to PONAPI::Builder::Resource::_get_relationship, avg 3µs/call
80 ? $self->_get_relationship($key)
81 : PONAPI::Builder::Relationship->new(
82 parent => $self,
83 name => $key,
84 collection => $collection,
85 );
86
87172883587ms17288328.4s $builder->add_resource( $_ ) foreach @resources;
# spent 28.4s making 172883 calls to PONAPI::Builder::Relationship::add_resource, avg 164µs/call
88
891728831.31s1728834.19s $self->_add_relationship( $key => $builder );
# spent 4.19s making 172883 calls to PONAPI::Builder::Resource::_add_relationship, avg 24µs/call
90}
91
92
# spent 60.4s (5.41+55.0) within PONAPI::Builder::Resource::add_self_link which was called 270247 times, avg 224µs/call: # 183655 times (3.84s+39.3s) by Test::PONAPI::Repository::MockDB::_add_resources at line 565 of lib/Test/PONAPI/Repository/MockDB.pm, avg 235µs/call # 86592 times (1.57s+15.7s) by Test::PONAPI::Repository::MockDB::_add_included at line 686 of lib/Test/PONAPI/Repository/MockDB.pm, avg 199µs/call
sub add_self_link {
9327024784.1ms my $self = shift;
94270247961ms5404948.43s my $base = $self->find_root->req_base;
# spent 7.86s making 270247 calls to PONAPI::Builder::find_root, avg 29µs/call # spent 572ms making 270247 calls to PONAPI::Builder::Document::req_base, avg 2µs/call
952702471.24s54049446.6s $self->links_builder->add_link( self => $base . $self->{type} . '/' . $self->{id} );
# spent 39.3s making 270247 calls to PONAPI::Builder::Resource::links_builder, avg 146µs/call # spent 7.23s making 270247 calls to PONAPI::Builder::Links::add_link, avg 27µs/call
962702471.21s return $self;
97}
98
99
# spent 125s (41.7+83.0) within PONAPI::Builder::Resource::build which was called 607534 times, avg 205µs/call: # 345766 times (25.7s+56.0s) by PONAPI::Builder::Relationship::_add_relationship_link at line 61 of lib/PONAPI/Builder/Relationship.pm, avg 236µs/call # 133899 times (8.30s+16.7s) by PONAPI::Builder::Document::build at line 155 of lib/PONAPI/Builder/Document.pm, avg 187µs/call # 78113 times (4.27s+3.05s) by PONAPI::Builder::Document::build at line 174 of lib/PONAPI/Builder/Document.pm, avg 94µs/call # 49756 times (3.47s+7.23s) by PONAPI::Builder::Document::build at line 160 of lib/PONAPI/Builder/Document.pm, avg 215µs/call
sub build {
100607534179ms my $self = shift;
101607534325ms my %args = @_;
102607534252ms my $result = {};
103
1046075341.09s607534917ms $result->{id} = $self->id;
# spent 917ms making 607534 calls to PONAPI::Builder::Resource::id, avg 2µs/call
105607534976ms607534985ms $result->{type} = $self->type;
# spent 985ms making 607534 calls to PONAPI::Builder::Resource::type, avg 2µs/call
1066075342.33s182260215.7s $result->{links} = $self->links_builder->build if $self->has_links_builder;
# spent 13.8s making 607534 calls to PONAPI::Builder::Links::build, avg 23µs/call # spent 1.08s making 607534 calls to PONAPI::Builder::Resource::links_builder, avg 2µs/call # spent 796ms making 607534 calls to PONAPI::Builder::Resource::has_links_builder, avg 1µs/call
107607534911ms6075341.28s $result->{meta} = $self->_meta if $self->has_meta;
# spent 1.28s making 607534 calls to PONAPI::Builder::Resource::has_meta, avg 2µs/call
108
109 # support filtered output for attributes/relationships through args
110607534115ms my @field_filters;
111607534228ms @field_filters = @{ $args{fields}{ $self->type } }
112 if exists $args{fields} and exists $args{fields}{ $self->type };
113
1146075341.15s6075341.60s if ( $self->has_attributes ) {
# spent 1.60s making 607534 calls to PONAPI::Builder::Resource::has_attributes, avg 3µs/call
115 my @attributes = @field_filters
1166075341.51s6075341.62s ? grep { $self->has_attribute_for($_) } @field_filters
# spent 1.62s making 607534 calls to PONAPI::Builder::Resource::_keys_attributes, avg 3µs/call
117 : $self->_keys_attributes;
118
11924053743.98s17978405.19s $result->{attributes} = +{ map { $_ => $self->_get_attribute($_) } @attributes };
# spent 5.19s making 1797840 calls to PONAPI::Builder::Resource::_get_attribute, avg 3µs/call
120 }
121
122542856801ms5428562.15s $result->{relationships} = +{
# spent 2.15s making 542856 calls to PONAPI::Builder::Resource::_get_relationship, avg 4µs/call
12311503903.43s164219153.5s map { my $v = $self->_get_relationship($_); $v ? ( $_ => $v->build ) : () }
# spent 50.7s making 542856 calls to PONAPI::Builder::Relationship::build, avg 93µs/call # spent 1.53s making 607534 calls to PONAPI::Builder::Resource::has_relationships, avg 3µs/call # spent 1.33s making 491801 calls to PONAPI::Builder::Resource::_keys_relationships, avg 3µs/call
124 ( @field_filters ? @field_filters : $self->_keys_relationships )
125 } if $self->has_relationships;
126
1276075342.48s return $result;
128}
129
13016µs29.12ms__PACKAGE__->meta->make_immutable;
# spent 9.10ms making 1 call to Class::MOP::Class::make_immutable # spent 22µs making 1 call to PONAPI::Builder::Resource::meta
131369µs2180µs
# spent 96µs (12+84) within PONAPI::Builder::Resource::BEGIN@131 which was called: # once (12µs+84µs) by PONAPI::Builder::Document::BEGIN@6 at line 131
no Moose; 1;
# spent 96µs making 1 call to PONAPI::Builder::Resource::BEGIN@131 # spent 84µs making 1 call to Moose::unimport
132
133__END__