diff options
author | Robert Gustafsson <robg@student.chalmers.se> | 2017-10-14 14:48:28 +0200 |
---|---|---|
committer | Robert Gustafsson <robg@student.chalmers.se> | 2017-10-14 14:48:28 +0200 |
commit | d1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae (patch) | |
tree | 251bd72f01982a13f503bca230e1622c2787c74d /broccoli/src | |
parent | d12ef314dfcd9bafd370669fc47e5ee443767b28 (diff) | |
download | midbro-d1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae.tar.gz midbro-d1e8d44990eb9e1bb7280ccff07b0d396fdcc0ae.tar.bz2 |
Add statistics after SIGINT
Diffstat (limited to 'broccoli/src')
-rw-r--r-- | broccoli/src/fifoqueue.c | 11 | ||||
-rw-r--r-- | broccoli/src/midbro.c | 30 |
2 files changed, 39 insertions, 2 deletions
diff --git a/broccoli/src/fifoqueue.c b/broccoli/src/fifoqueue.c index 9b4b75e..6a99740 100644 --- a/broccoli/src/fifoqueue.c +++ b/broccoli/src/fifoqueue.c @@ -13,6 +13,10 @@ init_queue(int size) q->tail = NULL; q->maxSize = size; q->currentSize = 0; + q->droppedValues = 0; + q->largestBufferSize = 0; + q->valuesReceived = 0; + q->valuesReleased = 0; /*Queue empty from the beginning (block)*/ sem_init(&q->bufferEmptyBlock, 0, 0); sem_init(&q->lock, 0, 1); @@ -50,6 +54,7 @@ add_to_queue(Fifo_q * q, Sensor_t * sensor) #ifdef DLR pop_from_queue(q); #endif + q->droppedValues++; return 0; } sem_wait(&q->lock); @@ -63,6 +68,9 @@ add_to_queue(Fifo_q * q, Sensor_t * sensor) q->tail->next = new_elem; q->tail = new_elem; q->currentSize++; + q->valuesReceived++; + if(q->currentSize > q->largestBufferSize) + q->largestBufferSize = q->currentSize; sem_post(&q->lock); return 1; } @@ -93,6 +101,9 @@ pop_from_queue(Fifo_q * q) } free(head); q->currentSize--; + #ifndef DLR + q->valuesReleased++; + #endif sem_post(&q->lock); return sensor; } 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); } |