Profile of Sys/Hostname.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:38 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/5.12.3/x86_64-linux/Sys/Hostname.pm
Statements | Executed 23 statements in 752µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 14µs | 17µs | Sys::Hostname::::BEGIN@3Sys::Hostname::BEGIN@3
1 | 1 | 1 | 12µs | 201µs | Sys::Hostname::::BEGIN@17Sys::Hostname::BEGIN@17
1 | 1 | 1 | 9µs | 9µs | Sys::Hostname::::ghnameSys::Hostname::ghname (xsub)
1 | 1 | 1 | 9µs | 18µs | Sys::Hostname::::hostnameSys::Hostname::hostname
1 | 1 | 1 | 9µs | 54µs | Sys::Hostname::::BEGIN@5Sys::Hostname::BEGIN@5

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

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Sys::Hostname;
2 |  |  |  |  |
3 | 3 | 17µs | 2 | 19µs | # spent 17µs (14+2) within Sys::Hostname::BEGIN@3 which was called: # once (14µs+2µs) by LockFile::Simple::BEGIN@72 at line 3 use strict; # spent 17µs making 1 call to Sys::Hostname::BEGIN@3 # spent 2µs making 1 call to strict::import
4 |  |  |  |  |
5 | 3 | 95µs | 2 | 99µs | # spent 54µs (9+45) within Sys::Hostname::BEGIN@5 which was called: # once (9µs+45µs) by LockFile::Simple::BEGIN@72 at line 5 use Carp; # spent 54µs making 1 call to Sys::Hostname::BEGIN@5 # spent 45µs making 1 call to Exporter::import
6 |  |  |  |  |
7 | 1 | 700ns |  |  | require Exporter;
8 | 1 | 500ns |  |  | require AutoLoader;
9 |  |  |  |  |
10 | 1 | 12µs |  |  | our @ISA = qw/ Exporter AutoLoader /;
11 | 1 | 500ns |  |  | our @EXPORT = qw/ hostname /;
12 |  |  |  |  |
13 | 1 | 200ns |  |  | our $VERSION;
14 |  |  |  |  |
15 | 1 | 100ns |  |  | our $host;
16 |  |  |  |  |
17 |  |  |  |  | # spent 201µs (12+189) within Sys::Hostname::BEGIN@17 which was called: # once (12µs+189µs) by LockFile::Simple::BEGIN@72 at line 27 BEGIN {
18 | 1 | 400ns |  |  | $VERSION = '1.11';
19 |  |  |  |  | {
20 | 2 | 8µs |  |  | local $SIG{__DIE__};
21 | 1 | 600ns |  |  | eval {
22 | 1 | 400ns |  |  | require XSLoader;
23 | 1 | 193µs | 1 | 189µs | XSLoader::load('Sys::Hostname', $VERSION); # spent 189µs making 1 call to XSLoader::load
24 |  |  |  |  | };
25 | 1 | 1µs |  |  | warn $@ if $@;
26 |  |  |  |  | }
27 | 1 | 398µs | 1 | 201µs | } # spent 201µs making 1 call to Sys::Hostname::BEGIN@17
28 |  |  |  |  |
29 |  |  |  |  |
30 |  |  |  |  | # spent 18µs (9+9) within Sys::Hostname::hostname which was called: # once (9µs+9µs) by Log::Log4perl::Layout::PatternLayout::BEGIN@29 at line 34 of Log/Log4perl/Layout/PatternLayout.pm sub hostname {
31 |  |  |  |  |
32 |  |  |  |  | # method 1 - we already know it
33 | 1 | 700ns |  |  | return $host if defined $host;
34 |  |  |  |  |
35 |  |  |  |  | # method 1' - try to ask the system
36 | 1 | 15µs | 1 | 9µs | $host = ghname() if defined &ghname; # spent 9µs making 1 call to Sys::Hostname::ghname
37 | 1 | 4µs |  |  | return $host if defined $host;
38 |  |  |  |  |
39 |  |  |  |  | if ($^O eq 'VMS') {
40 |  |  |  |  |
41 |  |  |  |  | # method 2 - no sockets ==> return DECnet node name
42 |  |  |  |  | eval { local $SIG{__DIE__}; $host = (gethostbyname('me'))[0] };
43 |  |  |  |  | if ($@) { return $host = $ENV{'SYS$NODE'}; }
44 |  |  |  |  |
45 |  |  |  |  | # method 3 - has someone else done the job already? It's common for the
46 |  |  |  |  | # TCP/IP stack to advertise the hostname via a logical name. (Are
47 |  |  |  |  | # there any other logicals which TCP/IP stacks use for the host name?)
48 |  |  |  |  | $host = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
49 |  |  |  |  | $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
50 |  |  |  |  | $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
51 |  |  |  |  | return $host if $host;
52 |  |  |  |  |
53 |  |  |  |  | # method 4 - does hostname happen to work?
54 |  |  |  |  | my($rslt) = `hostname`;
55 |  |  |  |  | if ($rslt !~ /IVVERB/) { ($host) = $rslt =~ /^(\S+)/; }
56 |  |  |  |  | return $host if $host;
57 |  |  |  |  |
58 |  |  |  |  | # rats!
59 |  |  |  |  | $host = '';
60 |  |  |  |  | croak "Cannot get host name of local machine";
61 |  |  |  |  |
62 |  |  |  |  | }
63 |  |  |  |  | elsif ($^O eq 'MSWin32') {
64 |  |  |  |  | ($host) = gethostbyname('localhost');
65 |  |  |  |  | chomp($host = `hostname 2> NUL`) unless defined $host;
66 |  |  |  |  | return $host;
67 |  |  |  |  | }
68 |  |  |  |  | elsif ($^O eq 'epoc') {
69 |  |  |  |  | $host = 'localhost';
70 |  |  |  |  | return $host;
71 |  |  |  |  | }
72 |  |  |  |  | else { # Unix
73 |  |  |  |  | # is anyone going to make it here?
74 |  |  |  |  |
75 |  |  |  |  | local $ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin'; # Paranoia.
76 |  |  |  |  |
77 |  |  |  |  | # method 2 - syscall is preferred since it avoids tainting problems
78 |  |  |  |  | # XXX: is it such a good idea to return hostname untainted?
79 |  |  |  |  | eval {
80 |  |  |  |  | local $SIG{__DIE__};
81 |  |  |  |  | require "syscall.ph";
82 |  |  |  |  | $host = "\0" x 65; ## preload scalar
83 |  |  |  |  | syscall(&SYS_gethostname, $host, 65) == 0;
84 |  |  |  |  | }
85 |  |  |  |  |
86 |  |  |  |  | # method 2a - syscall using systeminfo instead of gethostname
87 |  |  |  |  | # -- needed on systems like Solaris
88 |  |  |  |  | || eval {
89 |  |  |  |  | local $SIG{__DIE__};
90 |  |  |  |  | require "sys/syscall.ph";
91 |  |  |  |  | require "sys/systeminfo.ph";
92 |  |  |  |  | $host = "\0" x 65; ## preload scalar
93 |  |  |  |  | syscall(&SYS_systeminfo, &SI_HOSTNAME, $host, 65) != -1;
94 |  |  |  |  | }
95 |  |  |  |  |
96 |  |  |  |  | # method 3 - trusty old hostname command
97 |  |  |  |  | || eval {
98 |  |  |  |  | local $SIG{__DIE__};
99 |  |  |  |  | local $SIG{CHLD};
100 |  |  |  |  | $host = `(hostname) 2>/dev/null`; # bsdish
101 |  |  |  |  | }
102 |  |  |  |  |
103 |  |  |  |  | # method 4 - use POSIX::uname(), which strictly can't be expected to be
104 |  |  |  |  | # correct
105 |  |  |  |  | || eval {
106 |  |  |  |  | local $SIG{__DIE__};
107 |  |  |  |  | require POSIX;
108 |  |  |  |  | $host = (POSIX::uname())[1];
109 |  |  |  |  | }
110 |  |  |  |  |
111 |  |  |  |  | # method 5 - sysV uname command (may truncate)
112 |  |  |  |  | || eval {
113 |  |  |  |  | local $SIG{__DIE__};
114 |  |  |  |  | $host = `uname -n 2>/dev/null`; ## sysVish
115 |  |  |  |  | }
116 |  |  |  |  |
117 |  |  |  |  | # method 6 - Apollo pre-SR10
118 |  |  |  |  | || eval {
119 |  |  |  |  | local $SIG{__DIE__};
120 |  |  |  |  | my($a,$b,$c,$d);
121 |  |  |  |  | ($host,$a,$b,$c,$d)=split(/[:\. ]/,`/com/host`,6);
122 |  |  |  |  | }
123 |  |  |  |  |
124 |  |  |  |  | # bummer
125 |  |  |  |  | || croak "Cannot get host name of local machine";
126 |  |  |  |  |
127 |  |  |  |  | # remove garbage
128 |  |  |  |  | $host =~ tr/\0\r\n//d;
129 |  |  |  |  | $host;
130 |  |  |  |  | }
131 |  |  |  |  | }
132 |  |  |  |  |
133 | 1 | 4µs |  |  | 1;
134 |  |  |  |  |
135 |  |  |  |  | __END__
|  |  |  |  | # spent 9µs within Sys::Hostname::ghname which was called: # once (9µs+0s) by Sys::Hostname::hostname at line 36 sub Sys::Hostname::ghname; # xsub