Filename | /usr/local/libexec/sympa/task_manager-debug.pl |
Statements | Executed 479 statements in 1.45ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2755 | 2 | 1 | 372ms | 372ms | execute (xsub) | DBI::st::
12163 | 3 | 2 | 12.3ms | 12.3ms | can (xsub) | UNIVERSAL::
2754 | 2 | 1 | 6.74ms | 6.74ms | fetchrow_array (xsub) | DBI::st::
2 | 2 | 1 | 155µs | 155µs | do (xsub) | DBI::db::
3 | 3 | 1 | 146µs | 146µs | CORE:gpwnam (opcode) | main::
3 | 3 | 1 | 54µs | 54µs | CORE:ggrnam (opcode) | main::
1 | 1 | 1 | 26µs | 26µs | CORE:chdir (opcode) | main::
3 | 2 | 1 | 24µs | 163µs | prepare (xsub) | DBI::db::
7 | 6 | 4 | 18µs | 18µs | STORE (xsub) | DBI::common::
5 | 3 | 1 | 16µs | 16µs | FETCH (xsub) | DBI::common::
1 | 1 | 1 | 13µs | 264µs | sigterm | main::
3 | 2 | 1 | 12µs | 12µs | DESTROY (xsub) | DBI::common::
1 | 1 | 1 | 10µs | 10µs | CORE:umask (opcode) | main::
1 | 1 | 1 | 10µs | 10µs | disconnect_all (xsub) | DBI::dr::
1 | 1 | 1 | 8µs | 8µs | isa (xsub) | UNIVERSAL::
2 | 1 | 1 | 8µs | 132µs | ping (xsub) | DBI::db::
2 | 1 | 1 | 7µs | 7µs | can (xsub) | DBI::common::
1 | 1 | 1 | 6µs | 6.67ms | connect (xsub) | DBI::dr::
4 | 1 | 1 | 4µs | 4µs | SvREADONLY (xsub) | Internals::
1 | 1 | 1 | 2µs | 2µs | connected (xsub) | DBI::db::
1 | 1 | 1 | 1µs | 1µs | DESTROY (xsub) | DBD::_mem::common::
0 | 0 | 0 | 0s | 0s | BEGIN@29 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@30 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@31 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@32 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@33 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@34 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@35 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@37 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@38 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@39 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@40 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@41 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@42 | main::
0 | 0 | 0 | 0s | 0s | BEGIN@43 | main::
0 | 0 | 0 | 0s | 0s | CORE:pack (opcode) | main::
0 | 0 | 0 | 0s | 0s | RUNTIME | main::
0 | 0 | 0 | 0s | 0s | __ANON__ (xsub) | main::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
0 | 5 | 249µs | Profile data that couldn't be associated with a specific line: # spent 76µs making 1 call to File::Temp::END
# spent 75µs making 1 call to XML::LibXML::END
# spent 59µs making 1 call to DBI::END
# spent 20µs making 1 call to Crypt::OpenSSL::X509::END
# spent 19µs making 1 call to Class::Singleton::END | ||
1 | 1 | 93µs | #! /usr/local/bin/perl | ||
2 | # -*- indent-tabs-mode: nil; -*- | ||||
3 | # vim:ft=perl:et:sw=4 | ||||
4 | # $Id$ | ||||
5 | |||||
6 | # Sympa - SYsteme de Multi-Postage Automatique | ||||
7 | # | ||||
8 | # Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel | ||||
9 | # Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | ||||
10 | # 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites | ||||
11 | # Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER | ||||
12 | # Copyright 2017, 2018, 2019 The Sympa Community. See the AUTHORS.md file at | ||||
13 | # the top-level directory of this distribution and at | ||||
14 | # <https://github.com/sympa-community/sympa.git>. | ||||
15 | # | ||||
16 | # This program is free software; you can redistribute it and/or modify | ||||
17 | # it under the terms of the GNU General Public License as published by | ||||
18 | # the Free Software Foundation; either version 2 of the License, or | ||||
19 | # (at your option) any later version. | ||||
20 | # | ||||
21 | # This program is distributed in the hope that it will be useful, | ||||
22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
24 | # GNU General Public License for more details. | ||||
25 | # | ||||
26 | # You should have received a copy of the GNU General Public License | ||||
27 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
28 | |||||
29 | use lib split(/:/, $ENV{SYMPALIB} || ''), '/usr/local/libexec/sympa'; | ||||
30 | use strict; | ||||
31 | use warnings; | ||||
32 | use English qw(-no_match_vars); | ||||
33 | use Getopt::Long; | ||||
34 | use Pod::Usage; | ||||
35 | use POSIX qw(); | ||||
36 | |||||
37 | use Conf; | ||||
38 | use Sympa::Constants; | ||||
39 | use Sympa::Crash; # Show traceback. | ||||
40 | use Sympa::Log; | ||||
41 | use Sympa::Process; | ||||
42 | use Sympa::Spindle::ProcessTask; | ||||
43 | use Sympa::Spool::Listmaster; | ||||
44 | |||||
45 | my $process = Sympa::Process->instance; | ||||
46 | $process->init(pidname => 'task_manager'); | ||||
47 | |||||
48 | my %options; | ||||
49 | unless ( | ||||
50 | GetOptions( | ||||
51 | \%main::options, 'config|f=s', 'debug|d', 'help|h', | ||||
52 | 'version|v', 'log_level=s', 'foreground|F' | ||||
53 | ) | ||||
54 | ) { | ||||
55 | pod2usage(-exitval => 1, -output => \*STDERR); | ||||
56 | } | ||||
57 | if ($main::options{'help'}) { | ||||
58 | pod2usage(0); | ||||
59 | } elsif ($main::options{'version'}) { | ||||
60 | printf "Sympa %s\n", Sympa::Constants::VERSION; | ||||
61 | exit 0; | ||||
62 | } | ||||
63 | $Conf::sympa_config = $main::options{config}; | ||||
64 | |||||
65 | if ($main::options{'debug'}) { | ||||
66 | $main::options{'log_level'} = 2 unless $main::options{'log_level'}; | ||||
67 | $main::options{'foreground'} = 1; | ||||
68 | } | ||||
69 | |||||
70 | my $log = Sympa::Log->instance; | ||||
71 | $log->{log_to_stderr} = 'all' if $main::options{'foreground'}; | ||||
72 | |||||
73 | my $adrlist = {}; | ||||
74 | |||||
75 | # Load sympa.conf | ||||
76 | unless (Conf::load()) { | ||||
77 | die sprintf | ||||
78 | "Unable to load Sympa configuration, file %s or one of the virtual host robot.conf files contain errors. Exiting.\n", | ||||
79 | Conf::get_sympa_conf(); | ||||
80 | } | ||||
81 | |||||
82 | $log->openlog($Conf::Conf{'log_facility'}, $Conf::Conf{'log_socket_type'}); | ||||
83 | |||||
84 | # setting log_level using conf unless it is set by calling option | ||||
85 | if ($main::options{'log_level'}) { | ||||
86 | $log->{level} = $main::options{'log_level'}; | ||||
87 | $log->syslog( | ||||
88 | 'info', | ||||
89 | 'Configuration file read, log level set using options: %s', | ||||
90 | $main::options{'log_level'} | ||||
91 | ); | ||||
92 | } else { | ||||
93 | $log->{level} = $Conf::Conf{'log_level'}; | ||||
94 | $log->syslog( | ||||
95 | 'info', | ||||
96 | 'Configuration file read, default log level %s', | ||||
97 | $Conf::Conf{'log_level'} | ||||
98 | ); | ||||
99 | } | ||||
100 | |||||
101 | # Put ourselves in background if not in debug mode. | ||||
102 | 1 | 700ns | 1 | 18.2ms | unless ($main::options{'foreground'}) { # spent 18.2ms making 1 call to Sympa::Process::daemonize |
103 | $process->daemonize; | ||||
104 | } | ||||
105 | |||||
106 | # Create and write the PID file. | ||||
107 | 1 | 33µs | 1 | 2.53ms | $process->write_pid(initial => 1); # spent 2.53ms making 1 call to Sympa::Process::write_pid |
108 | # If process is running in foreground, don't write STDERR to a dedicated file. | ||||
109 | 1 | 7µs | 1 | 219µs | unless ($main::options{foreground}) { # spent 219µs making 1 call to Sympa::Process::direct_stderr_to_file |
110 | $process->direct_stderr_to_file; | ||||
111 | } | ||||
112 | |||||
113 | ## Set the UserID & GroupID for the process | ||||
114 | 1 | 86µs | 1 | 18µs | $GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2]; # spent 18µs making 1 call to main::CORE:ggrnam |
115 | 1 | 82µs | 1 | 49µs | $UID = $EUID = (getpwnam(Sympa::Constants::USER))[2]; # spent 49µs making 1 call to main::CORE:gpwnam |
116 | |||||
117 | ## Required on FreeBSD to change ALL IDs(effective UID + real UID + saved UID) | ||||
118 | 1 | 87µs | 2 | 72µs | POSIX::setuid((getpwnam(Sympa::Constants::USER))[2]); # spent 51µs making 1 call to main::CORE:gpwnam
# spent 21µs making 1 call to POSIX::setuid |
119 | 1 | 44µs | 2 | 24µs | POSIX::setgid((getgrnam(Sympa::Constants::GROUP))[2]); # spent 19µs making 1 call to main::CORE:ggrnam
# spent 5µs making 1 call to POSIX::setgid |
120 | |||||
121 | # Check if the UID has correctly been set (useful on OS X) | ||||
122 | 1 | 76µs | 2 | 62µs | unless (($GID == (getgrnam(Sympa::Constants::GROUP))[2]) # spent 45µs making 1 call to main::CORE:gpwnam
# spent 16µs making 1 call to main::CORE:ggrnam |
123 | && ($UID == (getpwnam(Sympa::Constants::USER))[2])) { | ||||
124 | die | ||||
125 | "Failed to change process user ID and group ID. Note that on some OS Perl scripts can't change their real UID. In such circumstances Sympa should be run via sudo.\n"; | ||||
126 | } | ||||
127 | |||||
128 | ## Sets the UMASK | ||||
129 | 1 | 22µs | 1 | 10µs | umask(oct($Conf::Conf{'umask'})); # spent 10µs making 1 call to main::CORE:umask |
130 | |||||
131 | ## Change to list root | ||||
132 | 1 | 38µs | 1 | 26µs | unless (chdir($Conf::Conf{'home'})) { # spent 26µs making 1 call to main::CORE:chdir |
133 | die sprintf 'Unable to change to directory %s', $Conf::Conf{'home'}; | ||||
134 | } | ||||
135 | |||||
136 | # Most initializations have now been done. | ||||
137 | 1 | 31µs | 1 | 690µs | $log->syslog('notice', 'Task_Manager %s Started', # spent 690µs making 1 call to Sympa::Log::syslog |
138 | Sympa::Constants::VERSION()); | ||||
139 | |||||
140 | 1 | 54µs | 1 | 2.87ms | my $spindle = Sympa::Spindle::ProcessTask->new; # spent 2.87ms making 1 call to Sympa::Spindle::new |
141 | |||||
142 | ## Catch signals, in order to exit cleanly, whenever possible. | ||||
143 | 1 | 12µs | $SIG{'TERM'} = \&sigterm; | ||
144 | 1 | 4µs | $SIG{'INT'} = \&sigterm; | ||
145 | |||||
146 | # Infinite loop scanning the spool (unless a sig TERM is received). | ||||
147 | 1 | 2µs | while (not $spindle->{finish}) { | ||
148 | 229 | 436µs | 229 | 34.5s | $spindle->spin; # spent 34.5s making 229 calls to Sympa::Spindle::spin, avg 151ms/call |
149 | |||||
150 | 229 | 236µs | last if $spindle->{finish}; | ||
151 | |||||
152 | # If the spool was empty, sleep for a while. | ||||
153 | # sleep 60; | ||||
154 | } | ||||
155 | |||||
156 | # Purge grouped notifications | ||||
157 | 1 | 9µs | 2 | 17µs | Sympa::Spool::Listmaster->instance->flush(purge => 1); # spent 13µs making 1 call to Sympa::Spool::Listmaster::flush
# spent 4µs making 1 call to Class::Singleton::instance |
158 | |||||
159 | 1 | 2µs | 1 | 179µs | $log->syslog('notice', 'Task_Manager exited normally due to signal'); # spent 179µs making 1 call to Sympa::Log::syslog |
160 | 1 | 3µs | 1 | 487µs | $process->remove_pid(final => 1); # spent 487µs making 1 call to Sympa::Process::remove_pid |
161 | |||||
162 | 1 | 85µs | exit(0); | ||
163 | |||||
164 | ## task creations | ||||
165 | # Obsoleted. Use Sympa::Task::new() and Sympa::Spool::Task::store(). | ||||
166 | #sub create; | ||||
167 | |||||
168 | ## check the syntax of a task | ||||
169 | # Moved: Use Sympa::Task::_check(). | ||||
170 | #sub check; | ||||
171 | |||||
172 | ## check a task line | ||||
173 | # Moved: Use Sympa::Task::_chk_line(). | ||||
174 | #sub chk_line; | ||||
175 | |||||
176 | ## check the arguments of a command | ||||
177 | # Moved: Use Sympa::Task::_chk_cmd(). | ||||
178 | #sub chk_cmd; | ||||
179 | |||||
180 | ### TASK EXECUTION SUBROUTINES ### | ||||
181 | |||||
182 | # Moved to Sympa::Spinlde::ProcessTask module. | ||||
183 | #sub execute; | ||||
184 | #sub cmd_process; | ||||
185 | #sub rm_file; | ||||
186 | #sub stop; | ||||
187 | #sub send_msg; | ||||
188 | #sub next_cmd; | ||||
189 | #sub select_subs; | ||||
190 | #sub delete_subs_cmd; | ||||
191 | #sub create_cmd; | ||||
192 | #sub exec_cmd; | ||||
193 | #sub purge_logs_table; | ||||
194 | #sub _db_log_del; | ||||
195 | #sub purge_session_table; | ||||
196 | #sub purge_spools; | ||||
197 | #sub _clean_spool; | ||||
198 | #sub purge_tables; | ||||
199 | #sub purge_one_time_ticket_table; | ||||
200 | #sub purge_user_table; | ||||
201 | #sub purge_orphan_bounces; | ||||
202 | #sub expire_bounce; | ||||
203 | |||||
204 | # Removed because not yet fully implemented. See r11771. | ||||
205 | #sub chk_cert_expiration; | ||||
206 | |||||
207 | # Removed becuase not yet fully implemented. See r11771. | ||||
208 | #sub update_crl; | ||||
209 | |||||
210 | # Moved to Sympa::Spindle::ProcessTask module. | ||||
211 | #sub eval_bouncers; | ||||
212 | #sub none; | ||||
213 | #sub process_bouncers; | ||||
214 | #sub get_score; | ||||
215 | |||||
216 | ### MISCELLANEOUS SUBROUTINES ### | ||||
217 | |||||
218 | ## when we catch signal, just change the value of the loop variable. | ||||
219 | # spent 264µs (13+251) within main::sigterm which was called:
# once (13µs+251µs) by Sympa::List::__ANON__[/usr/local/libexec/sympa/Sympa/List.pm:4267] at line 4267 of /usr/local/libexec/sympa/Sympa/List.pm | ||||
220 | 1 | 700ns | my ($sig) = @_; | ||
221 | 1 | 3µs | 1 | 251µs | $log->syslog('notice', # spent 251µs making 1 call to Sympa::Log::syslog |
222 | 'Signal %s received, still processing current task', $sig); | ||||
223 | 1 | 8µs | $spindle->{finish} = 'term'; | ||
224 | } | ||||
225 | |||||
226 | ## sort task name by their epoch date | ||||
227 | # No longer used. | ||||
228 | #sub epoch_sort; | ||||
229 | |||||
230 | # Moved to Sympa::Spindle::ProcessTask::_change_label(). | ||||
231 | #sub change_label; | ||||
232 | |||||
233 | # Moved to Sympa::Spindle::ProcessTask::error(). | ||||
234 | #sub error; | ||||
235 | |||||
236 | # Moved to Sympa::Spindle::ProcessTask module. | ||||
237 | #sub sync_include; | ||||
238 | |||||
239 | __END__ | ||||
# spent 1µs within DBD::_mem::common::DESTROY which was called:
# once (1µs+0s) by Sympa::Database::do_prepared_query at line 380 of /usr/local/libexec/sympa/Sympa/Database.pm | |||||
# spent 12µs within DBI::common::DESTROY which was called 3 times, avg 4µs/call:
# 2 times (10µs+0s) by Sympa::Database::do_prepared_query at line 380 of /usr/local/libexec/sympa/Sympa/Database.pm, avg 5µs/call
# once (1µs+0s) by Sympa::Database::connect at line 153 of /usr/local/libexec/sympa/Sympa/Database.pm | |||||
# spent 16µs within DBI::common::FETCH which was called 5 times, avg 3µs/call:
# 2 times (8µs+0s) by DBD::Pg::db::ping at line 459 of DBD/Pg.pm, avg 4µs/call
# 2 times (2µs+0s) by DBD::Pg::dr::connect at line 270 of DBD/Pg.pm, avg 1µs/call
# once (6µs+0s) by DBD::Pg::dr::connect at line 269 of DBD/Pg.pm | |||||
# spent 18µs within DBI::common::STORE which was called 7 times, avg 2µs/call:
# 2 times (3µs+0s) by DBI::__ANON__[/usr/local/lib/perl5/site_perl/mach/5.32/DBI.pm:746] at line 731 of DBI.pm, avg 2µs/call
# once (6µs+0s) by DBD::Pg::dr::connect at line 270 of DBD/Pg.pm
# once (3µs+0s) by Sympa::DatabaseDriver::PostgreSQL::connect at line 66 of /usr/local/libexec/sympa/Sympa/DatabaseDriver/PostgreSQL.pm
# once (2µs+0s) by DBI::connect at line 750 of DBI.pm
# once (2µs+0s) by DBI::__ANON__[/usr/local/lib/perl5/site_perl/mach/5.32/DBI.pm:746] at line 734 of DBI.pm
# once (1µs+0s) by Sympa::Database::_connect at line 203 of /usr/local/libexec/sympa/Sympa/Database.pm | |||||
# spent 7µs within DBI::common::can which was called 2 times, avg 3µs/call:
# 2 times (7µs+0s) by Sympa::Database::ping at line 453 of /usr/local/libexec/sympa/Sympa/Database.pm, avg 3µs/call | |||||
# spent 2µs within DBI::db::connected which was called:
# once (2µs+0s) by DBI::__ANON__[/usr/local/lib/perl5/site_perl/mach/5.32/DBI.pm:746] at line 741 of DBI.pm | |||||
# spent 155µs within DBI::db::do which was called 2 times, avg 78µs/call:
# once (109µs+0s) by Sympa::DatabaseDriver::PostgreSQL::connect at line 67 of /usr/local/libexec/sympa/Sympa/DatabaseDriver/PostgreSQL.pm
# once (46µs+0s) by Sympa::DatabaseDriver::PostgreSQL::connect at line 68 of /usr/local/libexec/sympa/Sympa/DatabaseDriver/PostgreSQL.pm | |||||
# spent 132µs (8+124) within DBI::db::ping which was called 2 times, avg 66µs/call:
# 2 times (8µs+124µs) by Sympa::Database::ping at line 454 of /usr/local/libexec/sympa/Sympa/Database.pm, avg 66µs/call | |||||
# spent 163µs (24+140) within DBI::db::prepare which was called 3 times, avg 54µs/call:
# 2 times (20µs+101µs) by Sympa::Database::do_prepared_query at line 327 of /usr/local/libexec/sympa/Sympa/Database.pm, avg 60µs/call
# once (4µs+39µs) by Sympa::Database::do_prepared_query at line 358 of /usr/local/libexec/sympa/Sympa/Database.pm | |||||
# spent 6.67ms (6µs+6.67) within DBI::dr::connect which was called:
# once (6µs+6.67ms) by DBI::__ANON__[/usr/local/lib/perl5/site_perl/mach/5.32/DBI.pm:746] at line 679 of DBI.pm | |||||
# spent 10µs within DBI::dr::disconnect_all which was called:
# once (10µs+0s) by DBI::disconnect_all at line 758 of DBI.pm | |||||
# spent 372ms within DBI::st::execute which was called 2755 times, avg 135µs/call:
# 2754 times (371ms+0s) by Sympa::Database::do_prepared_query at line 350 of /usr/local/libexec/sympa/Sympa/Database.pm, avg 135µs/call
# once (1.17ms+0s) by Sympa::Database::do_prepared_query at line 381 of /usr/local/libexec/sympa/Sympa/Database.pm | |||||
# spent 6.74ms within DBI::st::fetchrow_array which was called 2754 times, avg 2µs/call:
# 1377 times (3.84ms+0s) by Sympa::List::has_included_users at line 5800 of /usr/local/libexec/sympa/Sympa/List.pm, avg 3µs/call
# 1377 times (2.90ms+0s) by Sympa::List::has_included_users at line 5817 of /usr/local/libexec/sympa/Sympa/List.pm, avg 2µs/call | |||||
# spent 4µs within Internals::SvREADONLY which was called 4 times, avg 875ns/call:
# 4 times (4µs+0s) by constant::import at line 164 of constant.pm, avg 875ns/call | |||||
# spent 12.3ms within UNIVERSAL::can which was called 12163 times, avg 1µs/call:
# 12161 times (12.3ms+0s) by Sympa::Log::syslog at line 112 of /usr/local/libexec/sympa/Sympa/Log.pm, avg 1µs/call
# once (11µs+0s) by Sympa::Spindle::new at line 40 of /usr/local/libexec/sympa/Sympa/Spindle.pm
# once (6µs+0s) by Sympa::Spindle::new at line 47 of /usr/local/libexec/sympa/Sympa/Spindle.pm | |||||
# spent 8µs within UNIVERSAL::isa which was called:
# once (8µs+0s) by base::import at line 96 of base.pm | |||||
# spent 26µs within main::CORE:chdir which was called:
# once (26µs+0s) by main::RUNTIME at line 132 | |||||
sub main::CORE:ggrnam; # opcode | |||||
sub main::CORE:gpwnam; # opcode | |||||
# spent 10µs within main::CORE:umask which was called:
# once (10µs+0s) by main::RUNTIME at line 129 |