Profile of App/Rad/Help.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For bin/dpath
Run on Tue Jun 5 15:31:33 2012
Reported on Tue Jun 5 15:31:40 2012

Filename | /home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/App/Rad/Help.pm
Statements | Executed 27 statements in 2.61ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 8.54ms | 31.8ms | App::Rad::Help::::BEGIN@2App::Rad::Help::BEGIN@2
5 | 5 | 5 | 322µs | 322µs | UNIVERSAL::::VERSION UNIVERSAL::VERSION (xsub)
13 | 2 | 2 | 96µs | 96µs | UNIVERSAL::::isa UNIVERSAL::isa (xsub)
4 | 2 | 2 | 72µs | 72µs | UNIVERSAL::::can UNIVERSAL::can (xsub)
3 | 2 | 1 | 51µs | 51µs | App::Rad::Help::::register_helpApp::Rad::Help::register_help
1 | 1 | 1 | 34µs | 1.01ms | App::Rad::Help::::BEGIN@59App::Rad::Help::BEGIN@59
1 | 1 | 1 | 30µs | 43µs | App::Rad::Help::::BEGIN@3App::Rad::Help::BEGIN@3
1 | 1 | 1 | 27µs | 49µs | App::Rad::Help::::BEGIN@4App::Rad::Help::BEGIN@4
1 | 1 | 1 | 26µs | 26µs | UNIVERSAL::::Help UNIVERSAL::Help
1 | 1 | 1 | 22µs | 116µs | App::Rad::Help::::loadApp::Rad::Help::load
0 | 0 | 0 | 0s | 0s | App::Rad::Help::::helpApp::Rad::Help::help
0 | 0 | 0 | 0s | 0s | App::Rad::Help::::helpstrApp::Rad::Help::helpstr
0 | 0 | 0 | 0s | 0s | App::Rad::Help::::usageApp::Rad::Help::usage

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

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package App::Rad::Help;
2 | 2 | 400µs | 2 | 31.8ms | # spent 31.8ms (8.54+23.3) within App::Rad::Help::BEGIN@2 which was called: # once (8.54ms+23.3ms) by App::Rad::BEGIN@3 at line 2 use Attribute::Handlers; # spent 31.8ms making 1 call to App::Rad::Help::BEGIN@2 # spent 14µs making 1 call to Attribute::Handlers::import
3 | 2 | 87µs | 2 | 56µs | # spent 43µs (30+13) within App::Rad::Help::BEGIN@3 which was called: # once (30µs+13µs) by App::Rad::BEGIN@3 at line 3 use strict; # spent 43µs making 1 call to App::Rad::Help::BEGIN@3 # spent 13µs making 1 call to strict::import
4 | 2 | 1.39ms | 2 | 70µs | # spent 49µs (27+22) within App::Rad::Help::BEGIN@4 which was called: # once (27µs+22µs) by App::Rad::BEGIN@3 at line 4 use warnings; # spent 49µs making 1 call to App::Rad::Help::BEGIN@4 # spent 22µs making 1 call to warnings::import
5 |  |  |  |  |
6 | 1 | 3µs |  |  | our $VERSION = '0.03';
7 |  |  |  |  |
8 |  |  |  |  | # spent 116µs (22+94) within App::Rad::Help::load which was called: # once (22µs+94µs) by App::Rad::_init at line 40 of App/Rad.pm sub load {
9 | 2 | 30µs |  |  | my ($self, $c) = @_;
10 |  |  | 1 | 94µs | $c->register('help', \&help, 'show syntax and available commands'); # spent 94µs making 1 call to App::Rad::register
11 |  |  |  |  | }
12 |  |  |  |  |
13 |  |  |  |  | # shows specific help commands
14 |  |  |  |  | # TODO: context specific help,
15 |  |  |  |  | # such as "myapp.pl help command"
16 |  |  |  |  | sub help {
17 |  |  |  |  | my $c = shift;
18 |  |  |  |  | return usage() . "\n\n" . helpstr($c);
19 |  |  |  |  | }
20 |  |  |  |  |
21 |  |  |  |  | sub usage {
22 |  |  |  |  | return "Usage: $0 command [arguments]";
23 |  |  |  |  | }
24 |  |  |  |  |
25 |  |  |  |  | sub helpstr {
26 |  |  |  |  | my $c = shift;
27 |  |  |  |  |
28 |  |  |  |  | my $string = "Available Commands:\n";
29 |  |  |  |  |
30 |  |  |  |  | # get length of largest command name
31 |  |  |  |  | my $len = 0;
32 |  |  |  |  | foreach ( sort $c->commands() ) {
33 |  |  |  |  | $len = length($_) if (length($_) > $len);
34 |  |  |  |  | }
35 |  |  |  |  |
36 |  |  |  |  | # format help string
37 |  |  |  |  | foreach ( sort $c->commands() ) {
38 |  |  |  |  | $string .= sprintf " %-*s\t%s\n", $len, $_,
39 |  |  |  |  | defined ($c->{'_commands'}->{$_}->{'help'})
40 |  |  |  |  | ? $c->{'_commands'}->{$_}->{'help'}
41 |  |  |  |  | : ''
42 |  |  |  |  | ;
43 |  |  |  |  | ;
44 |  |  |  |  | }
45 |  |  |  |  | return $string;
46 |  |  |  |  | }
47 |  |  |  |  |
48 |  |  |  |  |
49 |  |  |  |  | {
50 | 2 | 6µs |  |  | my %help_attr = ();
51 |  |  |  |  | # spent 26µs within UNIVERSAL::Help which was called: # once (26µs+0s) by Attribute::Handlers::_apply_handler_AH_ at line 225 of Attribute/Handlers.pm sub UNIVERSAL::Help :ATTR(CODE) {
52 | 2 | 26µs |  |  | my ($package, $symbol, $ref, $attr, $data, $phase, $filename, $linenum) = @_;
53 |  |  |  |  |
54 | 2 | 8µs |  |  | if ($package eq 'main') {
55 |  |  |  |  | # If data is a single word, it is received as an array ref. Don't ask.
56 |  |  |  |  | $data = join(' ', @$data) if ref($data) eq 'ARRAY';
57 |  |  |  |  | $help_attr{ *{$symbol}{NAME} } = $data;
58 |  |  |  |  | }
59 | 2 | 582µs | 2 | 1.98ms | # spent 1.01ms (34µs+973µs) within App::Rad::Help::BEGIN@59 which was called: # once (34µs+973µs) by App::Rad::BEGIN@3 at line 59 } # spent 1.01ms making 1 call to App::Rad::Help::BEGIN@59 # spent 973µs making 1 call to attributes::import
60 |  |  |  |  |
61 |  |  |  |  | # spent 51µs within App::Rad::Help::register_help which was called 3 times, avg 17µs/call: # 2 times (34µs+0s) by App::Rad::register_commands at line 252 of App/Rad.pm, avg 17µs/call # once (16µs+0s) by App::Rad::register at line 306 of App/Rad.pm sub register_help {
62 | 9 | 68µs |  |  | my ($self, $c, $cmd, $helptext) = @_;
63 |  |  |  |  |
64 |  |  |  |  | if ((not defined $helptext) && (defined $help_attr{$cmd})) {
65 |  |  |  |  | $helptext = $help_attr{$cmd};
66 |  |  |  |  | }
67 |  |  |  |  |
68 |  |  |  |  | # we do $helptext // undef as it would issue a warning otherwise
69 |  |  |  |  | $c->{'_commands'}->{$cmd}->{'help'} = defined $helptext
70 |  |  |  |  | ? $helptext
71 |  |  |  |  | : undef
72 |  |  |  |  | ;
73 |  |  |  |  | }
74 |  |  |  |  |
75 |  |  |  |  | }
76 | 1 | 14µs |  |  | 42;
77 |  |  |  |  | __END__
|  |  |  |  | # spent 322µs within UNIVERSAL::VERSION which was called 5 times, avg 64µs/call: # once (76µs+0s) by Exception::Class::Base::BEGIN@10 at line 10 of Exception/Class/Base.pm # once (69µs+0s) by Data::OptList::BEGIN@11 at line 11 of Data/OptList.pm # once (65µs+0s) by Data::DPath::Path::BEGIN@17 at line 17 of Data/DPath/Path.pm # once (61µs+0s) by Sub::Exporter::BEGIN@9 at line 9 of Sub/Exporter.pm # once (52µs+0s) by Exporter::Heavy::heavy_export at line 120 of Exporter/Heavy.pm sub UNIVERSAL::VERSION; # xsub
|  |  |  |  | # spent 72µs within UNIVERSAL::can which was called 4 times, avg 18µs/call: # 3 times (62µs+0s) by attributes::import at line 50 of attributes.pm, avg 21µs/call # once (11µs+0s) by Attribute::Handlers::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/Attribute/Handlers.pm:195] at line 171 of Attribute/Handlers.pm sub UNIVERSAL::can; # xsub
|  |  |  |  | # spent 96µs within UNIVERSAL::isa which was called 13 times, avg 7µs/call: # 10 times (77µs+0s) by base::import at line 74 of base.pm, avg 8µs/call # 3 times (19µs+0s) by Exception::Class::_make_subclass at line 152 of Exception/Class.pm, avg 6µs/call sub UNIVERSAL::isa; # xsub