← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/CHI.pm
StatementsExecuted 32 statements in 793µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.51ms3.52msCHI::::BEGIN@8CHI::BEGIN@8
111676µs30.6msCHI::::BEGIN@5CHI::BEGIN@5
111307µs693µsCHI::::BEGIN@6CHI::BEGIN@6
11112µs12µsCHI::::BEGIN@3CHI::BEGIN@3
1116µs38µsCHI::::BEGIN@4CHI::BEGIN@4
1116µs11µsCHI::::configCHI::config
1116µs7µsCHI::::BEGIN@9CHI::BEGIN@9
1115µs20µsCHI::::BEGIN@7CHI::BEGIN@7
1115µs8µsCHI::::BEGIN@10CHI::BEGIN@10
1115µs12µsCHI::::BEGIN@34CHI::BEGIN@34
1115µs11µsCHI::::BEGIN@35CHI::BEGIN@35
1115µs16µsCHI::::BEGIN@39CHI::BEGIN@39
1114µs4µsCHI::::_set_configCHI::_set_config
111400ns400nsCHI::::__ANON__[:36]CHI::__ANON__[:36]
0000s0sCHI::::clear_memoized_cache_objectsCHI::clear_memoized_cache_objects
0000s0sCHI::::loggerCHI::logger
0000s0sCHI::::memoized_cache_objectsCHI::memoized_cache_objects
0000s0sCHI::::newCHI::new
0000s0sCHI::::statsCHI::stats
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package CHI;
21400ns$CHI::VERSION = '0.60';
3229µs112µs
# spent 12µs within CHI::BEGIN@3 which was called: # once (12µs+0s) by BenchmarkAnything::Storage::Backend::SQL::new at line 3
use 5.006;
# spent 12µs making 1 call to CHI::BEGIN@3
4222µs269µs
# spent 38µs (6+31) within CHI::BEGIN@4 which was called: # once (6µs+31µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 4
use Carp;
# spent 38µs making 1 call to CHI::BEGIN@4 # spent 31µs making 1 call to Exporter::import
5279µs130.6ms
# spent 30.6ms (676µs+29.9) within CHI::BEGIN@5 which was called: # once (676µs+29.9ms) by BenchmarkAnything::Storage::Backend::SQL::new at line 5
use CHI::Stats;
# spent 30.6ms making 1 call to CHI::BEGIN@5
6267µs2765µs
# spent 693µs (307+386) within CHI::BEGIN@6 which was called: # once (307µs+386µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 6
use String::RewritePrefix;
# spent 693µs making 1 call to CHI::BEGIN@6 # spent 73µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
7216µs235µs
# spent 20µs (5+15) within CHI::BEGIN@7 which was called: # once (5µs+15µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 7
use Module::Runtime qw(require_module);
# spent 20µs making 1 call to CHI::BEGIN@7 # spent 15µs making 1 call to Module::Runtime::import
8262µs13.52ms
# spent 3.52ms (1.51+2.01) within CHI::BEGIN@8 which was called: # once (1.51ms+2.01ms) by BenchmarkAnything::Storage::Backend::SQL::new at line 8
use Moo::Role ();
# spent 3.52ms making 1 call to CHI::BEGIN@8
9216µs28µs
# spent 7µs (6+1) within CHI::BEGIN@9 which was called: # once (6µs+1µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 9
use strict;
# spent 7µs making 1 call to CHI::BEGIN@9 # spent 1µs making 1 call to strict::import
10278µs211µs
# spent 8µs (5+3) within CHI::BEGIN@10 which was called: # once (5µs+3µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 10
use warnings;
# spent 8µs making 1 call to CHI::BEGIN@10 # spent 3µs making 1 call to warnings::import
11
121200nsmy ( %final_class_seen, %memoized_cache_objects, %stats );
13my %valid_config_keys =
1413µs map { ( $_, 1 ) } qw(defaults memoize_cache_objects namespace storage);
15
16sub logger {
17 warn
18 "CHI now uses Log::Any for logging - see Log::Any documentation for details";
19}
20
21
# spent 11µs (6+5) within CHI::config which was called: # once (6µs+5µs) by CHI::BEGIN@39 at line 39
sub config {
221300ns my $class = shift;
2311µs14µs $class->_set_config(@_) if @_;
# spent 4µs making 1 call to CHI::_set_config
2412µs1400ns return $class->_get_config();
# spent 400ns making 1 call to CHI::__ANON__[CHI.pm:36]
25}
26
27
# spent 4µs within CHI::_set_config which was called: # once (4µs+0s) by CHI::config at line 23
sub _set_config {
281400ns my ( $class, $config ) = @_;
291900ns if ( my @bad_keys = grep { !$valid_config_keys{$_} } keys(%$config) ) {
30 croak "unknown keys in config hash: " . join( ", ", @bad_keys );
31 }
32
33 # set class specific configuration
34214µs219µs
# spent 12µs (5+7) within CHI::BEGIN@34 which was called: # once (5µs+7µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 34
no strict 'refs';
# spent 12µs making 1 call to CHI::BEGIN@34 # spent 7µs making 1 call to strict::unimport
35246µs217µs
# spent 11µs (5+6) within CHI::BEGIN@35 which was called: # once (5µs+6µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 35
no warnings 'redefine';
# spent 11µs making 1 call to CHI::BEGIN@35 # spent 6µs making 1 call to warnings::unimport
3627µs
# spent 400ns within CHI::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/CHI.pm:36] which was called: # once (400ns+0s) by CHI::config at line 24
*{"$class\::_get_config"} = sub { $config };
37}
38
391344µs227µs
# spent 16µs (5+11) within CHI::BEGIN@39 which was called: # once (5µs+11µs) by BenchmarkAnything::Storage::Backend::SQL::new at line 39
BEGIN { __PACKAGE__->config( {} ) }
# spent 16µs making 1 call to CHI::BEGIN@39 # spent 11µs making 1 call to CHI::config
40
41sub memoized_cache_objects {
42 my ($class) = @_;
43
44 # Each CHI root class gets its hash of memoized objects
45 #
46 $memoized_cache_objects{$class} ||= {};
47 return $memoized_cache_objects{$class};
48}
49
50sub clear_memoized_cache_objects {
51 my ($class) = @_;
52
53 $memoized_cache_objects{$class} = {};
54}
55
56sub stats {
57 my ($class) = @_;
58
59 # Each CHI root class gets its own stats object
60 #
61 $stats{$class} ||= CHI::Stats->new( chi_root_class => $class );
62 return $stats{$class};
63}
64
65sub new {
66 my ( $chi_root_class, %params ) = @_;
67
68 my $config = $chi_root_class->config;
69
70 # Cache object memoization: See if cache object with these parameters
71 # has already been created, and return it if so. Only for parameters
72 # with 0 or 1 keys.
73 #
74 my ( $cache_object_key, $cache_objects );
75 if ( $config->{memoize_cache_objects} && keys(%params) <= 1 ) {
76 $cache_object_key = join chr(28), %params;
77 $cache_objects = $chi_root_class->memoized_cache_objects;
78 if ( my $cache_object = $cache_objects->{$cache_object_key} ) {
79 return $cache_object;
80 }
81 }
82
83 # Gather defaults
84 #
85 my $core_defaults = $config->{defaults} || {};
86 my $namespace_defaults =
87 $config->{namespace}->{ $params{namespace} || 'Default' } || {};
88 my $storage =
89 $params{storage}
90 || $namespace_defaults->{storage}
91 || $core_defaults->{storage};
92 my $storage_defaults = {};
93 if ( defined($storage) ) {
94 $storage_defaults = $config->{storage}->{$storage}
95 or croak "no config for storage type '$storage'";
96 }
97
98 # Combine passed params with defaults
99 #
100 %params =
101 ( %$core_defaults, %$storage_defaults, %$namespace_defaults, %params );
102
103 # Get driver class from driver or driver_class parameters
104 #
105 my $driver_class;
106 if ( my $driver = delete( $params{driver} ) ) {
107 ($driver_class) =
108 String::RewritePrefix->rewrite( { '' => 'CHI::Driver::', '+' => '' },
109 $driver );
110 }
111 else {
112 $driver_class = delete( $params{driver_class} );
113 }
114 croak "missing required param 'driver' or 'driver_class'"
115 unless defined $driver_class;
116
117 # Load driver class if it hasn't been loaded or defined in-line already
118 #
119 unless ( $driver_class->can('fetch') ) {
120 require_module($driver_class);
121 }
122
123 # Select roles depending on presence of certain arguments. Everyone gets
124 # the Universal role. Accept both 'roles' and 'traits' for backwards
125 # compatibility. Add CHI::Driver::Role:: unless prefixed with '+'.
126 #
127 my @roles = ('Universal');
128 foreach my $param_name (qw(roles traits)) {
129 if ( exists( $params{$param_name} ) ) {
130 push( @roles, @{ delete( $params{$param_name} ) } );
131 }
132 }
133 if ( exists( $params{max_size} ) || exists( $params{is_size_aware} ) ) {
134 push( @roles, 'IsSizeAware' );
135 }
136 if ( exists( $params{l1_cache} ) || exists( $params{mirror_cache} ) ) {
137 push( @roles, 'HasSubcaches' );
138 }
139 if ( $params{is_subcache} ) {
140 push( @roles, 'IsSubcache' );
141 }
142 @roles = String::RewritePrefix->rewrite(
143 { '' => 'CHI::Driver::Role::', '+' => '' }, @roles );
144
145 # Select a final class based on the driver class and roles, creating it
146 # if necessary - adapted from MooseX::Traits
147 #
148 my $final_class =
149 Moo::Role->create_class_with_roles( $driver_class, @roles );
150
151 my $cache_object = $final_class->new(
152 chi_root_class => $chi_root_class,
153 driver_class => $driver_class,
154 %params
155 );
156
157 # Memoize if appropriate
158 #
159 if ($cache_object_key) {
160 $cache_objects->{$cache_object_key} = $cache_object;
161 }
162
163 return $cache_object;
164}
165
16614µs1;
167
168__END__