← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Tue Nov 7 05:38:10 2017
Reported on Tue Nov 7 06:16:01 2017

Filename/usr/local/lib/perl5/5.24/mach/Sys/Hostname.pm
StatementsExecuted 18 statements in 1.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11157µs65µsSys::Hostname::::BEGIN@3Sys::Hostname::BEGIN@3
11153µs404µsSys::Hostname::::BEGIN@16Sys::Hostname::BEGIN@16
11126µs50µsSys::Hostname::::hostnameSys::Hostname::hostname
11124µs24µsSys::Hostname::::ghnameSys::Hostname::ghname (xsub)
11123µs210µsSys::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
1package Sys::Hostname;
2
3271µs273µs
# spent 65µs (57+8) within Sys::Hostname::BEGIN@3 which was called: # once (57µs+8µs) by Mail::SpamAssassin::Util::BEGIN@75 at line 3
use strict;
# spent 65µs making 1 call to Sys::Hostname::BEGIN@3 # spent 8µs making 1 call to strict::import
4
52227µs2397µs
# spent 210µs (23+187) within Sys::Hostname::BEGIN@5 which was called: # once (23µs+187µs) by Mail::SpamAssassin::Util::BEGIN@75 at line 5
use Carp;
# spent 210µs making 1 call to Sys::Hostname::BEGIN@5 # spent 187µs making 1 call to Exporter::import
6
718µsrequire Exporter;
8
9120µsour @ISA = qw/ Exporter /;
1012µsour @EXPORT = qw/ hostname /;
11
12our $VERSION;
13
14our $host;
15
16
# spent 404µs (53+351) within Sys::Hostname::BEGIN@16 which was called: # once (53µs+351µs) by Mail::SpamAssassin::Util::BEGIN@75 at line 26
BEGIN {
1712µs $VERSION = '1.20';
18 {
19217µs local $SIG{__DIE__};
2017µs eval {
2112µs require XSLoader;
221366µs1351µs XSLoader::load();
# spent 351µs making 1 call to XSLoader::load
23 };
24111µs warn $@ if $@;
25 }
2611.00ms1404µs}
# spent 404µs making 1 call to Sys::Hostname::BEGIN@16
27
28
29
# spent 50µs (26+24) within Sys::Hostname::hostname which was called: # once (26µs+24µs) by Mail::SpamAssassin::Util::hostname at line 835 of Mail/SpamAssassin/Util.pm
sub hostname {
30
31 # method 1 - we already know it
3213µs return $host if defined $host;
33
34 # method 1' - try to ask the system
35139µs124µs $host = ghname() if defined &ghname;
# spent 24µs making 1 call to Sys::Hostname::ghname
36110µs return $host if defined $host;
37
38 if ($^O eq 'VMS') {
39
40 # method 2 - no sockets ==> return DECnet node name
41 eval { local $SIG{__DIE__}; $host = (gethostbyname('me'))[0] };
42 if ($@) { return $host = $ENV{'SYS$NODE'}; }
43
44 # method 3 - has someone else done the job already? It's common for the
45 # TCP/IP stack to advertise the hostname via a logical name. (Are
46 # there any other logicals which TCP/IP stacks use for the host name?)
47 $host = $ENV{'ARPANET_HOST_NAME'} || $ENV{'INTERNET_HOST_NAME'} ||
48 $ENV{'MULTINET_HOST_NAME'} || $ENV{'UCX$INET_HOST'} ||
49 $ENV{'TCPWARE_DOMAINNAME'} || $ENV{'NEWS_ADDRESS'};
50 return $host if $host;
51
52 # method 4 - does hostname happen to work?
53 my($rslt) = `hostname`;
54 if ($rslt !~ /IVVERB/) { ($host) = $rslt =~ /^(\S+)/; }
55 return $host if $host;
56
57 # rats!
58 $host = '';
59 croak "Cannot get host name of local machine";
60
61 }
62 elsif ($^O eq 'MSWin32') {
63 ($host) = gethostbyname('localhost');
64 chomp($host = `hostname 2> NUL`) unless defined $host;
65 return $host;
66 }
67 else { # Unix
68 # is anyone going to make it here?
69
70 local $ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin'; # Paranoia.
71
72 # method 2 - syscall is preferred since it avoids tainting problems
73 # XXX: is it such a good idea to return hostname untainted?
74 eval {
75 local $SIG{__DIE__};
76 require "syscall.ph";
77 $host = "\0" x 65; ## preload scalar
78 syscall(&SYS_gethostname, $host, 65) == 0;
79 }
80
81 # method 2a - syscall using systeminfo instead of gethostname
82 # -- needed on systems like Solaris
83 || eval {
84 local $SIG{__DIE__};
85 require "sys/syscall.ph";
86 require "sys/systeminfo.ph";
87 $host = "\0" x 65; ## preload scalar
88 syscall(&SYS_systeminfo, &SI_HOSTNAME, $host, 65) != -1;
89 }
90
91 # method 3 - trusty old hostname command
92 || eval {
93 local $SIG{__DIE__};
94 local $SIG{CHLD};
95 $host = `(hostname) 2>/dev/null`; # BSDish
96 }
97
98 # method 4 - use POSIX::uname(), which strictly can't be expected to be
99 # correct
100 || eval {
101 local $SIG{__DIE__};
102 require POSIX;
103 $host = (POSIX::uname())[1];
104 }
105
106 # method 5 - sysV uname command (may truncate)
107 || eval {
108 local $SIG{__DIE__};
109 $host = `uname -n 2>/dev/null`; ## sysVish
110 }
111
112 # bummer
113 || croak "Cannot get host name of local machine";
114
115 # remove garbage
116 $host =~ tr/\0\r\n//d;
117 $host;
118 }
119}
120
121120µs1;
122
123__END__
 
# spent 24µs within Sys::Hostname::ghname which was called: # once (24µs+0s) by Sys::Hostname::hostname at line 35
sub Sys::Hostname::ghname; # xsub