aboutsummaryrefslogtreecommitdiff
path: root/broccoli/src/midbro.c
diff options
context:
space:
mode:
authorRobert Gustafsson <robg@student.chalmers.se>2017-10-14 14:48:28 +0200
committerRobert Gustafsson <robg@student.chalmers.se>2017-10-14 14:48:28 +0200
commitd1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae (patch)
tree251bd72f01982a13f503bca230e1622c2787c74d /broccoli/src/midbro.c
parentd12ef314dfcd9bafd370669fc47e5ee443767b28 (diff)
downloadmidbro-d1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae.tar.gz
midbro-d1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae.tar.bz2
Add statistics after SIGINT
Diffstat (limited to 'broccoli/src/midbro.c')
-rw-r--r--broccoli/src/midbro.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/broccoli/src/midbro.c b/broccoli/src/midbro.c
index 6c83207..e2f9644 100644
--- a/broccoli/src/midbro.c
+++ b/broccoli/src/midbro.c
@@ -1,5 +1,6 @@
#include <pthread.h>
#include <unistd.h>
+#include <signal.h>
#include "fifoqueue.h"
#include "broevent.h"
#include "midbro.h"
@@ -8,8 +9,25 @@
#endif
Fifo_q * queue;
+pthread_t event_listener;
+sigset_t signal_set;
void
+sigint_handler(int signal)
+{
+ printf("\nStatistics:\n"
+ "Total values received: %d\n"
+ "Total values dropped: %d\n"
+ "Total values released: %d\n"
+ "Maximum buffer utilization: %d\n"
+ "Buffer fixed size: %d\n"
+ "Buffer size upon termination: %d\n",
+ queue->valuesReceived, queue->droppedValues,
+ queue->valuesReleased, queue->largestBufferSize,
+ queue->maxSize, queue->currentSize);
+ exit(0);
+}
+ void
request_n_values(int number, int arrayOfValues[])
{
int i;
@@ -37,12 +55,20 @@ request_value()
start_data_capture()
{
int res;
- queue = init_queue(500000); /* Initiate queue with fixed size */
- pthread_t event_listener;
+ queue = init_queue(500); /* Initiate queue with fixed size */
/* Create producer thread that listen for bro events */
+ sigemptyset(&signal_set);
+ sigaddset(&signal_set, SIGINT);
+ res = pthread_sigmask(SIG_BLOCK, &signal_set, NULL);
+ if(res != 0)
+ perror("SIGINT block");
res = pthread_create(&event_listener, NULL, bro_event_listener, queue);
if(res){
perror("Unable to create thread");
exit(-1);
}
+ res = pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
+ if(res != 0)
+ perror("SIGINT unblock");
+ signal(SIGINT, sigint_handler);
}