[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30654 - in gnunet: contrib src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30654 - in gnunet: contrib src/util |
Date: |
Sun, 10 Nov 2013 00:12:23 +0100 |
Author: tg
Date: 2013-11-10 00:12:23 +0100 (Sun, 10 Nov 2013)
New Revision: 30654
Added:
gnunet/contrib/logread-ipc-sdedit.pl
gnunet/contrib/logread-ipc.sh
Modified:
gnunet/contrib/logread.pl
gnunet/src/util/client.c
Log:
logread: ipc message monitoring
Added: gnunet/contrib/logread-ipc-sdedit.pl
===================================================================
--- gnunet/contrib/logread-ipc-sdedit.pl (rev 0)
+++ gnunet/contrib/logread-ipc-sdedit.pl 2013-11-09 23:12:23 UTC (rev
30654)
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+
+# 1. Start sdedit and enable 'RT diagram server' in 'Global preferences'.
+#
+# 2. Start this tool (see defaults below):
+# gnunet-logread-ipc-sdedit -n buffer-name -i /path/to/ipc.sock -h
<sdedit-host> -p <sdedit-port>
+#
+# 3. Start a gnunet-logread instance for each component with the -n
<component_name> option
+
+use strict;
+use warnings;
+
+use Getopt::Std;
+use IO::Socket::INET;
+use POSIX qw(mkfifo);
+
+my %opts;
+getopts ('i:n:h:p:', \%opts);
+
+my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
+my $name = $opts{n} || 'gnunet';
+my $host = $opts{h} || 'localhost';
+my $port = $opts{p} || 16001;
+my %svcs = map { $_ => 1 } @ARGV;
+
+my $sdedit = IO::Socket::INET->new(PeerAddr => $host,
+ PeerPort => $port,
+ Proto => 'tcp')
+ or die "Cannot connect to $host:$port: $!\n";
+
+print $sdedit "$name\n";
+print $sdedit "_t:time[e]\n";
+print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV;
+print $sdedit "_e:ext[e]\n";
+print $sdedit "\n";
+
+mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc;
+open IPC, '<', $ipc or die "$ipc: $!\n";
+while (<IPC>)
+{
+ print;
+ my ($time, $from, $to, $msg, $svc);
+ if (my ($time, $from, $to, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
+ (\S+)\s+ -> \s+(\S+)\s+ (\S+\s+ \(\d+\))/x)
+ {
+ $from = '_e' unless exists $svcs{$from};
+ $to = '_e' unless exists $svcs{$to};
+ print $sdedit "*0 _t\n$time\n*0\n", "$from:$to.$msg\n"
+ }
+ elsif (($time, $svc, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
+ (\S+)\s+(.+)/x)
+ {
+ print $sdedit "*0 _t\n$time\n*0\n", "*0 $svc\n$msg\n*0\n"
+ }
+}
+
+close IPC;
Property changes on: gnunet/contrib/logread-ipc-sdedit.pl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: gnunet/contrib/logread-ipc.sh
===================================================================
--- gnunet/contrib/logread-ipc.sh (rev 0)
+++ gnunet/contrib/logread-ipc.sh 2013-11-09 23:12:23 UTC (rev 30654)
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+ipc=${1:-/tmp/gnunet-logread-ipc.sock}
+test -e "$ipc" || mkfifo "$ipc"
+cat "$ipc"
Property changes on: gnunet/contrib/logread-ipc.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Modified: gnunet/contrib/logread.pl
===================================================================
--- gnunet/contrib/logread.pl 2013-11-09 23:12:19 UTC (rev 30653)
+++ gnunet/contrib/logread.pl 2013-11-09 23:12:23 UTC (rev 30654)
@@ -3,13 +3,25 @@
# Usage:
# gnunet-service |& gnunet-logread
# gnunet-logread service.log
+#
+# Options:
+# -n <component_name> Name of this component to use for IPC
logging.
+# -i </path/to/ipc.sock> Path to IPC logging socket.
+# Passing on log messages to IPC socket:
+# -L <LOGLEVEL> Minimum level of messages to pass on.
+# Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
+# -m <regex> Only pass on messages matching a regular
expression.
use strict;
use warnings;
+use Getopt::Std;
use Term::ANSIColor qw(:constants :pushpop);
$Term::ANSIColor::AUTOLOCAL = 1;
+my (%opts, $name, $ipc, $msg_level, $msg_regex);
+getopts ('n:i:L:m:', \%opts);
+
# Message type numbers to names
my %msgtypes;
my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
@@ -28,8 +40,50 @@
warn "$filename: $!, try setting \$GNUNET_PREFIX";
}
+my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
+if (exists $opts{n})
+{
+ $name = $opts{n};
+ $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
+ $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
+ $msg_regex = $opts{m};
+ print STDERR "RE: /$msg_regex/\n";
+ open IPC, '>', $ipc or die "$ipc: $!\n";
+}
+
while (<>)
{
+ if (fileno IPC) {
+ my ($time, $type, $size, $from, $to, $level, $msg);
+ if (($time, $type, $size, $from, $to) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b
+ (?: Received | Transmitting )\ message \b.*?\b
+ type \s+ (\d+) \b.*?\b
+ size \s+ (\d+) \b.*?\b
+ (?: from \s+ (\S+)
+ | to \s+ (\S+) ) /x)
+ {
+ $from ||= $name;
+ $to ||= $name;
+ my ($time, $type, $size, $from, $to) = ($1, $2, $3,
+ $4 || $name, $5 || $name);
+ my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
+ my $ofh = select IPC;
+ print IPC "$time\t$from -> $to\t$msg ($size)\n";
+ $|++;
+ select $ofh;
+ }
+ if (($time, $level, $msg) =
+ /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)
+ \s+\S+\s+(\S+)\s+(.+)/x
+ and (exists $levels{$level}
+ && $levels{$level} <= $msg_level
+ && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
+ {
+ print IPC "$time\t$name\t$level: $msg\n";
+ }
+ }
+
# Timestamp (e.g. Nov 01 19:36:11-384136)
s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
@@ -50,3 +104,5 @@
print;
}
+
+fileno IPC and close IPC;
Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c 2013-11-09 23:12:19 UTC (rev 30653)
+++ gnunet/src/util/client.c 2013-11-09 23:12:23 UTC (rev 30654)
@@ -573,8 +573,8 @@
char mbuf[msize];
struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n",
- ntohs (cmsg->type), msize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u from
%s service.\n",
+ ntohs (cmsg->type), msize, client->service_name);
client->receive_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (GNUNET_YES == client->msg_complete);
GNUNET_assert (client->received_pos >= msize);
@@ -1148,6 +1148,14 @@
GNUNET_assert (size >= th->size);
ret = th->notify (th->notify_cls, size, buf);
GNUNET_free (th);
+ if (sizeof (struct GNUNET_MessageHeader) <= ret)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting message of type %u and size %u to %s service.\n",
+ ntohs (((struct GNUNET_MessageHeader *) buf)->type),
+ ntohs (((struct GNUNET_MessageHeader *) buf)->size),
+ client->service_name);
+ }
return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30654 - in gnunet: contrib src/util,
gnunet <=