← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Sun Nov 5 03:09:29 2017
Reported on Mon Nov 6 13:20:48 2017

Filename/usr/local/lib/perl5/site_perl/mach/5.24/Razor2/Syslog.pm
StatementsExecuted 15 statements in 1.12ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11138µs203µsRazor2::Syslog::::BEGIN@3Razor2::Syslog::BEGIN@3
11123µs728µsRazor2::Syslog::::BEGIN@5Razor2::Syslog::BEGIN@5
11120µs100µsRazor2::Syslog::::BEGIN@6Razor2::Syslog::BEGIN@6
11120µs3.33msRazor2::Syslog::::BEGIN@4Razor2::Syslog::BEGIN@4
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
3260µs2368µs
# spent 203µs (38+165) within Razor2::Syslog::BEGIN@3 which was called: # once (38µs+165µs) by Razor2::Logger::BEGIN@6 at line 3
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
# spent 203µs making 1 call to Razor2::Syslog::BEGIN@3 # spent 165µs making 1 call to vars::import
4263µs26.64ms
# spent 3.33ms (20µs+3.31) within Razor2::Syslog::BEGIN@4 which was called: # once (20µs+3.31ms) by Razor2::Logger::BEGIN@6 at line 4
use IO::Socket;
# spent 3.33ms making 1 call to Razor2::Syslog::BEGIN@4 # spent 3.31ms making 1 call to IO::Socket::import
5262µs21.43ms
# spent 728µs (23+705) within Razor2::Syslog::BEGIN@5 which was called: # once (23µs+705µs) by Razor2::Logger::BEGIN@6 at line 5
use IO::File;
# spent 728µs making 1 call to Razor2::Syslog::BEGIN@5 # spent 705µs making 1 call to Exporter::import
62868µs2180µs
# spent 100µs (20+80) within Razor2::Syslog::BEGIN@6 which was called: # once (20µs+80µs) by Razor2::Logger::BEGIN@6 at line 6
use Data::Dumper;
# spent 100µs making 1 call to Razor2::Syslog::BEGIN@6 # spent 80µs making 1 call to Exporter::import
7
812µsrequire Exporter;
9
10117µ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
33116µ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
125122µs1;
126__END__