Hi,

the attached patch implements a statistics report after a stream transfer
in client mode, eg

% obexapp -a phone -C ftrn -f -n put image.jpg
146753 bytes streamed in 13 seconds (11288 bytes/sec)

regards,
iain
--- client.c.orig       2010-01-08 18:31:22.000000000 +0000
+++ client.c    2010-10-19 18:14:38.000000000 +0100
@@ -50,6 +50,7 @@
 #include "client.h"
 #include "event.h"
 #include "log.h"
+#include "stream.h"
 #include "util.h"
 
 /*
@@ -769,6 +770,8 @@ obexapp_client_request_put(obex_t *handl
                        log_err("%s(): Could not add HDR_BODY", __func__);
                        goto done;
                }
+
+               obexapp_stream_stats_reset(context);
                break;
 
        case OBEXAPP_PUT_CREATE_EMPTY:
@@ -803,8 +806,12 @@ obexapp_client_request_put(obex_t *handl
 
        if (context->rsp != OBEX_RSP_SUCCESS)
                error = -1;
-       else
+       else {
                error = 0;
+               if (opcode == OBEXAPP_PUT)
+                       obexapp_stream_stats_print(context);
+       }
+
 done:
        if (object != NULL) {
                OBEX_ObjectDelete(handle, object);
@@ -909,6 +916,7 @@ obexapp_client_request_get(obex_t *handl
                        goto done;
                }
 
+               obexapp_stream_stats_reset(context);
                OBEX_ObjectReadStream(handle, object, NULL);
                break;
 
@@ -990,6 +998,8 @@ obexapp_client_request_get(obex_t *handl
                                        "%s (%d)", __func__,
                                        context->temp, local, strerror(errno),
                                        errno);
+                       else
+                               obexapp_stream_stats_print(context);
                        break;
                }
        } else
--- obexapp.h.orig      2009-08-20 22:57:18.000000000 +0100
+++ obexapp.h   2010-10-19 17:55:21.000000000 +0100
@@ -110,6 +110,8 @@ struct context
        /* stream file descriptor and buffer */
        int                      sfd;
        uint8_t                 *sbuffer;
+       size_t                   stotal;
+       time_t                   stime;
 
        int                      mtu;            /* OBEX MTU */
 
--- stream.c.orig       2009-04-10 00:16:31.000000000 +0100
+++ stream.c    2010-10-19 18:09:02.000000000 +0100
@@ -79,6 +79,8 @@ obexapp_stream_write(obex_t *handle, obe
 
                close(context->sfd);
                context->sfd = -1;
+       } else {
+               context->stotal += length;
        }
 } /* obexapp_stream_write */
 
@@ -224,6 +226,26 @@ obexapp_stream_read(obex_t *handle, obex
                return;
        }
 
+       context->stotal += length;
        log_debug("%s(): Wrote %d bytes of stream data", __func__, length);
 } /* obexapp_stream_read */
 
+void
+obexapp_stream_stats_reset(context_t *context)
+{
+       context->stotal = 0;
+       context->stime = time(NULL);
+}
+
+void
+obexapp_stream_stats_print(context_t *context)
+{
+       int tm;
+
+       tm = (int)(time(NULL) - context->stime);
+       printf("%zu bytes streamed in %d second%s",
+           context->stotal, tm, (tm == 1 ? "" : "s"));
+       if (tm > 1)
+               printf(" (%zu bytes/sec)", context->stotal / tm);
+       printf("\n");
+}
--- stream.h.orig       2007-02-22 20:35:01.000000000 +0000
+++ stream.h    2010-10-19 18:01:45.000000000 +0100
@@ -35,5 +35,8 @@
 obexapp_event_handler_t        obexapp_stream_write;
 obexapp_event_handler_t        obexapp_stream_read;
 
+void obexapp_stream_stats_reset(context_t *);
+void obexapp_stream_stats_print(context_t *);
+
 #endif /* _STREAM_H_ */
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bluetooth
To unsubscribe, send any mail to "[email protected]"

Reply via email to