Filename | /usr/local/libexec/sympa/Sympa/Spindle.pm |
Statements | Executed 1846 statements in 1.94ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
229 | 1 | 1 | 1.96ms | 34.5s | spin | Sympa::Spindle::
1 | 1 | 1 | 1.74ms | 2.87ms | new | Sympa::Spindle::
1 | 1 | 1 | 300ns | 300ns | CORE:sort (opcode) | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | BEGIN@30 | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | BEGIN@31 | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | BEGIN@32 | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | BEGIN@33 | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _init | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _on_failure | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _on_garbage | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _on_skip | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _on_success | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | _twist | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | add_stash | Sympa::Spindle::
0 | 0 | 0 | 0s | 0s | success | Sympa::Spindle::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # -*- indent-tabs-mode: nil; -*- | ||||
2 | # vim:ft=perl:et:sw=4 | ||||
3 | # $Id$ | ||||
4 | |||||
5 | # Sympa - SYsteme de Multi-Postage Automatique | ||||
6 | # | ||||
7 | # Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel | ||||
8 | # Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | ||||
9 | # 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites | ||||
10 | # Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER | ||||
11 | # Copyright 2017 The Sympa Community. See the AUTHORS.md file at the top-level | ||||
12 | # directory of this distribution and at | ||||
13 | # <https://github.com/sympa-community/sympa.git>. | ||||
14 | # | ||||
15 | # This program is free software; you can redistribute it and/or modify | ||||
16 | # it under the terms of the GNU General Public License as published by | ||||
17 | # the Free Software Foundation; either version 2 of the License, or | ||||
18 | # (at your option) any later version. | ||||
19 | # | ||||
20 | # This program is distributed in the hope that it will be useful, | ||||
21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
23 | # GNU General Public License for more details. | ||||
24 | # | ||||
25 | # You should have received a copy of the GNU General Public License | ||||
26 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
27 | |||||
28 | package Sympa::Spindle; | ||||
29 | |||||
30 | use strict; | ||||
31 | use warnings; | ||||
32 | use English qw(-no_match_vars); | ||||
33 | use Time::HiRes qw(); | ||||
34 | |||||
35 | # spent 2.87ms (1.74+1.13) within Sympa::Spindle::new which was called:
# once (1.74ms+1.13ms) by main::RUNTIME at line 140 of /usr/local/libexec/sympa/task_manager-debug.pl | ||||
36 | 1 | 1µs | my $class = shift; | ||
37 | 1 | 700ns | my %options = @_; | ||
38 | |||||
39 | 1 | 900ns | my $distaff; | ||
40 | 1 | 31µs | 1 | 11µs | if ($class->can('_distaff')) { # spent 11µs making 1 call to UNIVERSAL::can |
41 | 1 | 152µs | 1 | 600ns | die $EVAL_ERROR unless eval sprintf 'require %s', $class->_distaff; # spent 600ns making 1 call to Sympa::Spindle::ProcessTask::_distaff # spent 248µs executing statements in string eval |
42 | 1 | 25µs | 2 | 352µs | $distaff = $class->_distaff->new(%options); # spent 351µs making 1 call to Sympa::Spool::new
# spent 1µs making 1 call to Sympa::Spindle::ProcessTask::_distaff |
43 | 1 | 700ns | return undef unless $distaff; | ||
44 | } | ||||
45 | |||||
46 | 1 | 300ns | my %spools; | ||
47 | 1 | 11µs | 1 | 6µs | my $spools = $class->_spools if $class->can('_spools'); # spent 6µs making 1 call to UNIVERSAL::can |
48 | 1 | 21µs | 1 | 300ns | foreach my $key (sort keys %{$spools || {}}) { # spent 300ns making 1 call to Sympa::Spindle::CORE:sort |
49 | die $EVAL_ERROR unless eval sprintf 'require %s', $spools->{$key}; | ||||
50 | my $spool = $spools->{$key}->new; | ||||
51 | return undef unless $spool; | ||||
52 | |||||
53 | $spools{$key} = $spool; | ||||
54 | } | ||||
55 | |||||
56 | 1 | 3µs | my $self = bless {%options, %spools, distaff => $distaff} => $class; | ||
57 | 1 | 8µs | $self->{stash} ||= []; | ||
58 | |||||
59 | 1 | 4µs | 1 | 6µs | $self->_init(0) or return undef; # spent 6µs making 1 call to Sympa::Spindle::ProcessTask::_init |
60 | 1 | 5µs | $self; | ||
61 | } | ||||
62 | |||||
63 | sub add_stash { | ||||
64 | my $self = shift; | ||||
65 | my @params = @_; | ||||
66 | |||||
67 | $self->{stash} ||= []; | ||||
68 | push @{$self->{stash}}, [@params]; | ||||
69 | } | ||||
70 | |||||
71 | # spent 34.5s (1.96ms+34.5) within Sympa::Spindle::spin which was called 229 times, avg 151ms/call:
# 229 times (1.96ms+34.5s) by main::RUNTIME at line 148 of /usr/local/libexec/sympa/task_manager-debug.pl, avg 151ms/call | ||||
72 | 229 | 62µs | my $self = shift; | ||
73 | |||||
74 | 229 | 62µs | my $processed = 0; | ||
75 | |||||
76 | 229 | 34µs | while (1) { | ||
77 | 229 | 358µs | 229 | 4.24ms | $self->_init(1); # spent 4.24ms making 229 calls to Sympa::Spindle::ProcessTask::_init, avg 19µs/call |
78 | 229 | 483µs | 229 | 34.5s | my ($message, $handle) = $self->{distaff}->next; # spent 34.5s making 229 calls to Sympa::Spool::next, avg 150ms/call |
79 | |||||
80 | 229 | 121µs | if ($message and $handle) { | ||
81 | $self->{start_time} = Time::HiRes::time(); | ||||
82 | |||||
83 | my $status = $self->_twist($message); | ||||
84 | # If the result is arrayref, splice to the classes in it. | ||||
85 | while (ref $status eq 'ARRAY' and @$status) { | ||||
86 | foreach my $class (@$status) { | ||||
87 | die sprintf 'Illegal package name "%s"', $class | ||||
88 | unless $class =~ /\A(?:\w+::)*\w+\z/; | ||||
89 | die $EVAL_ERROR unless eval sprintf 'require %s', $class; | ||||
90 | my $twist = $class->can('_twist') | ||||
91 | or die sprintf | ||||
92 | 'Can\'t locate object method "_twist" via package "%s"', | ||||
93 | $class; | ||||
94 | |||||
95 | $status = $self->$twist($message); | ||||
96 | last unless $status; | ||||
97 | } | ||||
98 | } | ||||
99 | |||||
100 | unless (defined $status) { | ||||
101 | $self->_on_failure($message, $handle); | ||||
102 | } elsif ($status) { | ||||
103 | $self->_on_success($message, $handle); | ||||
104 | } else { | ||||
105 | $self->_on_skip($message, $handle); | ||||
106 | } | ||||
107 | |||||
108 | $processed++; | ||||
109 | $self->_init(2); | ||||
110 | } elsif ($handle) { | ||||
111 | $self->_on_garbage($handle); | ||||
112 | } else { | ||||
113 | 229 | 126µs | last; | ||
114 | } | ||||
115 | |||||
116 | last if $self->{finish}; | ||||
117 | } | ||||
118 | |||||
119 | 229 | 426µs | return $processed; | ||
120 | } | ||||
121 | |||||
122 | sub _init {1} | ||||
123 | |||||
124 | sub _on_failure { | ||||
125 | my $self = shift; | ||||
126 | my $message = shift; | ||||
127 | my $handle = shift; | ||||
128 | |||||
129 | $self->{distaff}->quarantine($handle); | ||||
130 | } | ||||
131 | |||||
132 | sub _on_success { | ||||
133 | my $self = shift; | ||||
134 | my $message = shift; | ||||
135 | my $handle = shift; | ||||
136 | |||||
137 | $self->{distaff}->remove($handle); | ||||
138 | } | ||||
139 | |||||
140 | sub _on_skip { | ||||
141 | my $self = shift; | ||||
142 | my $message = shift; | ||||
143 | my $handle = shift; | ||||
144 | |||||
145 | $handle->close if ref $handle; | ||||
146 | } | ||||
147 | |||||
148 | sub _on_garbage { | ||||
149 | my $self = shift; | ||||
150 | my $handle = shift; | ||||
151 | |||||
152 | $self->{distaff}->quarantine($handle); | ||||
153 | } | ||||
154 | |||||
155 | sub success { | ||||
156 | my $self = shift; | ||||
157 | |||||
158 | my $stash = $self->{stash} || []; | ||||
159 | return ( | ||||
160 | grep { $_->[1] eq 'intern' or $_->[1] eq 'auth' or $_->[1] eq 'user' } | ||||
161 | @$stash | ||||
162 | ) ? 0 : 1; | ||||
163 | } | ||||
164 | |||||
165 | sub _twist {0} | ||||
166 | |||||
167 | 1; | ||||
168 | __END__ | ||||
# spent 300ns within Sympa::Spindle::CORE:sort which was called:
# once (300ns+0s) by Sympa::Spindle::new at line 48 |