← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Sun Nov 5 02:36:06 2017
Reported on Sun Nov 5 02:56:21 2017

Filename/usr/local/lib/perl5/site_perl/mach/5.24/Razor2/Syslog.pm
StatementsExecuted 15 statements in 1.19ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11169µs327µsRazor2::Syslog::::BEGIN@3Razor2::Syslog::BEGIN@3
11139µs156µsRazor2::Syslog::::BEGIN@6Razor2::Syslog::BEGIN@6
11134µs5.30msRazor2::Syslog::::BEGIN@4Razor2::Syslog::BEGIN@4
11126µs1.30msRazor2::Syslog::::BEGIN@5Razor2::Syslog::BEGIN@5
0000s0sRazor2::Syslog::::newRazor2::Syslog::new
0000s0sRazor2::Syslog::::sendRazor2::Syslog::send
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Razor2::Syslog;
2
3280µs2585µs
# spent 327µs (69+258) within Razor2::Syslog::BEGIN@3 which was called: # once (69µs+258µs) by Razor2::Logger::BEGIN@6 at line 3
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
# spent 327µs making 1 call to Razor2::Syslog::BEGIN@3 # spent 258µs making 1 call to vars::import
4275µs210.6ms
# spent 5.30ms (34µs+5.27) within Razor2::Syslog::BEGIN@4 which was called: # once (34µs+5.27ms) by Razor2::Logger::BEGIN@6 at line 4
use IO::Socket;
# spent 5.30ms making 1 call to Razor2::Syslog::BEGIN@4 # spent 5.27ms making 1 call to IO::Socket::import
5265µs22.58ms
# spent 1.30ms (26µs+1.28) within Razor2::Syslog::BEGIN@5 which was called: # once (26µs+1.28ms) by Razor2::Logger::BEGIN@6 at line 5
use IO::File;
# spent 1.30ms making 1 call to Razor2::Syslog::BEGIN@5 # spent 1.28ms making 1 call to Exporter::import
62890µs2273µs
# spent 156µs (39+117) within Razor2::Syslog::BEGIN@6 which was called: # once (39µs+117µs) by Razor2::Logger::BEGIN@6 at line 6
use Data::Dumper;
# spent 156µs making 1 call to Razor2::Syslog::BEGIN@6 # spent 117µs making 1 call to Exporter::import
7
812µsrequire Exporter;
9
10129µs@ISA = qw(Exporter AutoLoader);
11# Items to export into callers namespace by default. Note: do not export
12# names by default without a very good reason. Use EXPORT_OK instead.
13# Do not simply export all your public functions/methods/constants.
1412µs@EXPORT = qw(
15
16);
1712µs$VERSION = '0.03';
18
19
20# Preloaded methods go here.
21
22111µsmy %syslog_priorities=(
23 emerg => 0,
24 alert => 1,
25 crit => 2,
26 err => 3,
27 warning => 4,
28 notice => 5,
29 info => 6,
30 debug => 7
31);
32
33117µsmy %syslog_facilities=(
34 kern => 0,
35 user => 1,
36 mail => 2,
37 daemon => 3,
38 auth => 4,
39 syslog => 5,
40 lpr => 6,
41 news => 7,
42 uucp => 8,
43 cron => 9,
44 authpriv=> 10,
45 ftp => 11,
46 local0 => 16,
47 local1 => 17,
48 local2 => 18,
49 local3 => 19,
50 local4 => 20,
51 local5 => 21,
52 local6 => 22,
53);
54
55
56sub new {
57
58 my $class = shift;
59 my $name = $0;
60 if($name =~ /.+\/(.+)/){
61 $name = $1;
62 }
63 my $self = { Name => $name,
64 Facility => 'local5',
65 Priority => 'err',
66 SyslogPort => 514,
67 SyslogHost => '127.0.0.1'};
68 bless $self,$class;
69 my %par = @_;
70
71 foreach (keys %par){
72 $self->{$_}=$par{$_};
73 }
74
75 my $sock=new IO::Socket::INET(PeerAddr => $$self{SyslogHost},
76 PeerPort => $$self{SyslogPort},
77 Proto => 'udp');
78 die "Socket could not be created : $!\n" unless $sock;
79
80 $self->{sock} = $sock;
81
82 return $self;
83
84}
85
86
87sub send {
88
89 my $self = shift;
90 my $msg=shift;
91 my %par = @_;
92 my %local=%$self;
93
94 foreach (keys %par){
95 $local{$_}=$par{$_};
96 }
97
98 my $pid=$$;
99 my $facility_i=$syslog_facilities{$local{Facility}};
100 my $priority_i=$syslog_priorities{$local{Priority}};
101
102 if(!defined $facility_i){
103 $facility_i=21;
104 }
105
106 if(!defined $priority_i){
107 $priority_i=4;
108 }
109
110 my $d=(($facility_i<<3)|($priority_i));
111 my $message = "<$d>$local{Name}\[$pid\]: $msg";
112
113 my $sock = $self->{sock};
114
115 # Send the message to the socket directly.
116 $sock->send($message);
117 # Flush the socket, to ensure that messages don't arrive combined into one packet.
118 $sock->flush;
119
120}
121
122
123# Autoload methods go after =cut, and are processed by the autosplit program.
124
125121µs1;
126__END__