diff options
-rw-r--r-- | broccoli/includes/types.h | 4 | ||||
-rw-r--r-- | broccoli/src/fifoqueue.c | 11 | ||||
-rw-r--r-- | broccoli/src/midbro.c | 30 |
3 files changed, 43 insertions, 2 deletions
diff --git a/broccoli/includes/types.h b/broccoli/includes/types.h index d2cf19e..b23da1a 100644 --- a/broccoli/includes/types.h +++ b/broccoli/includes/types.h @@ -25,6 +25,10 @@ struct fifo_q{ Queue_t * tail; int maxSize; int currentSize; + int droppedValues; + int largestBufferSize; + int valuesReceived; + int valuesReleased; sem_t bufferEmptyBlock; sem_t lock; }; 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); } |