Skip to content
Browse files

logging frequency option

git-svn-id: file:///home/svn/humanoids/src/common/lib/ach@5056 4f504ea5-f356-0410-adec-f1b3679f3bb7
  • Loading branch information...
1 parent f514c58 commit 7669115fbfdbbf8554c09e0338999ba23d3ecc3c @ndantam ndantam committed Oct 28, 2010
Showing with 38 additions and 6 deletions.
  1. +1 −1 Makefile
  2. +5 −3 achlog
  3. +5 −0 achpipe
  4. +27 −2 achpipe.c
View
2 Makefile
@@ -1,6 +1,6 @@
PROJECT := ach
-VERSION := 0.20100429
+VERSION := 0.20101028
SHAREDLIBS := ach
View
8 achlog
@@ -52,17 +52,19 @@ def parse():
action="count", dest="verbose" )
p.add_option("-d", "--directory",
dest="directory")
+ p.add_option("-f", "--frequency",
+ dest="frequency", type="float", default=0)
(options, args) = p.parse_args()
return (options, args)
-def start_children( channels, verbose ):
+def start_children( channels, verbose, frequency ):
timestring = strftime("%Y%m%dT%H%M%S")
def start_child(channel):
filename = channel + "." + timestring + ".achlog"
if (verbose):
print "Logging `" + channel + "' to " + filename
fd = open( filename, 'a' )
- child = Popen(["achpipe", "-s", channel], stdout=fd)
+ child = Popen(["achpipe", "-s", channel, "-f", str(frequency)], stdout=fd)
fd.close()
return child
@@ -110,7 +112,7 @@ def main():
install_signals( options.verbose )
## Start
- children = start_children( args, options.verbose )
+ children = start_children( args, options.verbose, options.frequency )
## Wait
wait_for_signal( options.verbose )
View
5 achpipe
@@ -168,6 +168,8 @@ def parse():
p.add_option("-H", "--host", dest="host")
p.add_option("-P", "--port", dest="port",
type="int", default=8075)
+ p.add_option("-f", "--frequency",
+ dest="frequency", type="float", default=0)
(options, args) = p.parse_args()
return options
@@ -193,6 +195,9 @@ def make_args(opts):
args.append("--subscribe")
args.append(opts.sync_channel)
args.append("--synchronous")
+ if opts.frequency:
+ args.append("--frequency")
+ args.append(str(opts.frequency))
return args
View
29 achpipe.c
@@ -103,8 +103,10 @@
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
+#include <amino.h>
#include "ach.h"
+
/* FIXME: It seems that the kernel buffers very small messages. This
* is really bad, because we want the data fast. Should come up with
* some way to force TCP to just send it.
@@ -141,6 +143,8 @@ int opt_verbosity = 0;
int opt_last = 0;
/// CLI option: synchronous mode
int opt_sync = 0;
+/// CLI option: frequency
+double opt_freq = 0;
/*
/// CLI option: read option headers
int opt_read_headers = 0;
@@ -213,6 +217,13 @@ static struct argp_option options[] = {
.doc = "say more stuff"
},
{
+ .name = "frequency",
+ .key = 'f',
+ .arg = "hertz",
+ .flags = 0,
+ .doc = "Frequency to send data on subscribe"
+ },
+ {
.name = NULL,
.key = 0,
.arg = NULL,
@@ -397,6 +408,7 @@ void publish( int fd, char *chan_name ) {
while( ! sig_received ) {
// get size
+ verbprintf( 2, "Reading size\n", r );
r = ach_stream_read_msg_size( fd, &cnt );
verbprintf( 2, "Read %d bytes\n", r );
if( r <= 0 ) break;
@@ -452,6 +464,9 @@ void subscribe(int fd, char *chan_name) {
char cmd[5] = {0};
size_t frame_size = 0;
+ struct timespec period = aa_tm_sec2timespec( aa_feq(opt_freq, 0.0, 0) ? 0 :
+ (1/opt_freq) );
+ int is_freq = !aa_feq(opt_freq,0,0);
// read loop
while( ! sig_received ) {
@@ -478,7 +493,7 @@ void subscribe(int fd, char *chan_name) {
}
} else {
// push the data
- r = opt_last ?
+ r = (opt_last || is_freq) ?
ach_wait_last(&chan, buf, max, &frame_size, NULL ) :
ach_wait_next(&chan, buf, max, &frame_size, NULL ) ;
}
@@ -513,6 +528,11 @@ void subscribe(int fd, char *chan_name) {
verbprintf( 2, "Printed output\n");
}
t0 = 0;
+ // maybe sleep
+ if( is_freq ) {
+ assert( !opt_sync );
+ aa_tm_relsleep(period);
+ }
}
free(buf);
ach_close( &chan );
@@ -574,6 +594,9 @@ int main( int argc, char **argv ) {
"must specify publish or subscribe mode\n" );
hard_assert( opt_pub || opt_sub ,
"must specify publish xor subscribe mode\n" ) ;
+ hard_assert( aa_feq(opt_freq,0,0) ? 1 : (!opt_sync && opt_sub),
+ "frequency only valid on async subscribe mode\n" );
+ hard_assert( opt_freq >= 0, "frequency must be positive\n" );
// maybe print
verbprintf( 1, "Channel: %s\n", opt_chan_name );
@@ -582,7 +605,6 @@ int main( int argc, char **argv ) {
// install sighandler
sighandler_install();
-
// run
if (opt_pub) {
publish( STDIN_FILENO, opt_chan_name );
@@ -613,6 +635,9 @@ static int parse_opt( int key, char *arg, struct argp_state *state) {
case 'c':
opt_sync = 1;
break;
+ case 'f':
+ opt_freq = atof(arg);
+ break;
/*
case 'R':
opt_read_headers = 1;

0 comments on commit 7669115

Please sign in to comment.
Something went wrong with that request. Please try again.