if ($package && $self->can("${package}::handle")) {
no strict 'refs';
dbg("cmd: package $package") if isdbg('command');
+ if (isdbg('progress')) {
+ my $s = "CMD: '$cmd' by $call ip $self->{hostname}";
+ }
+ my $t0 = [gettimeofday];
eval { @ans = &{"${package}::handle"}($self, $args) };
return (DXDebug::shortmess($@)) if $@;
+ if (isdbg('progress')) {
+ my $msecs = _diffms($t0);
+ my $s = "CMD: '$cmd' by $call ip: $self->{hostname} ${msecs}mS";
+ dbg($s);
+ }
} else {
dbg("cmd: $package not present") if isdbg('command');
return $self->_error_out('e1');
$dxchan->send(@res);
}
}
- diffms("by $call", $line, $t0, scalar @res) if isdbg('chan');
+ diffms("by $call", $line, $t0, scalar @res) if isdbg('progress');
});
return @out;
# To allow debugging of a category (e.g. 'chan') but not onto disc (just into the ring buffer)
# do: set/debug chan nologchan
#
+# To print the current contents into the debug log: show/debug_ring
+#
+# On exit or serious error the ring buffer is printed to the current debug log
+#
+# In Progress:
+# Expose a localhost listener on port (default) 27755 to things like watchdbg so that they can carry on
+# as normal, possibly with a "remember" button to permanently capture stuff observed.
+#
+# Future:
+# This is likely to be some form of triggering or filtering controlling (some portion
+# of) ring_buffer dumping.
+#
+#
package DXDebug;
# add it
Spot::add(@spot);
+ if (isdbg('progress')) {
+ my $s = sprintf "SPOT: $spot[1] on $spot[0] \@ %s by $spot[4]\@$spot[7]", cldatetime($spot[2]);
+ $s .= " '$spot[3]'" if $spot[3];
+ $s .= " from ip $spot[14]" if $spot[14];
+ dbg($s);
+ }
+
#
# @spot at this point contains:-
# freq, spotted call, time, text, spotter, spotted cc, spotters cc, orig node
print_all_fields cltounix unpad is_callsign is_latlong
is_qra is_freq is_digits is_pctext is_pcflag insertitem deleteitem
is_prefix dd is_ipaddr $pi $d2r $r2d localdata localdata_mv
- diffms
+ diffms _diffms
);
}
# measure the time taken for something to happen; use Time::HiRes qw(gettimeofday tv_interval);
+sub _diffms
+{
+ my $ta = shift;
+ my $tb = shift || [gettimeofday];
+ my $a = int($ta->[0] * 1000) + int($ta->[1] / 1000);
+ my $b = int($tb->[0] * 1000) + int($tb->[1] / 1000);
+ return $b - $a;
+}
+
sub diffms
{
my $call = shift;
my $line = shift;
my $ta = shift;
my $no = shift;
- my $tb = shift || [gettimeofday];
-
- my $a = int($ta->[0] * 1000) + int($ta->[1] / 1000);
- my $b = int($tb->[0] * 1000) + int($tb->[1] / 1000);
- my $msecs = $b - $a;
+ my $tb = shift;
+ my $msecs = _diffms($ta, $tb);
$line =~ s|\s+$||;
my $s = "subprocess stats cmd: '$line' $call ${msecs}mS";
use vars qw(@list $fp $today $string);
+
$fp = DXLog::new('debug', 'dat', 'd');
$today = $fp->unixtoj(time());
my $nolines = 1;
for my $arg (@ARGV) {
if ($arg =~ /^-/) {
$arg =~ s/^-//o;
+ if ($arg =~ /^\s*\-+(?:[h\?]e?l?p?)/) {
+ usage();
+ exit(0);
+ }
push @list, $arg;
} elsif ($arg =~ /^\d+$/) {
$nolines = $arg;
last;
}
}
-die "usage: grepdbg [nn] [[-nnn] ..] <regexp>\n" unless $string;
+
+$string ||= '.*';
push @list, "0" unless @list;
for my $entry (@list) {
my $line;
if ($fh) {
while (<$fh>) {
- my $line = $_;
- chomp $line;
- push @prev, $line;
- shift @prev while @prev > $nolines;
- if ($line =~ m{$string}io) {
- for (@prev) {
- s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
- my ($t, $l) = split /\^/, $_, 2;
- print atime($t), ' ', $l, "\n";
- }
- @prev = ();
- }
+ process($_);
}
$fp->close();
}
}
+
+sub process
+{
+ my $line = shift;
+ chomp $line;
+ push @prev, $line;
+ shift @prev while @prev > $nolines;
+ if ($line =~ m{$string}io) {
+ for (@prev) {
+ s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
+ my ($t, $l) = split /\^/, $_, 2;
+ print atime($t), ' ', $l, "\n";
+ }
+ @prev = ();
+ }
+}
+
+sub usage
+{
+ die "usage: grepdbg [nn] [[-nnn] ..] <regexp>\n";
+}
exit(0);