Skip to content

Commit dbede84

Browse files
committed
Add wall-time to debug messages
Signed-off-by: Niels Thykier <[email protected]>
1 parent 11d0e82 commit dbede84

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

apt-file

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ use File::Path;
4242
use File::Temp;
4343
use AptPkg::Config '$_config';
4444
use List::MoreUtils qw/any none uniq/;
45+
use Time::HiRes qw(gettimeofday tv_interval);
4546

4647
my ($Conf, @apt_options);
48+
my $time_baseline = [gettimeofday()];
49+
my $time_since_last = $time_baseline;
4750

4851
sub warning {
4952
my ($msg) = @_;
@@ -88,7 +91,11 @@ sub stop_with_msg {
8891
sub debug {
8992
my ($level, $msg) = @_;
9093
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);
9299
}
93100

94101
sub debug_line($) {
@@ -158,6 +165,7 @@ sub print_winners ($$) {
158165
sub start_pipe_to_cmd {
159166
my ($sub_proc_write_end, @cmd) = @_;
160167
my ($read_end, $our_write_end, $pid);
168+
my $parser_pid = $$;
161169
pipe($read_end, $our_write_end)
162170
or error("pipe failed: $!");
163171
$pid = fork()
@@ -168,7 +176,7 @@ sub start_pipe_to_cmd {
168176
or error("fdup stdout failed: $!");
169177
close($our_write_end)
170178
or error("close write end of pipe: $!");
171-
debug(1, 'starting ' . join(' ', @cmd));
179+
debug(1, "[${parser_pid}] starting " . join(' ', @cmd));
172180
exec {$cmd[0]} @cmd
173181
or error('exec ' . join(' ', @cmd) . " failed: $!");
174182
}
@@ -237,14 +245,15 @@ sub open_data_pipeline {
237245
$pid_table{$cat_pid} = {
238246
'cmd' => \@cat_cmd,
239247
};
240-
debug(1, "Starting to pass files");
248+
debug(1, 'Starting to pass files');
241249
for my $file (uniq(@{$file_list})) {
242250
debug(1, "Passing $file");
243251
printf {$to_cat} "%s\0", $file;
244252
}
245-
debug(1, "Closing input to cat");
253+
debug(1, 'Closing input to cat');
246254
close($to_cat)
247255
or error("close write end of xargs pipe: $!");
256+
debug(1, 'Input closed, reaping completed children');
248257
do {
249258
$dead_pid = waitpid(-1, 0);
250259
if ($dead_pid > 0) {
@@ -260,6 +269,7 @@ sub open_data_pipeline {
260269
}
261270
}
262271
} while ($dead_pid > 0);
272+
debug(1, 'Reaped children complete');
263273
if (my $sig = ($sub_proc_error & 0x7f)) {
264274
warn("Command ${failed_cmd} was killed by signal ${sig}");
265275
POSIX::_exit($sig);
@@ -286,6 +296,7 @@ sub do_grep($$) {
286296
my $matches = 0;
287297
my $quick_regexp = escape_parens($regexp);
288298
my $fd = open_data_pipeline($data);
299+
debug(1, "Pipeline open, waiting for input");
289300
while (<$fd>) {
290301

291302
# faster, non-capturing search first
@@ -309,6 +320,7 @@ sub do_grep($$) {
309320
if ($?) {
310321
error("A subprocess exited uncleanly (raw: $?)");
311322
}
323+
debug(1, 'Read all input');
312324
return reverse_hash($ret);
313325
}
314326

0 commit comments

Comments
 (0)