@@ -42,8 +42,11 @@ use File::Path;
42
42
use File::Temp;
43
43
use AptPkg::Config ' $_config' ;
44
44
use List::MoreUtils qw/ any none uniq/ ;
45
+ use Time::HiRes qw( gettimeofday tv_interval) ;
45
46
46
47
my ($Conf , @apt_options );
48
+ my $time_baseline = [gettimeofday()];
49
+ my $time_since_last = $time_baseline ;
47
50
48
51
sub warning {
49
52
my ($msg ) = @_ ;
@@ -88,7 +91,11 @@ sub stop_with_msg {
88
91
sub debug {
89
92
my ($level , $msg ) = @_ ;
90
93
return if not defined $Conf -> {verbose } or $level > $Conf -> {verbose };
91
- print STDERR " D: ${msg} \n " ;
94
+ my $now = [gettimeofday()];
95
+ my $diff_baseline = tv_interval($time_baseline , $now );
96
+ my $diff_last = tv_interval($time_since_last , $now );
97
+ $time_since_last = $now ;
98
+ print STDERR sprintf (" D: <%.3fs> [%.3fs] ($$ ) %s \n " , $diff_baseline , $diff_last , $msg );
92
99
}
93
100
94
101
sub debug_line ($) {
@@ -158,6 +165,7 @@ sub print_winners ($$) {
158
165
sub start_pipe_to_cmd {
159
166
my ($sub_proc_write_end , @cmd ) = @_ ;
160
167
my ($read_end , $our_write_end , $pid );
168
+ my $parser_pid = $$ ;
161
169
pipe ($read_end , $our_write_end )
162
170
or error(" pipe failed: $! " );
163
171
$pid = fork ()
@@ -168,7 +176,7 @@ sub start_pipe_to_cmd {
168
176
or error(" fdup stdout failed: $! " );
169
177
close ($our_write_end )
170
178
or error(" close write end of pipe: $! " );
171
- debug(1, ' starting ' . join (' ' , @cmd ));
179
+ debug(1, " [ ${parser_pid} ] starting " . join (' ' , @cmd ));
172
180
exec {$cmd [0]} @cmd
173
181
or error(' exec ' . join (' ' , @cmd ) . " failed: $! " );
174
182
}
@@ -237,14 +245,15 @@ sub open_data_pipeline {
237
245
$pid_table {$cat_pid } = {
238
246
' cmd' => \@cat_cmd ,
239
247
};
240
- debug(1, " Starting to pass files" );
248
+ debug(1, ' Starting to pass files' );
241
249
for my $file (uniq(@{$file_list })) {
242
250
debug(1, " Passing $file " );
243
251
printf {$to_cat } " %s \0 " , $file ;
244
252
}
245
- debug(1, " Closing input to cat" );
253
+ debug(1, ' Closing input to cat' );
246
254
close ($to_cat )
247
255
or error(" close write end of xargs pipe: $! " );
256
+ debug(1, ' Input closed, reaping completed children' );
248
257
do {
249
258
$dead_pid = waitpid (-1, 0);
250
259
if ($dead_pid > 0) {
@@ -260,6 +269,7 @@ sub open_data_pipeline {
260
269
}
261
270
}
262
271
} while ($dead_pid > 0);
272
+ debug(1, ' Reaped children complete' );
263
273
if (my $sig = ($sub_proc_error & 0x7f)) {
264
274
warn (" Command ${failed_cmd} was killed by signal ${sig} " );
265
275
POSIX::_exit($sig );
@@ -286,6 +296,7 @@ sub do_grep($$) {
286
296
my $matches = 0;
287
297
my $quick_regexp = escape_parens($regexp );
288
298
my $fd = open_data_pipeline($data );
299
+ debug(1, " Pipeline open, waiting for input" );
289
300
while (<$fd >) {
290
301
291
302
# faster, non-capturing search first
@@ -309,6 +320,7 @@ sub do_grep($$) {
309
320
if ($? ) {
310
321
error(" A subprocess exited uncleanly (raw: $? )" );
311
322
}
323
+ debug(1, ' Read all input' );
312
324
return reverse_hash($ret );
313
325
}
314
326
0 commit comments