From ecca21fd40be21164d664eb7d8a52ea1fdabfde0 Mon Sep 17 00:00:00 2001 From: Sebastian Unger Date: Thu, 13 Jun 2019 13:41:12 +0200 Subject: Add user custom timestamp interface Two new macros are introduced so that users can use their customized timestamps for DLT messages: - DLT_LOG_TS(CONTEXT, LOGLEVEL, TS, ARGS ...) - DLT_LOG_ID_TS(CONTEXT, LOGLEVEL, MSGID, TS, ARGS ...) Detailed explanations can be found in dlt_for_developers.md. Also a new option is added to dlt-system to use events' timestamps from journald adapter. Signed-off-by: Sebastian Unger --- src/system/dlt-system-journal.c | 28 +++++++++++++++++++++------- src/system/dlt-system-options.c | 5 +++++ src/system/dlt-system.conf | 3 +++ src/system/dlt-system.h | 1 + 4 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/system') diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c index 5c10c50..2845406 100644 --- a/src/system/dlt-system-journal.c +++ b/src/system/dlt-system-journal.c @@ -202,6 +202,7 @@ void journal_thread(void *v_conf) sd_journal *j; char match[DLT_SYSTEM_JOURNAL_BOOT_ID_MAX_LENGTH] = "_BOOT_ID="; sd_id128_t boot_id; + uint32_t ts; char buffer_process[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, buffer_priority[DLT_SYSTEM_JOURNAL_BUFFER_SIZE] = { 0 }, @@ -345,13 +346,26 @@ void journal_thread(void *v_conf) snprintf(buffer_priority, DLT_SYSTEM_JOURNAL_BUFFER_SIZE, "prio_unknown:"); /* write log entry */ - DLT_LOG(journalContext, loglevel, - DLT_STRING(timestamp.real), - DLT_STRING(timestamp.monotonic), - DLT_STRING(buffer_process), - DLT_STRING(buffer_priority), - DLT_STRING(buffer_message) - ); + if (conf->Journal.UseOriginalTimestamp == 0) { + DLT_LOG(journalContext, loglevel, + DLT_STRING(timestamp.real), + DLT_STRING(timestamp.monotonic), + DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), + DLT_STRING(buffer_message) + ); + + } + else { + /* since we are talking about points in time, I'd prefer truncating over arithmetic rounding */ + ts = (uint32_t)(atof(timestamp.monotonic) * 10000); + DLT_LOG_TS(journalContext, loglevel, ts, + DLT_STRING(timestamp.real), + DLT_STRING(buffer_process), + DLT_STRING(buffer_priority), + DLT_STRING(buffer_message) + ); + } } else { r = sd_journal_wait(j, 1000000); diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c index 667db9c..5fa31cb 100644 --- a/src/system/dlt-system-options.c +++ b/src/system/dlt-system-options.c @@ -148,6 +148,7 @@ void init_configuration(DltSystemConfiguration *config) config->Journal.CurrentBoot = 1; config->Journal.Follow = 0; config->Journal.MapLogLevels = 1; + config->Journal.UseOriginalTimestamp = 1; /* File transfer */ config->Filetransfer.Enable = 0; @@ -289,6 +290,10 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) { config->Journal.MapLogLevels = atoi(value); } + else if (strcmp(token, "JournalUseOriginalTimestamp") == 0) + { + config->Journal.UseOriginalTimestamp = atoi(value); + } /* File transfer */ else if (strcmp(token, "FiletransferEnable") == 0) diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf index b3677f9..4010b70 100644 --- a/src/system/dlt-system.conf +++ b/src/system/dlt-system.conf @@ -74,6 +74,9 @@ JournalFollow = 0 # 7 Debug DLT_LOG_DEBUG JournalMapLogLevels = 1 +# Use the original timestamp (uptime when the event actually occured) as DLT timestamp (Default: 1) +JournalUseOriginalTimestamp = 1 + ######################################################################## # Filetransfer Manager ######################################################################## diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index ed2b50b..46738b8 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -107,6 +107,7 @@ typedef struct { int CurrentBoot; int Follow; int MapLogLevels; + int UseOriginalTimestamp; } JournalOptions; typedef struct { -- cgit v1.2.1