Profile of Path/Class/File.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:09 2016

Filename | /usr/share/perl5/Path/Class/File.pm
Statements | Executed 65 statements in 1.30ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 1.94ms | 2.02ms | Path::Class::File::::BEGIN@14Path::Class::File::BEGIN@14
1 | 1 | 1 | 1.79ms | 28.7ms | Path::Class::File::::BEGIN@8Path::Class::File::BEGIN@8
1 | 1 | 1 | 286µs | 318µs | Path::Class::File::::BEGIN@13Path::Class::File::BEGIN@13
2 | 2 | 2 | 48µs | 252µs | Path::Class::File::::newPath::Class::File::new
1 | 1 | 1 | 34µs | 297µs | Path::Class::File::::spewPath::Class::File::spew
4 | 1 | 1 | 30µs | 214µs | Path::Class::File::::stringifyPath::Class::File::stringify
1 | 1 | 1 | 19µs | 169µs | Path::Class::File::::slurpPath::Class::File::slurp
2 | 2 | 1 | 8µs | 404µs | Path::Class::File::::openPath::Class::File::open
1 | 1 | 1 | 8µs | 17µs | Path::Class::::BEGIN@1 Path::Class::BEGIN@1
1 | 1 | 1 | 7µs | 68µs | Path::Class::File::::BEGIN@10Path::Class::File::BEGIN@10
1 | 1 | 1 | 6µs | 32µs | Path::Class::File::::BEGIN@9Path::Class::File::BEGIN@9
1 | 1 | 1 | 6µs | 6µs | Path::Class::File::::CORE:readlinePath::Class::File::CORE:readline (opcode)
1 | 1 | 1 | 4µs | 4µs | Path::Class::File::::BEGIN@55Path::Class::File::BEGIN@55
1 | 1 | 1 | 4µs | 4µs | Path::Class::File::::BEGIN@12Path::Class::File::BEGIN@12
1 | 1 | 1 | 3µs | 3µs | Path::Class::File::::CORE:printPath::Class::File::CORE:print (opcode)
2 | 1 | 1 | 2µs | 2µs | Path::Class::File::::dir_classPath::Class::File::dir_class
0 | 0 | 0 | 0s | 0s | Path::Class::File::::__ANON__[:189]Path::Class::File::__ANON__[:189]
0 | 0 | 0 | 0s | 0s | Path::Class::File::::__ANON__[:195]Path::Class::File::__ANON__[:195]
0 | 0 | 0 | 0s | 0s | Path::Class::File::::as_foreignPath::Class::File::as_foreign
0 | 0 | 0 | 0s | 0s | Path::Class::File::::basenamePath::Class::File::basename
0 | 0 | 0 | 0s | 0s | Path::Class::File::::componentsPath::Class::File::components
0 | 0 | 0 | 0s | 0s | Path::Class::File::::copy_toPath::Class::File::copy_to
0 | 0 | 0 | 0s | 0s | Path::Class::File::::dirPath::Class::File::dir
0 | 0 | 0 | 0s | 0s | Path::Class::File::::move_toPath::Class::File::move_to
0 | 0 | 0 | 0s | 0s | Path::Class::File::::openaPath::Class::File::opena
0 | 0 | 0 | 0s | 0s | Path::Class::File::::openrPath::Class::File::openr
0 | 0 | 0 | 0s | 0s | Path::Class::File::::openwPath::Class::File::openw
0 | 0 | 0 | 0s | 0s | Path::Class::File::::removePath::Class::File::remove
0 | 0 | 0 | 0s | 0s | Path::Class::File::::touchPath::Class::File::touch
0 | 0 | 0 | 0s | 0s | Path::Class::File::::traversePath::Class::File::traverse
0 | 0 | 0 | 0s | 0s | Path::Class::File::::traverse_ifPath::Class::File::traverse_if
0 | 0 | 0 | 0s | 0s | Path::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
--- | --- | --- | --- | --- | ---
1 | 2 | 38µs | 2 | 27µ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 |  |  |  |  |
3 |  |  |  |  | package Path::Class::File;
4 |  |  |  |  | {
5 | 2 | 900ns |  |  | $Path::Class::File::VERSION = '0.33';
6 |  |  |  |  | }
7 |  |  |  |  |
8 | 2 | 71µs | 1 | 28.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
9 | 2 | 22µs | 2 | 58µ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
10 | 2 | 32µs | 2 | 129µ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 |  |  |  |  |
12 | 2 | 16µs | 1 | 4µ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
13 | 2 | 78µs | 1 | 318µ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
14 | 2 | 259µs | 1 | 2.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 {
17 | 2 | 6µs | 2 | 7µs | my $self = shift->SUPER::new; # spent 7µs making 2 calls to Path::Class::Entity::new, avg 3µs/call
18 | 2 | 800ns |  |  | my $file = pop();
19 | 2 | 1µs |  |  | my @dirs = @_;
20 |  |  |  |  |
21 | 2 | 7µs | 4 | 63µ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 |  |  |  |  |
23 | 2 | 3µs | 2 | 4µ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 |  |  |  |  |
27 | 2 | 8µs | 4 | 130µ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
28 | 2 | 1µs |  |  | $self->{file} = $base;
29 |  |  |  |  |
30 | 2 | 6µs |  |  | return $self;
31 |  |  |  |  | }
32 |  |  |  |  |
33 | 2 | 4µ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 |  |  |  |  |
35 |  |  |  |  | sub 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 {
45 | 4 | 1µs |  |  | my $self = shift;
46 | 4 | 2µs |  |  | return $self->{file} unless defined $self->{dir};
47 | 4 | 20µs | 12 | 184µ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 |  |  |  |  |
50 |  |  |  |  | sub dir {
51 |  |  |  |  | my $self = shift;
52 |  |  |  |  | return $self->{dir} if defined $self->{dir};
53 |  |  |  |  | return $self->dir_class->new($self->_spec->curdir);
54 |  |  |  |  | }
55 | 1 | 649µs | 1 | 4µ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 |  |  |  |  |
57 |  |  |  |  | sub volume {
58 |  |  |  |  | my $self = shift;
59 |  |  |  |  | return '' unless defined $self->{dir};
60 |  |  |  |  | return $self->{dir}->volume;
61 |  |  |  |  | }
62 |  |  |  |  |
63 |  |  |  |  | sub 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 |  |  |  |  |
69 |  |  |  |  | sub basename { shift->{file} }
70 | 2 | 9µs | 2 | 395µ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 |  |  |  |  |
72 |  |  |  |  | sub openr { $_[0]->open('r') or croak "Can't read $_[0]: $!" }
73 |  |  |  |  | sub openw { $_[0]->open('w') or croak "Can't write to $_[0]: $!" }
74 |  |  |  |  | sub opena { $_[0]->open('a') or croak "Can't append to $_[0]: $!" }
75 |  |  |  |  |
76 |  |  |  |  | sub 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 {
86 | 1 | 1µs |  |  | my ($self, %args) = @_;
87 | 1 | 800ns |  |  | my $iomode = $args{iomode} || 'r';
88 | 1 | 1µs | 1 | 144µs | my $fh = $self->open($iomode) or croak "Can't read $self: $!"; # spent 144µs making 1 call to Path::Class::File::open
89 |  |  |  |  |
90 | 1 | 300ns |  |  | 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 |  |  |  |  |
102 | 1 | 1µs |  |  | croak "'split' argument can only be used in list context"
103 |  |  |  |  | if $args{split};
104 |  |  |  |  |
105 |  |  |  |  |
106 | 1 | 700ns |  |  | if ($args{chomped} or $args{chomp}) {
107 |  |  |  |  | chomp( my @data = <$fh> );
108 |  |  |  |  | return join '', @data;
109 |  |  |  |  | }
110 |  |  |  |  |
111 |  |  |  |  |
112 | 1 | 2µs |  |  | local $/;
113 | 1 | 19µs | 1 | 6µ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 {
117 | 1 | 400ns |  |  | my $self = shift;
118 | 1 | 2µs |  |  | my %args = splice( @_, 0, @_-1 );
119 |  |  |  |  |
120 | 1 | 700ns |  |  | my $iomode = $args{iomode} || 'w';
121 | 1 | 2µs | 1 | 260µ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 |  |  |  |  |
123 | 1 | 900ns |  |  | 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 {
130 | 1 | 7µs | 1 | 3µs | print $fh $_[0]; # spent 3µs making 1 call to Path::Class::File::CORE:print
131 |  |  |  |  | }
132 |  |  |  |  |
133 | 1 | 25µs |  |  | return;
134 |  |  |  |  | }
135 |  |  |  |  |
136 |  |  |  |  | sub 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 |  |  |  |  |
143 |  |  |  |  | sub 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 |  |  |  |  |
169 |  |  |  |  | sub 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 |  |  |  |  |
186 |  |  |  |  | sub traverse {
187 |  |  |  |  | my $self = shift;
188 |  |  |  |  | my ($callback, @args) = @_;
189 |  |  |  |  | return $self->$callback(sub { () }, @args);
190 |  |  |  |  | }
191 |  |  |  |  |
192 |  |  |  |  | sub traverse_if {
193 |  |  |  |  | my $self = shift;
194 |  |  |  |  | my ($callback, $condition, @args) = @_;
195 |  |  |  |  | return $self->$callback(sub { () }, @args);
196 |  |  |  |  | }
197 |  |  |  |  |
198 | 1 | 2µs |  |  | 1;
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