summaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2015-10-26 14:57:00 +0900
committerLutz Helwing <lutz_helwing@mentor.com>2015-11-24 09:48:42 +0100
commitd73717a4f6b243d40388bb1d3bb9db7421d7b9b0 (patch)
tree091f25b5f38257f611733e4757b762a036b12d83 /src/daemon
parent5574d46a4083d783a915688e0e05593b9558497b (diff)
downloadDLT-daemon-d73717a4f6b243d40388bb1d3bb9db7421d7b9b0.tar.gz
DltLogstorage: Logstorage Cache
When using DltLogstorage on internal storage device, it is needed to reduce writing to internal storage device as much as possible. This patch introduces sync strategies to Logstorage to provide that functionality. The ON_MSG strategy is the default sync strategy that flushes every written log message to the storage device (fflush). The ON_DAEMON_EXIT strategy only flushes data to disk when the daemon exits. The strategy can be defined per filter in the dlt_logstorage.conf configuration file by adding SyncBehavior=<Strategy> to a configuration. Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/CMakeLists.txt2
-rw-r--r--src/daemon/dlt-daemon.c29
-rw-r--r--src/daemon/dlt-daemon.h1
-rw-r--r--src/daemon/dlt.conf3
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c32
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.h19
6 files changed, 79 insertions, 7 deletions
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index f665a4d..128dbe8 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -20,7 +20,7 @@ if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
message( STATUS "Added ${systemd_SRCS} to dlt-daemon")
endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
-set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_connection.c dlt_daemon_event_handler.c dlt_daemon_socket.c dlt_daemon_unix_socket.c dlt_daemon_serial.c dlt_daemon_client.c dlt_daemon_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_config_file_parser.c)
+set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_connection.c dlt_daemon_event_handler.c dlt_daemon_socket.c dlt_daemon_unix_socket.c dlt_daemon_serial.c dlt_daemon_client.c dlt_daemon_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_config_file_parser.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage_behavior.c)
add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
target_link_libraries(dlt-daemon rt ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 61aca56..02e42ec 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -84,6 +84,8 @@ static int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_loc
static uint32_t watchdog_trigger_interval; // watchdog trigger interval in [s]
#endif
+/* used in main event loop and signal handler */
+int g_exit = 0;
/**
* Print usage information of tool.
@@ -238,6 +240,9 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineLogstorageDelimiter = '_';
daemon_local->flags.offlineLogstorageMaxCounter = UINT_MAX;
daemon_local->flags.offlineLogstorageMaxCounterIdx = 0;
+ daemon_local->flags.offlineLogstorageCacheSize = 30000; /* 30MB */
+ dlt_daemon_logstorage_set_logstorage_cache_size(
+ daemon_local->flags.offlineLogstorageCacheSize);
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
sizeof(daemon_local->flags.ctrlSockPath) - 1);
@@ -459,6 +464,13 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineLogstorageMaxCounter = atoi(value);
daemon_local->flags.offlineLogstorageMaxCounterIdx = strlen(value);
}
+ else if(strcmp(token, "OfflineLogstorageCacheSize") == 0)
+ {
+ daemon_local->flags.offlineLogstorageCacheSize =
+ (unsigned int)atoi(value);
+ dlt_daemon_logstorage_set_logstorage_cache_size(
+ daemon_local->flags.offlineLogstorageCacheSize);
+ }
else if(strcmp(token,"ControlSocketPath") == 0)
{
memset(
@@ -499,7 +511,7 @@ int main(int argc, char* argv[])
char version[DLT_DAEMON_TEXTBUFSIZE];
DltDaemonLocal daemon_local;
DltDaemon daemon;
- int back;
+ int back = 0;
/* Command line option handling */
if ((back = option_handling(&daemon_local,argc,argv))<0)
@@ -637,7 +649,7 @@ int main(int argc, char* argv[])
dlt_daemon_log_internal(&daemon, &daemon_local, "Daemon launched. Starting to output traces...", daemon_local.flags.vflag);
/* Even handling loop. */
- while (back >= 0)
+ while ((back >= 0) && (g_exit >= 0))
{
back = dlt_daemon_handle_event(&daemon_local.pEvent,
&daemon,
@@ -647,7 +659,13 @@ int main(int argc, char* argv[])
dlt_daemon_log_internal(&daemon, &daemon_local, "Exiting Daemon...", daemon_local.flags.vflag);
- dlt_daemon_local_cleanup(&daemon, &daemon_local, daemon_local.flags.vflag);
+ /* disconnect all logstorage devices */
+ dlt_daemon_logstorage_cleanup(&daemon,
+ &daemon_local,
+ daemon_local.flags.vflag);
+
+
+// dlt_daemon_local_cleanup(&daemon, &daemon_local, daemon_local.flags.vflag);
dlt_log(LOG_NOTICE, "Leaving DLT daemon\n");
@@ -1167,9 +1185,8 @@ void dlt_daemon_signal_handler(int sig)
tmp[PATH_MAX] = 0;
unlink(tmp);
-
- /* Terminate program */
- exit(0);
+ /* stop event loop */
+ g_exit = -1;
break;
}
default:
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 503a98f..02a55b3 100644
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -118,6 +118,7 @@ typedef struct
char offlineLogstorageDelimiter; /**< (char) Append delimeter character in offline logstorage filename */
unsigned int offlineLogstorageMaxCounter; /**< (int) Maximum offline logstorage file counter index until wraparound */
unsigned int offlineLogstorageMaxCounterIdx; /**< (int) String len of offlineLogstorageMaxCounter*/
+ unsigned int offlineLogstorageCacheSize; /**< Max cache size offline logstorage cache */
char userPipesDir[NAME_MAX + 1]; /**< (String: Directory) directory where dltpipes reside (Default: /tmp/dltpipes) */
char daemonFifoName[NAME_MAX + 1]; /**< (String: Filename) name of local fifo (Default: /tmp/dlt) */
unsigned int port; /**< port number */
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index 72377e5..5deec60 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -145,3 +145,6 @@ ControlSocketPath = /tmp/dlt-ctrl.sock
# Wrap around value for log file count in file name (Default: UINT_MAX)
# OfflineLogstorageMaxCounter = 999
+
+# Maximal used memory for Logstorage Cache in KB (Default: 30000 KB)
+# OfflineLogstorageCacheSize = 30000 \ No newline at end of file
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index bc8817c..66f9ec8 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -565,3 +565,35 @@ int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path,
return ret;
}
+
+void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size)
+{
+ /* store given [KB] size in [Bytes] */
+ g_logstorage_cache_max = size * 1000;
+}
+
+int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose)
+{
+ int i = 0;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if (daemon == NULL || daemon_local == NULL)
+ {
+ return -1;
+ }
+
+ for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
+ {
+ /* call disconnect on all currently connected devices */
+ if (daemon->storage_handle[i].connection_type ==
+ DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
+ {
+ dlt_logstorage_device_disconnected(&daemon->storage_handle[i]);
+ }
+ }
+
+ return 0;
+}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.h b/src/daemon/dlt_daemon_offline_logstorage.h
index 621bd59..cb7698a 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.h
+++ b/src/daemon/dlt_daemon_offline_logstorage.h
@@ -126,4 +126,23 @@ void dlt_daemon_logstorage_write(DltDaemon *daemon, DltDaemonFlags user_config,
* @param verbose If set to true verbose information is printed out
*/
int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose);
+
+/**
+ * Set max size of logstorage cache. Stored internally in bytes
+ *
+ * @param size Size of logstorage cache [in KB]
+ */
+void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size);
+
+/**
+ * Cleanup dlt logstorage
+ *
+ * @param daemon Pointer to Dlt Daemon structure
+ * @param daemon_local Pointer to Dlt Daemon Local structure
+ * @param verbose If set to true verbose information is printed out
+ */
+int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
+ DltDaemonLocal *daemon_local,
+ int verbose);
+
#endif /* DLT_DAEMON_OFFLINE_LOGSTORAGE_H */