Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2019-04-05 06:30:45 -0400
committerHenrik Rentz-Reichert2019-04-26 13:07:27 -0400
commit5304c038dc6ad38868064cd7fa84d5bd89dcc931 (patch)
treee721e75b2362d802937dd302168181fbeabea29a /runtime/org.eclipse.etrice.runtime.c/src/common/messaging
parent636465baf602e2bc9ea0b6ae89c2bb255306eaaf (diff)
downloadorg.eclipse.etrice-5304c038dc6ad38868064cd7fa84d5bd89dcc931.tar.gz
org.eclipse.etrice-5304c038dc6ad38868064cd7fa84d5bd89dcc931.tar.xz
org.eclipse.etrice-5304c038dc6ad38868064cd7fa84d5bd89dcc931.zip
Bug 546142 - etRuntime should give access to message service statistics
* equipped message service with a name * runtime allows access to message service statistics * runtime allows to reset all message service statistics Change-Id: I807dfd47883f53f5123c92734056d2cc5c346172
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/messaging')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c30
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h28
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c64
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h39
4 files changed, 146 insertions, 15 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
index 59dcb5ed4..d8cff4026 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.c
@@ -18,8 +18,8 @@ void etMessageQueue_init(etMessageQueue* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "init")
self->first = NULL;
self->last = NULL;
- self->highWaterMark = 0;
- self->lowWaterMark = 0;
+ self->statistics.highWaterMark = 0;
+ self->statistics.lowWaterMark = 0;
self->size = 0;
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -39,8 +39,8 @@ void etMessageQueue_push(etMessageQueue* self, etMessage* msg){
}
msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/
- if (++self->size > self->highWaterMark)
- self->highWaterMark++;
+ if (++self->size > self->statistics.highWaterMark)
+ self->statistics.highWaterMark++;
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -65,8 +65,8 @@ etMessage* etMessageQueue_pop(etMessageQueue* self){
pop_msg->next=NULL;
self->size--;
- if (self->size < self->lowWaterMark)
- self->lowWaterMark--;
+ if (self->size < self->statistics.lowWaterMark)
+ self->statistics.lowWaterMark--;
ET_MSC_LOGGER_SYNC_EXIT
return pop_msg;
@@ -96,20 +96,32 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self){
return self->last != NULL;
}
+const etQueueStatistics* etMessageQueue_getStatistics(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark")
+ ET_MSC_LOGGER_SYNC_EXIT
+ return &self->statistics;
+}
+
etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self) {
ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getHighWaterMark")
ET_MSC_LOGGER_SYNC_EXIT
- return self->highWaterMark;
+ return self->statistics.highWaterMark;
+}
+
+void etMessageQueue_resetHighWaterMark(etMessageQueue* self) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetHighWaterMark")
+ self->statistics.highWaterMark = 0;
+ ET_MSC_LOGGER_SYNC_EXIT
}
etInt16 etMessageQueue_getLowWaterMark(etMessageQueue* self) {
ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "getLowWaterMark")
ET_MSC_LOGGER_SYNC_EXIT
- return self->lowWaterMark;
+ return self->statistics.lowWaterMark;
}
void etMessageQueue_resetLowWaterMark(etMessageQueue* self) {
ET_MSC_LOGGER_SYNC_ENTRY("etMessageQueue", "resetLowWaterMark")
- self->lowWaterMark = self->size;
+ self->statistics.lowWaterMark = self->size;
ET_MSC_LOGGER_SYNC_EXIT
}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
index 3765f39d3..32e19023e 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageQueue.h
@@ -25,16 +25,24 @@
#include <stddef.h>
/**
+ * a data structure for the queue statistics
+ */
+typedef struct etQueueStatistics {
+ etInt16 highWaterMark; /**< high water mark */
+ etInt16 lowWaterMark; /**< low water mark */
+}
+etQueueStatistics;
+
+/**
* the message queue data structure
*/
typedef struct etMessageQueue {
etMessage* first; /**< the head of the list */
etMessage* last; /**< the tail of the list */
- etInt16 highWaterMark; /**< high water mark for statistical purposes */
- etInt16 lowWaterMark; /**< low water mark for statistical purposes */
etInt16 size; /**< the size of the list */
-
-} etMessageQueue;
+ etQueueStatistics statistics; /**< high water mark for statistical purposes */
+}
+etMessageQueue;
/**
* initializes the queue data fields ("constructor")
@@ -88,6 +96,12 @@ etBool etMessageQueue_isNotEmpty(etMessageQueue* self);
*/
etInt16 etMessageQueue_getSize(etMessageQueue* self);
/**
+ * returns the statistics of the queue
+ * \param self the this pointer
+ * \return the statistics of the queue (immutable)
+ */
+const etQueueStatistics* etMessageQueue_getStatistics(etMessageQueue* self);
+/**
* returns the high water mark of the message queue
*
* \param self the this pointer
@@ -95,6 +109,12 @@ etInt16 etMessageQueue_getSize(etMessageQueue* self);
*/
etInt16 etMessageQueue_getHighWaterMark(etMessageQueue* self);
/**
+ * resets the high water mark of the message queue to 0
+ *
+ * \param self the this pointer
+ */
+void etMessageQueue_resetHighWaterMark(etMessageQueue* self);
+/**
* returns the low water mark of the message queue
*
* \param self the this pointer
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
index 98940d81d..71e3df127 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
@@ -17,6 +17,8 @@
#include "etSystemProtocol.h"
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
+#include "runtime/etRuntime.h"
+#include "helpers/etTimeHelpers.h"
static void etMessageService_timerCallback(void* data);
static void etMessageService_deliverAllMessages(etMessageService* self);
@@ -35,9 +37,28 @@ void etMessageService_init(
etTime interval,
etDispatcherReceiveMessage msgDispatcher,
etMessageService_execmode execmode){
+ etMessageService_initx(self, NULL, buffer, maxBlocks, blockSize, stacksize, priority, interval, msgDispatcher, execmode);
+}
+
+/*
+ * initialize message service with all needed data and initialize message queue and message pool
+ *
+ */
+void etMessageService_initx(
+ etMessageService* self,
+ const char* name,
+ etUInt8* buffer,
+ etUInt16 maxBlocks,
+ etUInt16 blockSize,
+ etStacksize stacksize,
+ etPriority priority,
+ etTime interval,
+ etDispatcherReceiveMessage msgDispatcher,
+ etMessageService_execmode execmode){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
/* copy init data to self */
+ self->name = name;
self->messageBuffer.buffer = buffer;
self->messageBuffer.maxBlocks = maxBlocks;
self->messageBuffer.blockSize = blockSize;
@@ -65,6 +86,14 @@ void etMessageService_init(
etTimer_construct(&self->timer, &interval, etMessageService_timerCallback, self);
}
+ /* init statistics */
+ self->statistics.highWaterMark = 0;
+ self->statistics.queueStatistics = &self->messageQueue.statistics;
+ self->resetStatistics = ET_FALSE;
+
+ /* register with runtime */
+ etRuntime_registerMessageService(self);
+
ET_MSC_LOGGER_SYNC_EXIT
}
@@ -96,6 +125,10 @@ void etMessageService_stop(etMessageService* self){
void etMessageService_destroy(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "destroy")
+
+ /* unregister from runtime */
+ etRuntime_unregisterMessageService(self);
+
etMutex_destruct( &(self->poolMutex) );
etMutex_destruct( &(self->queueMutex) );
etSema_destruct( &(self->executionSemaphore) );
@@ -206,16 +239,43 @@ static void etMessageService_callHighPrioFunc(etMessageService* self){
ET_MSC_LOGGER_SYNC_EXIT
}
+static etBool etMessageService_dispatchMessage(etMessageService* self, const etMessage* msg) {
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "dispatchMessages")
+ etBool success;
+ etTime startTime, endTime;
+ etTimeDiff delta;
+
+ getTimeFromTarget(&startTime);
+ success = self->msgDispatcher(msg);
+ getTimeFromTarget(&endTime);
+ delta = etTimeHelpers_delta(&endTime, &startTime);
+
+ if (delta > self->statistics.highWaterMark) {
+ self->statistics.highWaterMark = delta;
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return success;
+}
+
static void etMessageService_deliverAllMessages(etMessageService* self){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "deliverAllMessages")
{
etBool cont = ET_TRUE;
while (cont){
etMessageService_callHighPrioFunc(self);
+
+ if (self->resetStatistics) {
+ self->resetStatistics = ET_FALSE;
+
+ self->statistics.highWaterMark = 0;
+ etMessageQueue_resetHighWaterMark(&self->messageQueue);
+ etMessageQueue_resetLowWaterMark(&self->messageQueue);
+ }
+
while (etMessageQueue_isNotEmpty(&self->messageQueue) && cont){
etMessage* msg = etMessageService_popMessage(self);
- if (!self->msgDispatcher(msg))
- cont = ET_FALSE;
+ cont &= etMessageService_dispatchMessage(self, msg);
etMessageService_returnMessageBuffer(self, msg);
etMessageService_callHighPrioFunc(self);
}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
index a00e2b561..cb6ff2319 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
@@ -62,7 +62,18 @@ struct etHighPrioFunc{
etHighPrioFunc *next;
};
+/**
+ * a data structure for the performance statistics
+ */
+typedef struct etMessageServiceStatistics {
+ etTimeDiff highWaterMark; /** high water mark */
+ etQueueStatistics* queueStatistics; /** a pointer to the queue statistics */
+}
+etMessageServiceStatistics;
+
typedef struct etMessageService {
+ const char* name; /** (unique) name */
+ struct etMessageService* next; /** linked list */
etMessageQueue messageQueue; /** message queue that holds all used messages */
etMessageQueue messagePool; /** message pool that holds all free messages */
etBuffer messageBuffer; /** information about the message buffer that holds information about the actual memory position and size for the message pool */
@@ -74,12 +85,40 @@ typedef struct etMessageService {
etTimer timer; /** timer for cyclic calls */
etMessageService_execmode execmode; /** execution mode*/
etHighPrioFunc *highPrioFuncRoot;
+ etMessageServiceStatistics statistics; /** statistical data */
+ etBool resetStatistics; /** flag that tells the message service to reset all statistics values */
} etMessageService;
/**
* initialization (construction)
*
* \param self the this pointer
+ * \param name the name of the message service
+ * \param buffer the buffer for the message pool
+ * \param maxBlocks the number of (equal sized) message blocks in the buffer
+ * \param blockSize the size of each message block
+ * \param stackSize the stack size for the thread in which this service will run
+ * \param priority the thread priority
+ * \param interval the polling interval
+ * \param msgDispatcher the dispatcher method
+ * \param execmdoe the execution mode for this message service
+ */
+void etMessageService_initx(
+ etMessageService* self,
+ const char* name,
+ etUInt8* buffer,
+ etUInt16 maxBlocks,
+ etUInt16 blockSize,
+ etStacksize stacksize,
+ etPriority priority,
+ etTime interval,
+ etDispatcherReceiveMessage msgDispatcher,
+ etMessageService_execmode execmode);
+
+/**
+ * initialization (construction)
+ *
+ * \param self the this pointer
* \param buffer the buffer for the message pool
* \param maxBlocks the number of (equal sized) message blocks in the buffer
* \param blockSize the size of each message block

Back to the top