← 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:09 2016

Filename/usr/share/perl5/Path/Class/File.pm
StatementsExecuted 65 statements in 1.30ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.94ms2.02msPath::Class::File::::BEGIN@14Path::Class::File::BEGIN@14
1111.79ms28.7msPath::Class::File::::BEGIN@8Path::Class::File::BEGIN@8
111286µs318µsPath::Class::File::::BEGIN@13Path::Class::File::BEGIN@13
22248µs252µsPath::Class::File::::newPath::Class::File::new
11134µs297µsPath::Class::File::::spewPath::Class::File::spew
41130µs214µsPath::Class::File::::stringifyPath::Class::File::stringify
11119µs169µsPath::Class::File::::slurpPath::Class::File::slurp
2218µs404µsPath::Class::File::::openPath::Class::File::open
1118µs17µsPath::Class::::BEGIN@1 Path::Class::BEGIN@1
1117µs68µsPath::Class::File::::BEGIN@10Path::Class::File::BEGIN@10
1116µs32µsPath::Class::File::::BEGIN@9Path::Class::File::BEGIN@9
1116µs6µsPath::Class::File::::CORE:readlinePath::Class::File::CORE:readline (opcode)
1114µs4µsPath::Class::File::::BEGIN@55Path::Class::File::BEGIN@55
1114µs4µsPath::Class::File::::BEGIN@12Path::Class::File::BEGIN@12
1113µs3µsPath::Class::File::::CORE:printPath::Class::File::CORE:print (opcode)
2112µs2µsPath::Class::File::::dir_classPath::Class::File::dir_class
0000s0sPath::Class::File::::__ANON__[:189]Path::Class::File::__ANON__[:189]
0000s0sPath::Class::File::::__ANON__[:195]Path::Class::File::__ANON__[:195]
0000s0sPath::Class::File::::as_foreignPath::Class::File::as_foreign
0000s0sPath::Class::File::::basenamePath::Class::File::basename
0000s0sPath::Class::File::::componentsPath::Class::File::components
0000s0sPath::Class::File::::copy_toPath::Class::File::copy_to
0000s0sPath::Class::File::::dirPath::Class::File::dir
0000s0sPath::Class::File::::move_toPath::Class::File::move_to
0000s0sPath::Class::File::::openaPath::Class::File::opena
0000s0sPath::Class::File::::openrPath::Class::File::openr
0000s0sPath::Class::File::::openwPath::Class::File::openw
0000s0sPath::Class::File::::removePath::Class::File::remove
0000s0sPath::Class::File::::touchPath::Class::File::touch
0000s0sPath::Class::File::::traversePath::Class::File::traverse
0000s0sPath::Class::File::::traverse_ifPath::Class::File::traverse_if
0000s0sPath::Class::File::::volumePath::Class::File::volume
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1238µs227µs
# spent 17µs (8+10) within Path::Class::BEGIN@1 which was called: # once (8µs+10µs) by Path::Class::BEGIN@17 at line 1
use strict;
# spent 17µs making 1 call to Path::Class::BEGIN@1 # spent 10µs making 1 call to strict::import
2
3package Path::Class::File;
4{
52900ns $Path::Class::File::VERSION = '0.33';
6}
7
8271µs128.7ms
# spent 28.7ms (1.79+26.9) within Path::Class::File::BEGIN@8 which was called: # once (1.79ms+26.9ms) by Path::Class::BEGIN@17 at line 8
use Path::Class::Dir;
# spent 28.7ms making 1 call to Path::Class::File::BEGIN@8
9222µs258µs
# spent 32µs (6+26) within Path::Class::File::BEGIN@9 which was called: # once (6µs+26µs) by Path::Class::BEGIN@17 at line 9
use parent qw(Path::Class::Entity);
# spent 32µs making 1 call to Path::Class::File::BEGIN@9 # spent 26µs making 1 call to parent::import
10232µs2129µs
# spent 68µs (7+61) within Path::Class::File::BEGIN@10 which was called: # once (7µs+61µs) by Path::Class::BEGIN@17 at line 10
use Carp;
# spent 68µs making 1 call to Path::Class::File::BEGIN@10 # spent 61µs making 1 call to Exporter::import
11
12216µs14µs
# spent 4µs within Path::Class::File::BEGIN@12 which was called: # once (4µs+0s) by Path::Class::BEGIN@17 at line 12
use IO::File ();
# spent 4µs making 1 call to Path::Class::File::BEGIN@12
13278µs1318µs
# spent 318µs (286+33) within Path::Class::File::BEGIN@13 which was called: # once (286µs+33µs) by Path::Class::BEGIN@17 at line 13
use Perl::OSType ();
# spent 318µs making 1 call to Path::Class::File::BEGIN@13
142259µs12.02ms
# spent 2.02ms (1.94+82µs) within Path::Class::File::BEGIN@14 which was called: # once (1.94ms+82µs) by Path::Class::BEGIN@17 at line 14
use File::Copy ();
# spent 2.02ms making 1 call to Path::Class::File::BEGIN@14
15
16
# spent 252µs (48+203) within Path::Class::File::new which was called 2 times, avg 126µs/call: # once (36µs+152µs) by Path::Class::file at line 21 of Path/Class.pm # once (12µs+51µs) by Path::Class::Dir::file at line 89 of Path/Class/Dir.pm
sub new {
1726µs27µs my $self = shift->SUPER::new;
# spent 7µs making 2 calls to Path::Class::Entity::new, avg 3µs/call
182800ns my $file = pop();
1921µs my @dirs = @_;
20
2127µs463µs my ($volume, $dirs, $base) = $self->_spec->splitpath($file);
# spent 44µs making 2 calls to Path::Class::Entity::_spec, avg 22µs/call # spent 19µs making 2 calls to File::Spec::Unix::splitpath, avg 9µs/call
22
2323µs24µs if (length $dirs) {
# spent 2µs making 1 call to File::Spec::Unix::catpath # spent 2µs making 1 call to Path::Class::Entity::_spec
24 push @dirs, $self->_spec->catpath($volume, $dirs, '');
25 }
26
2728µs4130µs $self->{dir} = @dirs ? $self->dir_class->new(@dirs) : undef;
# spent 128µs making 2 calls to Path::Class::Dir::new, avg 64µs/call # spent 2µs making 2 calls to Path::Class::File::dir_class, avg 1µs/call
2821µs $self->{file} = $base;
29
3026µs return $self;
31}
32
3324µs
# spent 2µs within Path::Class::File::dir_class which was called 2 times, avg 1µs/call: # 2 times (2µs+0s) by Path::Class::File::new at line 27, avg 1µs/call
sub dir_class { "Path::Class::Dir" }
34
35sub as_foreign {
36 my ($self, $type) = @_;
37 local $Path::Class::Foreign = $self->_spec_class($type);
38 my $foreign = ref($self)->SUPER::new;
39 $foreign->{dir} = $self->{dir}->as_foreign($type) if defined $self->{dir};
40 $foreign->{file} = $self->{file};
41 return $foreign;
42}
43
44
# spent 214µs (30+184) within Path::Class::File::stringify which was called 4 times, avg 54µs/call: # 4 times (30µs+184µs) by IO::File::CORE:open at line 62 of IO/File.pm, avg 54µs/call
sub stringify {
4541µs my $self = shift;
4642µs return $self->{file} unless defined $self->{dir};
47420µs12184µs return $self->_spec->catfile($self->{dir}->stringify, $self->{file});
# spent 94µs making 4 calls to File::Spec::Unix::catfile, avg 23µs/call # spent 84µs making 4 calls to Path::Class::Dir::stringify, avg 21µs/call # spent 6µs making 4 calls to Path::Class::Entity::_spec, avg 1µs/call
48}
49
50sub dir {
51 my $self = shift;
52 return $self->{dir} if defined $self->{dir};
53 return $self->dir_class->new($self->_spec->curdir);
54}
551649µs14µs
# spent 4µs within Path::Class::File::BEGIN@55 which was called: # once (4µs+0s) by Path::Class::BEGIN@17 at line 55
BEGIN { *parent = \&dir; }
# spent 4µs making 1 call to Path::Class::File::BEGIN@55
56
57sub volume {
58 my $self = shift;
59 return '' unless defined $self->{dir};
60 return $self->{dir}->volume;
61}
62
63sub components {
64 my $self = shift;
65 die "Arguments are not currently supported by File->components()" if @_;
66 return ($self->dir->components, $self->basename);
67}
68
69sub basename { shift->{file} }
7029µs2395µs
# spent 404µs (8+395) within Path::Class::File::open which was called 2 times, avg 202µs/call: # once (5µs+255µs) by Path::Class::File::spew at line 121 # once (3µs+141µs) by Path::Class::File::slurp at line 88
sub open { IO::File->new(@_) }
# spent 395µs making 2 calls to IO::File::new, avg 198µs/call
71
72sub openr { $_[0]->open('r') or croak "Can't read $_[0]: $!" }
73sub openw { $_[0]->open('w') or croak "Can't write to $_[0]: $!" }
74sub opena { $_[0]->open('a') or croak "Can't append to $_[0]: $!" }
75
76sub touch {
77 my $self = shift;
78 if (-e $self) {
79 utime undef, undef, $self;
80 } else {
81 $self->openw;
82 }
83}
84
85
# spent 169µs (19+150) within Path::Class::File::slurp which was called: # once (19µs+150µs) by PONAPI::Server::ConfigReader::_build_conf at line 33 of lib/PONAPI/Server/ConfigReader.pm
sub slurp {
8611µs my ($self, %args) = @_;
871800ns my $iomode = $args{iomode} || 'r';
8811µs1144µs my $fh = $self->open($iomode) or croak "Can't read $self: $!";
# spent 144µs making 1 call to Path::Class::File::open
89
901300ns if (wantarray) {
91 my @data = <$fh>;
92 chomp @data if $args{chomped} or $args{chomp};
93
94 if ( my $splitter = $args{split} ) {
95 @data = map { [ split $splitter, $_ ] } @data;
96 }
97
98 return @data;
99 }
100
101
10211µs croak "'split' argument can only be used in list context"
103 if $args{split};
104
105
1061700ns if ($args{chomped} or $args{chomp}) {
107 chomp( my @data = <$fh> );
108 return join '', @data;
109 }
110
111
11212µs local $/;
113119µs16µs return <$fh>;
# spent 6µs making 1 call to Path::Class::File::CORE:readline
114}
115
116
# spent 297µs (34+264) within Path::Class::File::spew which was called: # once (34µs+264µs) by PONAPI::CLI::RunServer::_create_dir at line 35 of lib/PONAPI/CLI/RunServer.pm
sub spew {
1171400ns my $self = shift;
11812µs my %args = splice( @_, 0, @_-1 );
119
1201700ns my $iomode = $args{iomode} || 'w';
12112µs1260µs my $fh = $self->open( $iomode ) or croak "Can't write to $self: $!";
# spent 260µs making 1 call to Path::Class::File::open
122
1231900ns if (ref($_[0]) eq 'ARRAY') {
124 # Use old-school for loop to avoid copying.
125 for (my $i = 0; $i < @{ $_[0] }; $i++) {
126 print $fh $_[0]->[$i];
127 }
128 }
129 else {
13017µs13µs print $fh $_[0];
# spent 3µs making 1 call to Path::Class::File::CORE:print
131 }
132
133125µs return;
134}
135
136sub remove {
137 my $file = shift->stringify;
138 return unlink $file unless -e $file; # Sets $! correctly
139 1 while unlink $file;
140 return not -e $file;
141}
142
143sub copy_to {
144 my ($self, $dest) = @_;
145 if ( UNIVERSAL::isa($dest, Path::Class::File::) ) {
146 $dest = $dest->stringify;
147 die "Can't copy to file $dest: it is a directory" if -d $dest;
148 } elsif ( UNIVERSAL::isa($dest, Path::Class::Dir::) ) {
149 $dest = $dest->stringify;
150 die "Can't copy to directory $dest: it is a file" if -f $dest;
151 die "Can't copy to directory $dest: no such directory" unless -d $dest;
152 } elsif ( ref $dest ) {
153 die "Don't know how to copy files to objects of type '".ref($self)."'";
154 }
155
156 if ( !Perl::OSType::is_os_type('Unix') ) {
157
158 return unless File::Copy::cp($self->stringify, $dest);
159
160 } else {
161
162 return unless (system('cp', $self->stringify, $dest) == 0);
163
164 }
165
166 return $self->new($dest);
167}
168
169sub move_to {
170 my ($self, $dest) = @_;
171 if (File::Copy::move($self->stringify, $dest)) {
172
173 my $new = $self->new($dest);
174
175 $self->{$_} = $new->{$_} foreach (qw/ dir file /);
176
177 return $self;
178
179 } else {
180
181 return;
182
183 }
184}
185
186sub traverse {
187 my $self = shift;
188 my ($callback, @args) = @_;
189 return $self->$callback(sub { () }, @args);
190}
191
192sub traverse_if {
193 my $self = shift;
194 my ($callback, $condition, @args) = @_;
195 return $self->$callback(sub { () }, @args);
196}
197
19812µs1;
199__END__
 
# spent 3µs within Path::Class::File::CORE:print which was called: # once (3µs+0s) by Path::Class::File::spew at line 130
sub Path::Class::File::CORE:print; # opcode
# spent 6µs within Path::Class::File::CORE:readline which was called: # once (6µs+0s) by Path::Class::File::slurp at line 113
sub Path::Class::File::CORE:readline; # opcode