← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:11 2015

Filename/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm
StatementsExecuted 31 statements in 992µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1115.18ms5.70msFoswiki::::BEGIN@72Foswiki::BEGIN@72
11178µs2.75msFoswiki::::QUERYFoswiki::QUERY
11125µs42µsFoswiki::::BEGIN@4.79Foswiki::BEGIN@4.79
11122µs653µsFoswiki::::__ANON__[:56]Foswiki::__ANON__[:56]
11115µs22µsFoswiki::::BEGIN@5.80Foswiki::BEGIN@5.80
1114µs4µsFoswiki::::_serialise_Foswiki::_serialise_
1113µs3µsFoswiki::::__ANON__[:65]Foswiki::__ANON__[:65]
0000s0sFoswiki::::__ANON__[:62]Foswiki::__ANON__[:62]
0000s0sFoswiki::::_serialise_jsonFoswiki::_serialise_json
0000s0sFoswiki::::_serialise_perlFoswiki::_serialise_perl
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2package Foswiki;
3
4241µs259µs
# spent 42µs (25+17) within Foswiki::BEGIN@4.79 which was called: # once (25µs+17µs) by Foswiki::_expandMacroOnTopicRendering at line 4
use strict;
# spent 42µs making 1 call to Foswiki::BEGIN@4.79 # spent 17µs making 1 call to strict::import
52505µs229µs
# spent 22µs (15+7) within Foswiki::BEGIN@5.80 which was called: # once (15µs+7µs) by Foswiki::_expandMacroOnTopicRendering at line 5
use warnings;
# spent 22µs making 1 call to Foswiki::BEGIN@5.80 # spent 7µs making 1 call to warnings::import
6
71100nsour $evalParser; # could share $ifParser from IF.pm
8
9
# spent 2.75ms (78µs+2.68) within Foswiki::QUERY which was called: # once (78µs+2.68ms) by Foswiki::_expandMacroOnTopicRendering at line 3160 of /var/www/foswiki11/lib/Foswiki.pm
sub QUERY {
101900ns my ( $this, $params, $topicObject ) = @_;
111100ns my $result;
121700ns my $expr = $params->{_DEFAULT};
131200ns $expr = '' unless defined $expr;
1411µs my $style = lc( $params->{style} || '' );
151400ns my $rev = $params->{rev};
16
17 # FORMFIELD does its own caching.
18 # Either the home-made cache there should go into Meta so that both
19 # FORMFIELD and QUERY benefit, or the store should be made a lot smarter.
20
21110µs2607µs if ( defined $rev ) {
# spent 590µs making 1 call to Foswiki::Meta::load # spent 16µs making 1 call to Foswiki::Meta::latestIsLoaded
22 my $crev = $topicObject->getLoadedRev();
23 if ( defined $crev && $crev != $rev ) {
24 $topicObject =
25 Foswiki::Meta->load( $topicObject->session, $topicObject->web,
26 $topicObject->topic, $rev );
27 }
28 }
29 elsif ( !$topicObject->latestIsLoaded() ) {
30
31 # load latest rev
32 $topicObject = $topicObject->load();
33 }
34
35 # Recursion block.
3612µs $this->{evaluatingEval} ||= {};
37
38 # Block after 5 levels.
391500ns if ( $this->{evaluatingEval}->{$expr}
40 && $this->{evaluatingEval}->{$expr} > 5 )
41 {
42 delete $this->{evaluatingEval}->{$expr};
43 return '';
44 }
451500ns unless ($evalParser) {
4611µs require Foswiki::Query::Parser;
47111µs11.38ms $evalParser = new Foswiki::Query::Parser();
# spent 1.38ms making 1 call to Foswiki::Query::Parser::new
48 }
49
5012µs $this->{evaluatingEval}->{$expr}++;
51
# spent 653µs (22+631) within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:56] which was called: # once (22µs+631µs) by Error::subs::try at line 419 of Error.pm
try {
5215µs1586µs my $node = $evalParser->parse($expr);
# spent 586µs making 1 call to Foswiki::Infix::Parser::parse
5315µs141µs $result = $node->evaluate( tom => $topicObject, data => $topicObject );
# spent 41µs making 1 call to Foswiki::Query::Node::evaluate
541800ns my $fn = "_serialise_$style";
5518µs14µs $result = $this->$fn($result);
# spent 4µs making 1 call to Foswiki::_serialise_
56 }
57 catch Foswiki::Infix::Error with {
58 my $e = shift;
59 $result =
60 $this->inlineAlert( 'alerts', 'generic', 'QUERY{',
61 $params->stringify(), '}:', $e->{-text} );
62 }
63
# spent 3µs within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:65] which was called: # once (3µs+0s) by Error::subs::try at line 433 of Error.pm
finally {
6416µs delete $this->{evaluatingEval}->{$expr};
65126µs416µs };
# spent 10µs making 1 call to Error::catch # spent 4µs making 1 call to Error::subs::finally # spent 2µs making 1 call to Error::subs::with # spent 675µs making 1 call to Error::subs::try, recursion: max depth 1, sum of overlapping time 675µs
66
6715µs return $result;
68}
69
70sub _serialise_perl {
71 my ( $this, $result ) = @_;
722351µs15.70ms
# spent 5.70ms (5.18+517µs) within Foswiki::BEGIN@72 which was called: # once (5.18ms+517µs) by Foswiki::_expandMacroOnTopicRendering at line 72
use Data::Dumper ();
# spent 5.70ms making 1 call to Foswiki::BEGIN@72
73 local $Data::Dumper::Indent = 0;
74 local $Data::Dumper::Terse = 1;
75 return Data::Dumper->Dump( [$result] );
76}
77
78sub _serialise_json {
79 my ( $this, $result ) = @_;
80 eval "require JSON";
81 if ($@) {
82 return $this->inlineAlert( 'alerts', 'generic',
83 'Perl JSON module is not available' );
84 }
85 return JSON::to_json( $result, { allow_nonref => 1 } );
86}
87
88# Default serialiser
89
# spent 4µs within Foswiki::_serialise_ which was called: # once (4µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:56] at line 55
sub _serialise_ {
901800ns my ( $this, $result ) = @_;
911800ns if ( ref($result) eq 'ARRAY' ) {
92
93 # If any of the results is non-scalar, have to perl it
94 foreach my $v (@$result) {
95 if ( ref($v) ) {
96 return _serialise_perl($result);
97 }
98 }
99 return join( ',', @$result );
100 }
101 elsif ( ref($result) ) {
102 return _serialise_perl($result);
103 }
104 else {
10516µs return defined $result ? $result : '';
106 }
107}
108
10913µs1;
110__END__