Profile of lib/PONAPI/DAO/Request/Role/HasFields.pm

← 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/DAO/Request/Role/HasFields.pm
Statements | Executed 672758 statements in 1.94s

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
100001 | 1 | 1 | 1.72s | 3.89s | PONAPI::DAO::Request::Role::HasFields::::_validate_fieldsPONAPI::DAO::Request::Role::HasFields::_validate_fields
69132 | 1 | 1 | 228ms | 228ms | PONAPI::DAO::Request::Role::HasFields::::__ANON__[lib/PONAPI/DAO/Request/Role/HasFields.pm:10]PONAPI::DAO::Request::Role::HasFields::__ANON__[lib/PONAPI/DAO/Request/Role/HasFields.pm:10]
1 | 1 | 1 | 21µs | 6.65ms | PONAPI::DAO::Request::Role::HasFields::::BEGIN@4PONAPI::DAO::Request::Role::HasFields::BEGIN@4
1 | 1 | 1 | 8µs | 86µs | PONAPI::DAO::Request::Role::HasFields::::BEGIN@64PONAPI::DAO::Request::Role::HasFields::BEGIN@64

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | # ABSTRACT: DAO request role - `fields`
2 |  |  |  |  | package PONAPI::DAO::Request::Role::HasFields;
3 |  |  |  |  |
4 | 2 | 257µs | 2 | 13.3ms | # spent 6.65ms (21µs+6.63) within PONAPI::DAO::Request::Role::HasFields::BEGIN@4 which was called: # once (21µs+6.63ms) by Module::Runtime::require_module at line 4 use Moose::Role; # spent 6.65ms making 1 call to PONAPI::DAO::Request::Role::HasFields::BEGIN@4 # spent 6.63ms making 1 call to Moose::Role::import
5 |  |  |  |  |
6 |  |  |  |  | has fields => (
7 |  |  |  |  | traits => [ 'Hash' ],
8 |  |  |  |  | is => 'ro',
9 |  |  |  |  | isa => 'HashRef',
10 | 69132 | 573ms |  |  | # spent 228ms within PONAPI::DAO::Request::Role::HasFields::__ANON__[lib/PONAPI/DAO/Request/Role/HasFields.pm:10] which was called 69132 times, avg 3µs/call: # 69132 times (228ms+0s) by PONAPI::DAO::Request::Retrieve::new or PONAPI::DAO::Request::RetrieveAll::new at line 37 of (eval 45)[Eval/Closure.pm:144], avg 3µs/call default => sub { +{} },
11 | 1 | 13µs | 1 | 139µs | handles => { # spent 139µs making 1 call to Moose::Role::has
12 |  |  |  |  | "has_fields" => 'count',
13 |  |  |  |  | },
14 |  |  |  |  | );
15 |  |  |  |  |
16 |  |  |  |  | # spent 3.89s (1.72+2.17) within PONAPI::DAO::Request::Role::HasFields::_validate_fields which was called 100001 times, avg 39µs/call: # 100001 times (1.72s+2.17s) by PONAPI::DAO::Request::BUILD at line 117 of lib/PONAPI/DAO/Request.pm, avg 39µs/call sub _validate_fields {
17 | 100001 | 56.7ms |  |  | my ( $self, $args ) = @_;
18 |  |  |  |  |
19 | 100001 | 445ms |  |  | return unless defined $args->{fields};
20 | 30869 | 90.5ms | 30869 | 134ms | return unless $self->has_fields; # spent 67.4ms making 15437 calls to PONAPI::DAO::Request::RetrieveAll::has_fields, avg 4µs/call # spent 66.7ms making 15432 calls to PONAPI::DAO::Request::Retrieve::has_fields, avg 4µs/call
21 |  |  |  |  |
22 | 30869 | 84.4ms | 30869 | 96.9ms | my $fields = $self->fields; # spent 48.4ms making 15437 calls to PONAPI::DAO::Request::RetrieveAll::fields, avg 3µs/call # spent 48.4ms making 15432 calls to PONAPI::DAO::Request::Retrieve::fields, avg 3µs/call
23 | 30869 | 46.1ms | 30869 | 32.0ms | my $repo = $self->repository; # spent 32.0ms making 30869 calls to PONAPI::DAO::Request::repository, avg 1µs/call
24 |  |  |  |  |
25 | 30869 | 206ms |  |  | foreach my $fields_type ( keys %$fields ) {
26 | 30869 | 66.8ms | 30869 | 199ms | if ( !$repo->has_type( $fields_type ) ) { # spent 199ms making 30869 calls to Test::PONAPI::Repository::MockDB::has_type, avg 6µs/call
27 |  |  |  |  | $self->_bad_request( "Type `$fields_type` doesn't exist.", 404 );
28 |  |  |  |  | }
29 |  |  |  |  | else {
30 | 30869 | 24.8ms |  |  | my $fields_array = $fields->{$fields_type};
31 | 30869 | 57.8ms |  |  | my @fields = @$fields_array;
32 |  |  |  |  |
33 | 30869 | 103ms | 30869 | 939ms | my $ok = $repo->type_has_fields( $fields_type, \@fields ); # spent 939ms making 30869 calls to Test::PONAPI::Repository::MockDB::type_has_fields, avg 30µs/call
34 | 30869 | 30.4ms |  |  | next if $ok;
35 |  |  |  |  |
36 |  |  |  |  | # Sigh... let's test for this:
37 |  |  |  |  | # fields => { articles => [qw/ title authors /] }
38 |  |  |  |  | # where authors is a *relationship*
39 |  |  |  |  | # There can't be clashes, so yes, this is fine. Somehow.
40 |  |  |  |  | # http://jsonapi.org/format/#document-resource-object-fields
41 | 13386 | 5.50ms |  |  | my (@real_fields, @relationships);
42 | 13386 | 15.4ms |  |  | foreach my $maybe_rel ( @fields ) {
43 | 43836 | 78.4ms | 43836 | 531ms | if ( $repo->has_relationship($fields_type, $maybe_rel) ) { # spent 531ms making 43836 calls to Test::PONAPI::Repository::MockDB::has_relationship, avg 12µs/call
44 |  |  |  |  | push @relationships, $maybe_rel;
45 |  |  |  |  | }
46 |  |  |  |  | else {
47 | 28417 | 16.9ms |  |  | push @real_fields, $maybe_rel;
48 |  |  |  |  | }
49 |  |  |  |  | }
50 |  |  |  |  |
51 |  |  |  |  | $ok = @real_fields
52 | 13386 | 26.4ms | 13386 | 233ms | ? $repo->type_has_fields($fields_type, \@real_fields) # spent 233ms making 13386 calls to Test::PONAPI::Repository::MockDB::type_has_fields, avg 17µs/call
53 |  |  |  |  | : 1;
54 |  |  |  |  |
55 | 13386 | 15.6ms |  |  | if (!$ok) {
56 |  |  |  |  | $self->_bad_request(
57 |  |  |  |  | "Type `$fields_type` does not have at least one of the requested fields"
58 |  |  |  |  | );
59 |  |  |  |  | }
60 |  |  |  |  | }
61 |  |  |  |  | }
62 |  |  |  |  | }
63 |  |  |  |  |
64 | 3 | 40µs | 2 | 165µs | # spent 86µs (8+78) within PONAPI::DAO::Request::Role::HasFields::BEGIN@64 which was called: # once (8µs+78µs) by Module::Runtime::require_module at line 64 no Moose::Role; 1; # spent 86µs making 1 call to PONAPI::DAO::Request::Role::HasFields::BEGIN@64 # spent 78µs making 1 call to Moose::Role::unimport
65 |  |  |  |  |
66 |  |  |  |  | __END__