summaryrefslogtreecommitdiff
path: root/src/kpi
diff options
context:
space:
mode:
authorSven Hassler <sven_hassler@mentor.com>2015-11-25 14:26:06 +0100
committerLutz Helwing <lutz_helwing@mentor.com>2015-12-16 17:20:39 +0100
commit77400754611a8e7982a7ee3c4816ee5f070c0dca (patch)
tree43ddcfdbaeffa1afaa3df6377838c771ed8a837c /src/kpi
parent96439591a8be7e3e10a5de9488dde245777318c8 (diff)
downloadDLT-daemon-77400754611a8e7982a7ee3c4816ee5f070c0dca.tar.gz
Renamed "procfs" to "kpi", added sync-messages
Diffstat (limited to 'src/kpi')
-rw-r--r--src/kpi/CMakeLists.txt29
-rw-r--r--src/kpi/dlt-kpi-common.c68
-rw-r--r--src/kpi/dlt-kpi-common.h40
-rw-r--r--src/kpi/dlt-kpi-interrupt.c153
-rw-r--r--src/kpi/dlt-kpi-interrupt.h35
-rw-r--r--src/kpi/dlt-kpi-options.c259
-rw-r--r--src/kpi/dlt-kpi-process-list.c288
-rw-r--r--src/kpi/dlt-kpi-process-list.h54
-rw-r--r--src/kpi/dlt-kpi-process.c468
-rw-r--r--src/kpi/dlt-kpi-process.h56
-rw-r--r--src/kpi/dlt-kpi.c510
-rw-r--r--src/kpi/dlt-kpi.conf18
-rw-r--r--src/kpi/dlt-kpi.h62
13 files changed, 2040 insertions, 0 deletions
diff --git a/src/kpi/CMakeLists.txt b/src/kpi/CMakeLists.txt
new file mode 100644
index 0000000..721b612
--- /dev/null
+++ b/src/kpi/CMakeLists.txt
@@ -0,0 +1,29 @@
+#######
+# @licence make begin@
+# SPDX license identifier: MPL-2.0
+#
+# Copyright (C) 2011-2015, BMW AG
+#
+# This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+#
+# This Source Code Form is subject to the terms of the
+# Mozilla Public License (MPL), v. 2.0.
+# If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# For further information see http://www.genivi.org/.
+# @licence end@
+#######
+
+set (dlt_kpi_SRCS dlt-kpi.c dlt-kpi-options.c dlt-kpi-process.c dlt-kpi-process-list.c dlt-kpi-common.c dlt-kpi-interrupt.c)
+add_executable (dlt-kpi ${dlt_kpi_SRCS})
+target_link_libraries (dlt-kpi dlt)
+set_target_properties(dlt-kpi PROPERTIES LINKER_LANGUAGE C)
+
+install(TARGETS dlt-kpi
+ RUNTIME DESTINATION bin
+ COMPONENT base)
+
+INSTALL(FILES dlt-kpi.conf
+ DESTINATION ${CONFIGURATION_FILES_DIR}
+ COMPONENT base)
diff --git a/src/kpi/dlt-kpi-common.c b/src/kpi/dlt-kpi-common.c
new file mode 100644
index 0000000..c0c7767
--- /dev/null
+++ b/src/kpi/dlt-kpi-common.c
@@ -0,0 +1,68 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-common.c
+ */
+
+#include "dlt-kpi-common.h"
+
+DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target)
+{
+ char buffer[BUFFER_SIZE];
+ int ret = dlt_kpi_read_file(filename, buffer, BUFFER_SIZE);
+ if(ret < DLT_RETURN_OK)
+ return ret;
+
+ if((*target = malloc(strlen(buffer) + 1)) == NULL)
+ {
+ fprintf(stderr, "Out of memory!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ memcpy(*target, buffer, strlen(buffer) + 1);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_read_file(char* filename, char* buffer, uint maxLength)
+{
+ if(filename == NULL || buffer == NULL)
+ {
+ fprintf(stderr, "Nullpointer parameter!\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ FILE* file = fopen(filename, "r");
+ if(file == NULL)
+ {
+ // fprintf(stderr, "Could not read file %s\n", filename);
+ return DLT_RETURN_ERROR;
+ }
+
+ int buflen = fread(buffer, 1, maxLength-1, file);
+ buffer[buflen] = '\0';
+
+ fclose(file);
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/kpi/dlt-kpi-common.h b/src/kpi/dlt-kpi-common.h
new file mode 100644
index 0000000..4e220a8
--- /dev/null
+++ b/src/kpi/dlt-kpi-common.h
@@ -0,0 +1,40 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-common.h
+ */
+
+#ifndef SRC_KPI_DLT_KPI_COMMON_H_
+#define SRC_KPI_DLT_KPI_COMMON_H_
+
+#include <dlt_types.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define BUFFER_SIZE 4096
+
+DltReturnValue dlt_kpi_read_file(char* filename, char* buffer, uint maxLength);
+DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target);
+
+#endif /* SRC_KPI_DLT_KPI_COMMON_H_ */
diff --git a/src/kpi/dlt-kpi-interrupt.c b/src/kpi/dlt-kpi-interrupt.c
new file mode 100644
index 0000000..c193b70
--- /dev/null
+++ b/src/kpi/dlt-kpi-interrupt.c
@@ -0,0 +1,153 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-interrupt.c
+ */
+
+#include "dlt-kpi-interrupt.h"
+
+DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level)
+{
+ if(ctx == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ char buffer[BUFFER_SIZE];
+ *buffer = '\0';
+
+ char file_buffer[BUFFER_SIZE];
+ char *token, *delim = " \t", *delim2 = " \t\n", *check;
+ int head_line = 1, first_row = 1, cpu_count = 0, column = 0, buffer_offset = 0;
+ DltReturnValue ret;
+
+ if((ret = dlt_kpi_read_file("/proc/interrupts", file_buffer, BUFFER_SIZE)) < DLT_RETURN_OK) return ret;
+
+ token = strtok(file_buffer, delim);
+ while(token != NULL)
+ {
+ if(head_line)
+ {
+ if(strlen(token) > 3 && token[0]=='C' && token[1]=='P' && token[2]=='U')
+ cpu_count++;
+ else if(cpu_count <= 0)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts: Could not parse CPU count\n");
+ return DLT_RETURN_ERROR;
+ }
+ else if(strcmp(token, "\n") == 0)
+ head_line = 0;
+
+ token = strtok(NULL, delim);
+ }
+ else
+ {
+ int tokenlen = strlen(token);
+ if(token[tokenlen - 1] == ':')
+ {
+ column = 0;
+
+ if(first_row)
+ first_row = 0;
+ else
+ buffer_offset += snprintf(buffer + buffer_offset, BUFFER_SIZE - buffer_offset, "\n");
+ }
+
+ if(column == 0) // IRQ number
+ {
+ buffer_offset += snprintf(buffer + buffer_offset, BUFFER_SIZE - buffer_offset, "%.*s;", tokenlen-1, token);
+ }
+ else if(column <= cpu_count)
+ {
+ long int interrupt_count = strtol(token, &check, 10);
+ if(*check != '\0')
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts: Could not parse interrupt count for CPU %d\n", column - 1);
+ return DLT_RETURN_ERROR;
+ }
+
+ buffer_offset += snprintf(buffer + buffer_offset, BUFFER_SIZE - buffer_offset, "cpu%d:%ld;", column - 1, interrupt_count);
+ }
+
+ column++;
+
+ token = strtok(NULL, delim2);
+ }
+ }
+
+ // synchronization message
+ DLT_LOG(*ctx, log_level, DLT_STRING("IRQ"), DLT_STRING("BEG"));
+
+ DltContextData ctx_data;
+ if((ret = dlt_user_log_write_start(ctx, &ctx_data, log_level)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_start() returned error\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_string(&ctx_data, "IRQ")) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_string() returned error\n");
+ return ret;
+ }
+
+ token = strtok(buffer, "\n");
+ while(token != NULL)
+ {
+ if(dlt_user_log_write_string(&ctx_data, token) < DLT_RETURN_OK)
+ {
+ /* message buffer full, start new one */
+ if((ret = dlt_user_log_write_finish(&ctx_data)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_finish() returned error\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_start(ctx, &ctx_data, log_level)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_start() returned error\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_string(&ctx_data, "IRQ")) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_string() returned error\n");
+ return ret;
+ }
+ }
+ else
+ token = strtok(NULL, "\n");
+ }
+
+ if((ret = dlt_user_log_write_finish(&ctx_data)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_interrupts(): dlt_user_log_write_finish() returned error\n");
+ return ret;
+ }
+
+ // synchronization message
+ DLT_LOG(*ctx, log_level, DLT_STRING("IRQ"), DLT_STRING("END"));
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/kpi/dlt-kpi-interrupt.h b/src/kpi/dlt-kpi-interrupt.h
new file mode 100644
index 0000000..8b5dc4d
--- /dev/null
+++ b/src/kpi/dlt-kpi-interrupt.h
@@ -0,0 +1,35 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-interrupt.h
+ */
+
+#ifndef SRC_KPI_DLT_KPI_INTERRUPT_H_
+#define SRC_KPI_DLT_KPI_INTERRUPT_H_
+
+#include "dlt.h"
+#include "dlt-kpi-common.h"
+
+DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level);
+
+#endif /* SRC_KPI_DLT_KPI_INTERRUPT_H_ */
diff --git a/src/kpi/dlt-kpi-options.c b/src/kpi/dlt-kpi-options.c
new file mode 100644
index 0000000..dda36dc
--- /dev/null
+++ b/src/kpi/dlt-kpi-options.c
@@ -0,0 +1,259 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-options.c
+ */
+
+#include "dlt-kpi.h"
+
+/**
+ * Print information how to use this program.
+ */
+void usage(char *prog_name)
+{
+ char version[255];
+ dlt_get_version(version,255);
+
+ printf("Usage: %s [options]\n", prog_name);
+ printf("Application to forward information from the /proc/ file system to DLT.\n");
+ printf("%s\n", version);
+ printf("Options:\n");
+ //printf(" -d Daemonize. Detach from terminal and run in background.\n");
+ printf(" -c filename Use configuration file. \n");
+ printf(" Default: %s\n", DEFAULT_CONF_FILE);
+ printf(" -h This help message.\n");
+}
+
+/**
+ * Initialize command line options with default values.
+ */
+void dlt_kpi_init_cli_options(DltKpiOptions *options)
+{
+ options->configurationFileName = DEFAULT_CONF_FILE;
+ options->customConfigFile = 0;
+}
+
+void dlt_kpi_free_cli_options(DltKpiOptions *options)
+{
+ if(options->customConfigFile)
+ free(options->configurationFileName);
+}
+
+DltReturnValue dlt_kpi_read_command_line(DltKpiOptions *options, int argc, char **argv)
+{
+ if(options == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_read_command_line(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+ dlt_kpi_init_cli_options(options);
+ int opt;
+
+ while((opt = getopt(argc, argv, "c:h")) != -1)
+ {
+ switch(opt) {
+ case 'c':
+ {
+ if((options->configurationFileName = malloc(strlen(optarg)+1)) == 0)
+ {
+ fprintf(stderr, "Out of memory!\n");
+ return DLT_RETURN_ERROR;
+ }
+ strcpy(options->configurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
+ options->customConfigFile = 1;
+ break;
+ }
+ case 'h':
+ {
+ usage(argv[0]);
+ exit(0);
+ return -1;//for parasoft
+ }
+ default:
+ {
+ fprintf(stderr, "Unknown option: %c\n", optopt);
+ usage(argv[0]);
+ return DLT_RETURN_ERROR;
+ }
+ }
+ }
+
+ return DLT_RETURN_OK;
+}
+
+/**
+ * Initialize configuration to default values.
+ */
+void dlt_kpi_init_configuration(DltKpiConfig *config)
+{
+ config->process_log_interval = 1000;
+ config->irq_log_interval = 1000;
+ config->log_level = DLT_LOG_DEFAULT;
+}
+
+/**
+ * Read options from the configuration file
+ */
+DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_name)
+{
+ FILE *file;
+ char *line, *token, *value, *pch, *strchk;
+ int tmp;
+
+ if(config == NULL || file_name == NULL)
+ {
+ fprintf(stderr, "Nullpointer parameter!\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ dlt_kpi_init_configuration(config);
+
+ file = fopen(file_name, "r");
+
+ if(file == NULL)
+ {
+ fprintf(stderr, "Could not open configuration file!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if((line = malloc(COMMAND_LINE_SIZE)) == 0)
+ {
+ fprintf(stderr, "Out of memory!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if((token = malloc(COMMAND_LINE_SIZE)) == 0)
+ {
+ fprintf(stderr, "Out of memory!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if((value = malloc(COMMAND_LINE_SIZE)) == 0)
+ {
+ fprintf(stderr, "Out of memory!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ while(fgets(line, COMMAND_LINE_SIZE, file) != NULL)
+ {
+ token[0] = '\0';
+ value[0] = '\0';
+
+ pch = strtok (line, " =\r\n");
+ while(pch != NULL)
+ {
+ if(pch[0] == '#')
+ break;
+
+ if(token[0] == '\0')
+ {
+ strncpy(token, pch, COMMAND_LINE_SIZE-1);
+ token[COMMAND_LINE_SIZE-1] = '\0';
+ }
+ else
+ {
+ strncpy(value, pch, COMMAND_LINE_SIZE-1);
+ value[COMMAND_LINE_SIZE-1] = '\0';
+ break;
+ }
+
+ pch = strtok(NULL, " =\r\n");
+ }
+
+ if(token[0] != '\0' && value[0] != '\0')
+ {
+ if(strcmp(token, "process_interval") == '\0')
+ {
+ tmp = strtol(value, &strchk, 10);
+
+ if(strchk[0] == '\0' && tmp > 0)
+ config->process_log_interval = tmp;
+ else
+ fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token);
+ }
+ else if(strcmp(token, "irq_interval") == '\0')
+ {
+ tmp = strtol(value, &strchk, 10);
+
+ if(strchk[0] == '\0' && tmp > 0)
+ config->irq_log_interval = tmp;
+ else
+ fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token);
+ }
+ else if(strcmp(token, "check_interval") == '\0')
+ {
+ tmp = strtol(value, &strchk, 10);
+
+ if(strchk[0] == '\0' && tmp > 0)
+ config->check_log_interval = tmp;
+ else
+ fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token);
+ }
+ else if(strcmp(token, "log_level") == '\0')
+ {
+ tmp = strtol(value, &strchk, 10);
+
+ if(strchk[0] == '\0' && tmp >= -1 && tmp <= 6)
+ config->log_level = tmp;
+ else
+ fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token);
+ }
+ }
+ }
+
+ fclose(file);
+ free(value);
+ free(token);
+ free(line);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_init(int argc, char **argv, DltKpiConfig *config)
+{
+ DltKpiOptions options;
+
+ DltReturnValue ret;
+
+ if(config == NULL)
+ {
+ fprintf(stderr, "Nullpointer parameter!");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if((ret = dlt_kpi_read_command_line(&options, argc, argv)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "Failed to read command line!");
+ return ret;
+ }
+
+ if((ret = dlt_kpi_read_configuration_file(config, options.configurationFileName)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "Failed to read configuration file!");
+ return ret;
+ }
+
+ dlt_kpi_free_cli_options(&options);
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/kpi/dlt-kpi-process-list.c b/src/kpi/dlt-kpi-process-list.c
new file mode 100644
index 0000000..7711498
--- /dev/null
+++ b/src/kpi/dlt-kpi-process-list.c
@@ -0,0 +1,288 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-process-list.c
+ */
+
+#include "dlt-kpi-process-list.h"
+
+DltKpiProcessList *dlt_kpi_create_process_list()
+{
+ DltKpiProcessList *new_list = malloc(sizeof(DltKpiProcessList));
+ if(new_list == NULL)
+ {
+ fprintf(stderr, "Cannot create process list, out of memory\n");
+ return NULL;
+ }
+
+ memset(new_list, 0, sizeof(DltKpiProcessList));
+ new_list->start = new_list->cursor = NULL;
+
+ return new_list;
+}
+
+DltReturnValue dlt_kpi_free_process_list_soft(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_free_process_list_soft: Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ free(list);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_free_process_list(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_free_process_list: Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ DltKpiProcess *tmp;
+
+ list->cursor = list->start;
+ while(list->cursor != NULL)
+ {
+ tmp = list->cursor->next;
+ dlt_kpi_free_process(list->cursor);
+ list->cursor = tmp;
+ }
+
+ return dlt_kpi_free_process_list_soft(list);
+}
+
+DltKpiProcess *dlt_kpi_get_process_at_cursor(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_get_process_at_cursor(): Nullpointer parameter\n");
+ return NULL;
+ }
+
+ return list->cursor;
+}
+
+DltReturnValue dlt_kpi_reset_cursor(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_reset_cursor(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ list->cursor = list->start;
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_set_cursor_at_end(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_set_cursor_at_end(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ list->cursor = list->start;
+ if(list->cursor == NULL)
+ return DLT_RETURN_OK;
+
+ while(list->cursor->next != NULL)
+ dlt_kpi_increment_cursor(list);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_increment_cursor(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_set_cursor_at_end(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->cursor == NULL)
+ return DLT_RETURN_ERROR;
+
+ list->cursor = list->cursor->next;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_decrement_cursor(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_set_cursor_at_end(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->cursor == NULL)
+ return DLT_RETURN_ERROR;
+
+ list->cursor = list->cursor->prev;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_add_process_at_start(DltKpiProcessList *list, DltKpiProcess *process)
+{
+ if(list == NULL || process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_add_process_at_start(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->start != NULL)
+ list->start->prev = process;
+
+ process->next = list->start;
+ list->start = process;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_add_process_before_cursor(DltKpiProcessList *list, DltKpiProcess *process)
+{
+ if(list == NULL || process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_add_process_before_cursor(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->start == NULL) // Empty list?
+ {
+ DltReturnValue ret = dlt_kpi_add_process_at_start(list, process);
+ list->cursor = NULL;
+ return ret;
+ }
+ else if(list->cursor == NULL)
+ {
+ dlt_kpi_set_cursor_at_end(list);
+ DltReturnValue ret = dlt_kpi_add_process_after_cursor(list, process);
+ list->cursor = NULL;
+ return ret;
+ }
+
+ if(list->cursor->prev != NULL)
+ list->cursor->prev->next = process;
+ else
+ list->start = process;
+
+ process->next = list->cursor;
+ process->prev = list->cursor->prev;
+ list->cursor->prev = process;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_add_process_after_cursor(DltKpiProcessList *list, DltKpiProcess *process)
+{
+ if(list == NULL || process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_add_process_after_cursor: Nullpointer parameter\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if(list->cursor == NULL)
+ return dlt_kpi_add_process_at_start(list, process);
+
+ if(list->cursor->next != NULL)
+ list->cursor->next->prev = process;
+
+ process->next = list->cursor->next;
+ process->prev = list->cursor;
+ list->cursor->next = process;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_remove_process_at_cursor_soft(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_set_cursor_at_end(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->cursor == NULL)
+ {
+ fprintf(stderr, "Could not remove process from list - cursor is NULL!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ DltKpiProcess *tmp = list->cursor;
+
+ if(tmp->prev != NULL)
+ {
+ if(tmp->next != NULL)
+ {
+ tmp->prev->next = tmp->next;
+ tmp->next->prev = tmp->prev;
+ }
+ else
+ tmp->prev->next = NULL;
+ }
+ else
+ {
+ if(tmp->next != NULL)
+ {
+ tmp->next->prev = NULL;
+ list->start = tmp->next;
+ }
+ else
+ list->start = NULL;
+ }
+
+ list->cursor = tmp->next; // becomes NULL if list is at end
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_remove_process_at_cursor(DltKpiProcessList *list)
+{
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_set_cursor_at_end(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(list->cursor == NULL)
+ {
+ fprintf(stderr, "Could not remove process from list - cursor is NULL!\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ DltKpiProcess *tmp = list->cursor;
+ DltReturnValue ret = dlt_kpi_remove_process_at_cursor_soft(list);
+ if(ret < DLT_RETURN_OK)
+ return ret;
+
+ dlt_kpi_free_process(tmp);
+
+ return DLT_RETURN_OK;
+}
+
diff --git a/src/kpi/dlt-kpi-process-list.h b/src/kpi/dlt-kpi-process-list.h
new file mode 100644
index 0000000..52eb11f
--- /dev/null
+++ b/src/kpi/dlt-kpi-process-list.h
@@ -0,0 +1,54 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-process-list.h
+ */
+
+#ifndef SRC_KPI_DLT_KPI_PROCESS_LIST_H_
+#define SRC_KPI_DLT_KPI_PROCESS_LIST_H_
+
+#include "dlt-kpi-process.h"
+#include "dlt-kpi-common.h"
+
+typedef struct
+{
+ struct DltKpiProcess *start, *cursor;
+} DltKpiProcessList;
+
+DltKpiProcessList *dlt_kpi_create_process_list();
+DltReturnValue dlt_kpi_free_process_list_soft(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_free_process_list(DltKpiProcessList *list);
+DltKpiProcess *dlt_kpi_get_process_at_cursor(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_increment_cursor(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_decrement_cursor(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_reset_cursor(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_add_process_at_start(DltKpiProcessList *list, DltKpiProcess *process);
+DltReturnValue dlt_kpi_add_process_before_cursor(DltKpiProcessList *list, DltKpiProcess *process);
+DltReturnValue dlt_kpi_add_process_after_cursor(DltKpiProcessList *list, DltKpiProcess *process);
+DltReturnValue dlt_kpi_remove_process_at_cursor_soft(DltKpiProcessList *list);
+DltReturnValue dlt_kpi_remove_process_at_cursor(DltKpiProcessList *list);
+
+// DltReturnValue dlt_kpi_remove_process_after_cursor(DltKpiProcessList *list);
+// DltReturnValue dlt_kpi_remove_first_process(DltKpiProcessList *list);
+
+#endif /* SRC_KPI_DLT_KPI_PROCESS_LIST_H_ */
diff --git a/src/kpi/dlt-kpi-process.c b/src/kpi/dlt-kpi-process.c
new file mode 100644
index 0000000..d126551
--- /dev/null
+++ b/src/kpi/dlt-kpi-process.c
@@ -0,0 +1,468 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-process.c
+ */
+
+#include "dlt-kpi-process.h"
+
+#include <pthread.h>
+#include <unistd.h>
+
+DltReturnValue dlt_kpi_read_process_file_to_str(pid_t pid, char **target_str, char *subdir);
+unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int index);
+DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer);
+
+DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned long int time_dif_ms)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_process_update_io_wait(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ unsigned long int total_io_wait = dlt_kpi_read_process_stat_to_ulong(process->pid, 42);
+
+ process->io_wait = (total_io_wait - process->last_io_wait) * 1000 / sysconf(_SC_CLK_TCK); // busy milliseconds since last update
+ if(time_dif_ms > 0)
+ process->io_wait = process->io_wait * 1000 / time_dif_ms; // busy milliseconds per second
+
+ process->last_io_wait = total_io_wait;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned long int time_dif_ms)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_process_update_cpu_time(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ unsigned long int utime = dlt_kpi_read_process_stat_to_ulong(process->pid, 14);
+ unsigned long int stime = dlt_kpi_read_process_stat_to_ulong(process->pid, 15);
+
+ unsigned long total_cpu_time = utime + stime;
+
+ process->cpu_time = (total_cpu_time - process->last_cpu_time) * 1000 / sysconf(_SC_CLK_TCK); // busy milliseconds since last update
+ if(time_dif_ms > 0)
+ process->cpu_time = process->cpu_time * 1000 / time_dif_ms; // busy milliseconds per second
+
+ process->last_cpu_time = total_cpu_time;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_process_update_rss(DltKpiProcess *process)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_process_update_rss(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ process->rss = dlt_kpi_read_process_stat_to_ulong(process->pid, 24);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_process_update_ctx_switches(DltKpiProcess *process)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_process_update_ctx_switches(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ char *buffer, *tok, *last_tok;
+ char *delim = " :\t\n";
+ last_tok = NULL;
+
+ DltReturnValue ret;
+ if((ret = dlt_kpi_read_process_file_to_str(process->pid, &buffer, "status")) < DLT_RETURN_OK) return ret;
+
+ process->ctx_switches = 0;
+
+ tok = strtok(buffer, delim);
+ while(tok != NULL)
+ {
+ if(last_tok != NULL)
+ {
+ if(strcmp(last_tok, "voluntary_ctxt_switches") == 0 || strcmp(last_tok, "nonvoluntary_ctxt_switches") == 0)
+ {
+ char *chk;
+ process->ctx_switches += strtol(tok, &chk, 10);
+
+ if(*chk != '\0')
+ {
+ fprintf(stderr, "Could not parse ctx_switches info from /proc/%d/status", process->pid);
+ free(buffer);
+ return DLT_RETURN_ERROR;
+ }
+ }
+ }
+
+ last_tok = tok;
+ tok = strtok(NULL, delim);
+ }
+
+ free(buffer);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_process_update_io_bytes(DltKpiProcess *process)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_process_update_io_bytes: Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ char *buffer, *tok, *last_tok;
+ char *delim = " :\t\n";
+ last_tok = NULL;
+
+ DltReturnValue ret;
+ if((ret = dlt_kpi_read_process_file_to_str(process->pid, &buffer, "io")) < DLT_RETURN_OK)
+ return ret;
+
+ process->io_bytes = 0;
+
+ tok = strtok(buffer, delim);
+ while(tok != NULL)
+ {
+ if(last_tok != NULL)
+ {
+ if(strcmp(last_tok, "rchar") == 0 || strcmp(last_tok, "wchar") == 0)
+ {
+ char *chk;
+ process->io_bytes += strtoul(tok, &chk, 10);
+
+ if(*chk != '\0')
+ {
+ fprintf(stderr, "Could not parse io_bytes info from /proc/%d/io", process->pid);
+ free(buffer);
+ return DLT_RETURN_ERROR;
+ }
+ }
+ }
+
+ last_tok = tok;
+ tok = strtok(NULL, delim);
+ }
+
+ free(buffer);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms)
+{
+ dlt_kpi_process_update_io_wait(process, time_dif_ms);
+ dlt_kpi_process_update_cpu_time(process, time_dif_ms);
+ dlt_kpi_process_update_rss(process);
+ dlt_kpi_process_update_ctx_switches(process);
+ dlt_kpi_process_update_io_bytes(process);
+
+ return DLT_RETURN_OK;
+}
+
+DltKpiProcess *dlt_kpi_create_process(int pid)
+{
+ DltKpiProcess *new_process = malloc(sizeof(DltKpiProcess));
+ memset(new_process, 0, sizeof(DltKpiProcess));
+
+ new_process->pid = pid;
+ new_process->ppid = (pid_t)dlt_kpi_read_process_stat_to_ulong(pid, 4);
+
+ dlt_kpi_read_process_file_to_str(pid, &(new_process->command_line), "cmdline");
+ if(new_process->command_line != NULL)
+ if(strlen(new_process->command_line) == 0)
+ {
+ free(new_process->command_line);
+ dlt_kpi_read_process_stat_cmdline(pid, &(new_process->command_line));
+ }
+
+ dlt_kpi_update_process(new_process, 0);
+
+ return new_process;
+}
+
+DltKpiProcess *dlt_kpi_clone_process(DltKpiProcess *original)
+{
+ if(original == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_clone_process: Nullpointer parameter\n");
+ return NULL;
+ }
+
+ // DltKpiProcess *new_process = dlt_kpi_create_process(original->pid);
+ DltKpiProcess *new_process = malloc(sizeof(DltKpiProcess));
+ if(new_process == NULL)
+ {
+ fprintf(stderr, "Out of memory\n");
+ return NULL;
+ }
+
+ memcpy(new_process, original, sizeof(DltKpiProcess));
+
+ if(original->command_line != NULL)
+ {
+ new_process->command_line = malloc(strlen(original->command_line) + 1);
+ if(new_process->command_line == NULL)
+ {
+ fprintf(stderr, "Out of memory\n");
+ return NULL;
+ }
+ strncpy(new_process->command_line, original->command_line, strlen(original->command_line) + 1);
+ }
+ else
+ new_process->command_line = NULL;
+
+ new_process->next = new_process->prev = NULL;
+
+ return new_process;
+}
+
+DltReturnValue dlt_kpi_free_process(DltKpiProcess *process)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_free_process: Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(process->command_line != NULL)
+ free(process->command_line);
+
+ free(process);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_print_process(DltKpiProcess *process)
+{
+ if(process == NULL)
+ {
+ fprintf(stderr, "Error: Nullpointer parameter\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ printf("[PID %d]\n", process->pid);
+ printf(" > PPID : %d\n", process->ppid);
+ printf(" > CMDLINE : %s\n", process->command_line);
+ printf(" > CPUTIME : %lu (busy ms/s)\n", process->cpu_time);
+ printf(" > RSS : %ld\n", process->rss);
+ printf(" > CTXSWTC : %ld\n", process->ctx_switches);
+ printf(" > IOBYTES : %lu\n", process->io_bytes);
+ printf(" > IOWAIT : %ld (%ld)\n", process->io_wait, process->last_io_wait);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_read_process_file_to_str(pid_t pid, char **target_str, char *subdir)
+{
+ if(target_str == NULL)
+ {
+ fprintf(stderr, "Error: Nullpointer parameter\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ *target_str = NULL;
+
+ if(pid <= 0)
+ {
+ fprintf(stderr, "Error: Invalid PID\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if(subdir == NULL)
+ {
+ fprintf(stderr, "Error: Nullpointer parameter\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ char filename[BUFFER_SIZE];
+ snprintf(filename, BUFFER_SIZE, "/proc/%d/%s", pid, subdir);
+
+ return dlt_kpi_read_file_compact(filename, target_str);
+}
+
+unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int index)
+{
+ if(pid <= 0)
+ {
+ fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Invalid PID\n");
+ return 0;
+ }
+
+ char *buffer = NULL;
+ DltReturnValue tmp = dlt_kpi_read_process_file_to_str(pid, &buffer, "stat");
+ if(tmp < DLT_RETURN_OK)
+ {
+ if(buffer != NULL)
+ free(buffer);
+
+ return tmp;
+ }
+
+ char *tok = strtok(buffer, " \t\n");
+ unsigned int i = 1, found = 0;
+
+ while(tok != NULL)
+ {
+ if(i == index)
+ {
+ found = 1;
+ break;
+ }
+ i++;
+ tok = strtok(NULL, " \t\n");
+ }
+
+ unsigned long int ret = 0;
+
+ if(found)
+ {
+ char *check = NULL;
+ ret = strtoul(tok, &check, 10);
+ if(*check != '\0')
+ {
+ fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Could not extract token\n");
+ ret = 0;
+ }
+ }
+ else
+ fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Index not found\n");
+
+ free(buffer);
+
+ return ret;
+}
+
+DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer)
+{
+ if(pid <= 0)
+ {
+ fprintf(stderr, "dlt_kpi_read_process_stat_cmdline(): Invalid PID\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ if(buffer == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_read_process_stat_cmdline(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ char *tmp_buffer = NULL;
+ DltReturnValue tmp = dlt_kpi_read_process_file_to_str(pid, &tmp_buffer, "stat");
+ if(tmp < DLT_RETURN_OK)
+ {
+ if(tmp_buffer != NULL)
+ free(tmp_buffer);
+
+ return tmp;
+ }
+
+ char *tok = strtok(tmp_buffer, " \t\n");
+ unsigned int i = 1;
+
+ while(tok != NULL)
+ {
+ if(i == 2)
+ {
+ break;
+ }
+ i++;
+ tok = strtok(NULL, " \t\n");
+ }
+
+ if(i == 2)
+ {
+ (*buffer) = malloc(strlen(tok) + 1);
+ strncpy(*buffer, tok, strlen(tok) + 1);
+ }
+ else
+ {
+ fprintf(stderr, "dlt_kpi_read_process_stat_cmdline(): cmdline entry not found\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ free(tmp_buffer);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen)
+{
+ if(process == NULL || buffer == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_process_new(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ snprintf(buffer, maxlen, "%d;%lu;%ld;%ld;%lu;%lu", process->pid, process->cpu_time, process->rss, process->ctx_switches, process->io_bytes, process->io_wait);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, int maxlen)
+{
+ if(process == NULL || buffer == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_process_new(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ snprintf(buffer, maxlen, "%d;%d;%s", process->pid, process->ppid, process->command_line);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen)
+{
+ if(process == NULL || buffer == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_process_new(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ snprintf(buffer, maxlen, "%d", process->pid);
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen)
+{
+ if(process == NULL || buffer == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_process_new(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ snprintf(buffer, maxlen, "%d;%s", process->pid, process->command_line);
+
+ return DLT_RETURN_OK;
+}
diff --git a/src/kpi/dlt-kpi-process.h b/src/kpi/dlt-kpi-process.h
new file mode 100644
index 0000000..50d5fbc
--- /dev/null
+++ b/src/kpi/dlt-kpi-process.h
@@ -0,0 +1,56 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi-process.h
+ */
+
+#ifndef SRC_KPI_DLT_KPI_PROCESS_H_
+#define SRC_KPI_DLT_KPI_PROCESS_H_
+
+#include "dlt.h"
+#include <stdlib.h>
+#include "dlt-kpi-common.h"
+
+typedef struct DltKpiEventWatch DltKpiEventWatch; // forward declaration
+
+typedef struct DltKpiProcess
+{
+ pid_t pid, ppid;
+ char *command_line;
+ unsigned long int cpu_time, last_cpu_time, io_wait, last_io_wait, io_bytes;
+ long int rss, ctx_switches;
+
+ struct DltKpiProcess *next, *prev;
+} DltKpiProcess;
+
+DltKpiProcess *dlt_kpi_create_process();
+DltKpiProcess *dlt_kpi_clone_process(DltKpiProcess *original);
+DltReturnValue dlt_kpi_free_process(DltKpiProcess *process);
+DltReturnValue dlt_kpi_print_process(DltKpiProcess *process);
+DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms);
+DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, int maxlen);
+DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen);
+DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen);
+DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen);
+
+#endif /* SRC_KPI_DLT_KPI_PROCESS_H_ */
diff --git a/src/kpi/dlt-kpi.c b/src/kpi/dlt-kpi.c
new file mode 100644
index 0000000..f315058
--- /dev/null
+++ b/src/kpi/dlt-kpi.c
@@ -0,0 +1,510 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi.c
+ */
+
+#include "dlt-kpi.h"
+
+#include <signal.h>
+#include <dirent.h>
+#include <time.h>
+#include <unistd.h>
+#include <pthread.h>
+
+DLT_DECLARE_CONTEXT(kpi_ctx);
+
+DltKpiConfig config;
+
+static volatile sig_atomic_t stop_loop = 0;
+static DltKpiProcessList *list, *new_process_list, *stopped_process_list, *update_process_list;
+static struct timespec _tmp_time;
+static pthread_mutex_t process_list_mutex;
+
+void dlt_kpi_stop_loops(int sig);
+void dlt_kpi_init_sigterm_handler();
+DltReturnValue dlt_kpi_init_process_lists();
+DltReturnValue dlt_kpi_free_process_lists();
+void *dlt_kpi_start_process_thread();
+DltReturnValue dlt_kpi_process_loop();
+DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned long int time_dif_ms);
+void *dlt_kpi_start_irq_thread();
+DltReturnValue dlt_kpi_irq_loop();
+void *dlt_kpi_start_check_thread();
+DltReturnValue dlt_kpi_check_loop();
+DltReturnValue dlt_kpi_log_check_commandlines();
+
+unsigned long int timespec_to_millis(struct timespec *time)
+{
+ return (time->tv_sec) * 1000 + (time->tv_nsec / 1000000);
+}
+
+unsigned long int get_millis()
+{
+ clock_gettime(CLOCK_REALTIME, &_tmp_time);
+ return timespec_to_millis(&_tmp_time);
+}
+
+int main(int argc, char **argv)
+{
+ printf("Launching dlt-kpi...\n");
+
+ if(dlt_kpi_init(argc, argv, &config) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "Initialization error!\n");
+ return -1;
+ }
+
+ dlt_kpi_init_sigterm_handler();
+
+ if(dlt_kpi_init_process_lists() < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "Error occurred initializing process lists\n");
+ return -1;
+ }
+
+ if(pthread_mutex_init(&process_list_mutex, NULL) < 0)
+ {
+ fprintf(stderr, "Error occurred initializing mutex\n");
+ return -1;
+ }
+
+ DLT_REGISTER_APP("PROC", "/proc/-filesystem logger application");
+ DLT_REGISTER_CONTEXT_LL_TS(kpi_ctx, "PROC", "/proc/-filesystem logger context", config.log_level, 1);
+
+ pthread_t process_thread;
+ pthread_t irq_thread;
+ pthread_t check_thread;
+
+ if(pthread_create(&process_thread, NULL, &dlt_kpi_start_process_thread, NULL) != 0)
+ {
+ fprintf(stderr, "Could not create thread\n");
+ return -1;
+ }
+ if(pthread_create(&irq_thread, NULL, &dlt_kpi_start_irq_thread, NULL) != 0)
+ {
+ fprintf(stderr, "Could not create thread\n");
+ return -1;
+ }
+ if(pthread_create(&check_thread, NULL, &dlt_kpi_start_check_thread, NULL) != 0)
+ {
+ fprintf(stderr, "Could not create thread\n");
+ return -1;
+ }
+
+ pthread_join(process_thread, NULL);
+ pthread_join(irq_thread, NULL);
+ pthread_join(check_thread, NULL);
+
+ DLT_UNREGISTER_CONTEXT(kpi_ctx);
+ DLT_UNREGISTER_APP();
+
+ pthread_mutex_destroy(&process_list_mutex);
+
+ dlt_kpi_free_process_lists();
+
+ printf("Done.\n");
+}
+
+void dlt_kpi_init_sigterm_handler()
+{
+ struct sigaction action;
+ memset(&action, 0, sizeof(struct sigaction));
+ action.sa_handler = dlt_kpi_stop_loops;
+
+ sigaction(SIGTERM, &action, NULL);
+}
+
+void dlt_kpi_stop_loops(int sig)
+{
+ if(sig > -1)
+ fprintf(stderr, "dlt-kpi is now terminating due to signal %d...\n", sig);
+ else
+ fprintf(stderr, "dlt-kpi is now terminating due to an error...\n");
+
+ stop_loop = 1;
+}
+
+DltReturnValue dlt_kpi_init_process_lists()
+{
+ if((list = dlt_kpi_create_process_list()) == NULL) return DLT_RETURN_ERROR;
+ if((new_process_list = dlt_kpi_create_process_list()) == NULL) return DLT_RETURN_ERROR;
+ if((stopped_process_list = dlt_kpi_create_process_list()) == NULL) return DLT_RETURN_ERROR;
+ if((update_process_list = dlt_kpi_create_process_list()) == NULL) return DLT_RETURN_ERROR;
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_free_process_lists()
+{
+ DltReturnValue ret = DLT_RETURN_OK;
+
+ if(dlt_kpi_free_process_list(list) < DLT_RETURN_OK)
+ ret = DLT_RETURN_ERROR;
+
+ if(dlt_kpi_free_process_list(new_process_list) < DLT_RETURN_OK)
+ ret = DLT_RETURN_ERROR;
+
+ if(dlt_kpi_free_process_list(stopped_process_list) < DLT_RETURN_OK)
+ ret = DLT_RETURN_ERROR;
+
+ if(dlt_kpi_free_process_list(update_process_list) < DLT_RETURN_OK)
+ ret = DLT_RETURN_ERROR;
+
+ return ret;
+}
+
+void *dlt_kpi_start_process_thread()
+{
+ if(dlt_kpi_process_loop() < DLT_RETURN_OK)
+ dlt_kpi_stop_loops(-1);
+
+ return NULL;
+}
+
+DltReturnValue dlt_kpi_process_loop()
+{
+ static unsigned long int old_millis, sleep_millis, dif_millis;
+
+ old_millis = get_millis();
+
+ while(!stop_loop)
+ {
+ /*DltReturnValue ret = */ dlt_kpi_update_process_list(list, config.process_log_interval);
+ //if(ret < DLT_RETURN_OK)
+ // return ret;
+
+ dif_millis = get_millis() - old_millis;
+
+ if(dif_millis >= (unsigned long)(config.process_log_interval))
+ sleep_millis = 0;
+ else
+ sleep_millis = config.process_log_interval - dif_millis;
+
+ usleep(sleep_millis * 1000);
+
+ old_millis = get_millis();
+ }
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, DltReturnValue(*process_callback)(DltKpiProcess*, char*, int), char *title, int delete_elements)
+{
+ if(list == NULL || process_callback == NULL || title == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): Nullpointer parameter\n");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ dlt_kpi_reset_cursor(list);
+ if(list->cursor == NULL)
+ return DLT_RETURN_OK; // list empty; nothing to do
+
+ // Synchronization message
+ DLT_LOG(kpi_ctx, config.log_level, DLT_STRING(title), DLT_STRING("BEG"));
+
+ DltReturnValue ret;
+ DltContextData data;
+
+ char buffer[BUFFER_SIZE];
+ buffer[0] = '\0';
+
+ if((ret = dlt_user_log_write_start(&kpi_ctx, &data, config.log_level)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_start() returned error.\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_string() returned error.\n");
+ return ret;
+ }
+
+ do
+ {
+ if((ret = (*process_callback)(list->cursor, buffer, sizeof(buffer) - 1)) < DLT_RETURN_OK)
+ return ret;
+
+ if((ret = dlt_user_log_write_string(&data, buffer)) < DLT_RETURN_OK)
+ {
+ /* Log buffer full => Write log and start new one*/
+ if((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_finish() returned error.\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_start(&kpi_ctx, &data, config.log_level)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_start() returned error.\n");
+ return ret;
+ }
+
+ if((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_string() returned error.\n");
+ return ret;
+ }
+ }
+ else if(delete_elements)
+ {
+ if((ret = dlt_kpi_remove_process_at_cursor(list)) < DLT_RETURN_OK)
+ return ret;
+ }
+ else
+ {
+ list->cursor = list->cursor->next;
+ }
+ }
+ while(list->cursor != NULL);
+
+ if((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_log_list(): dlt_user_log_write_finish() returned error.\n");
+ return ret;
+ }
+
+ // Synchronization message
+ DLT_LOG(kpi_ctx, config.log_level, DLT_STRING(title), DLT_STRING("END"));
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned long int time_dif_ms)
+{
+ static char *strchk;
+ static DltReturnValue tmp_ret;
+ static struct dirent *current_dir;
+ static pid_t current_dir_pid;
+
+ if(list == NULL)
+ {
+ fprintf(stderr, "dlt_kpi_update_process_list(): Nullpointer parameter");
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
+ DIR *proc_dir = opendir("/proc");
+ if(proc_dir == NULL)
+ {
+ dlt_log(LOG_ERR, "Could not open /proc/ !\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ current_dir = readdir(proc_dir);
+ dlt_kpi_reset_cursor(list);
+
+ int debug_process_count = 0;
+
+ if(pthread_mutex_lock(&process_list_mutex) < 0)
+ {
+ fprintf(stderr, "Can't lock mutex\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ while(1)
+ {
+ if(current_dir == NULL)
+ {
+ /* no more active processes.. delete all remaining processes in the list */
+ if(list->cursor != NULL)
+ while(list->cursor != NULL)
+ {
+ if((tmp_ret = dlt_kpi_add_process_after_cursor(stopped_process_list, dlt_kpi_clone_process(list->cursor))) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ dlt_kpi_remove_process_at_cursor(list);
+ }
+
+ break;
+ }
+
+ current_dir_pid = strtol(current_dir->d_name, &strchk, 10);
+ if(*strchk != '\0' || current_dir_pid <= 0)
+ {
+ /* no valid PID */
+ current_dir = readdir(proc_dir); // next process in proc-fs
+ continue;
+ }
+
+ /* compare the /proc/-filesystem with our process-list */
+ if(list->cursor == NULL || current_dir_pid < list->cursor->pid) // New Process
+ {
+ DltKpiProcess *new_process = dlt_kpi_create_process(current_dir_pid);
+ if(new_process == NULL)
+ {
+ fprintf(stderr, "Error: Could not create process (out of memory?)\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ if((tmp_ret = dlt_kpi_add_process_before_cursor(list, new_process)) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ if((tmp_ret = dlt_kpi_add_process_before_cursor(new_process_list, dlt_kpi_clone_process(new_process))) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ current_dir = readdir(proc_dir); // next process in proc-fs
+ debug_process_count++;
+ }
+ else if(current_dir_pid > list->cursor->pid) // Process ended
+ {
+ if((tmp_ret = dlt_kpi_add_process_after_cursor(stopped_process_list, dlt_kpi_clone_process(list->cursor))) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ if((tmp_ret = dlt_kpi_remove_process_at_cursor(list)) < DLT_RETURN_OK)
+ return tmp_ret;
+ }
+ else if(current_dir_pid == list->cursor->pid) // Staying process
+ {
+ /* update data */
+ if((tmp_ret = dlt_kpi_update_process(list->cursor, time_dif_ms)) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ if(list->cursor->cpu_time > 0) // only log active processes
+ if((tmp_ret = dlt_kpi_add_process_after_cursor(update_process_list, dlt_kpi_clone_process(list->cursor))) < DLT_RETURN_OK)
+ {
+ fprintf(stderr, "dlt_kpi_update_process_list: Can't add process to list updateProcessList\n");
+ return tmp_ret;
+ }
+
+ if((tmp_ret = dlt_kpi_increment_cursor(list)) < DLT_RETURN_OK) // next process in list
+ return tmp_ret;
+
+ current_dir = readdir(proc_dir); // next process in proc-fs
+ debug_process_count++;
+ }
+ }
+
+ if(pthread_mutex_unlock(&process_list_mutex) < 0)
+ {
+ fprintf(stderr, "Can't unlock mutex\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ /* Log new processes */
+ if((tmp_ret = dlt_kpi_log_list(new_process_list, &dlt_kpi_get_msg_process_new, "NEW", 1)) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ /* Log stopped processes */
+ if((tmp_ret = dlt_kpi_log_list(stopped_process_list, &dlt_kpi_get_msg_process_stop, "STP", 1)) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ /* Log active processes */
+ if((tmp_ret = dlt_kpi_log_list(update_process_list, &dlt_kpi_get_msg_process_update, "ACT", 1)) < DLT_RETURN_OK)
+ return tmp_ret;
+
+ if(closedir(proc_dir) < 0)
+ fprintf(stderr, "Could not close /proc/ directory\n");
+
+ return DLT_RETURN_OK;
+}
+
+void *dlt_kpi_start_irq_thread()
+{
+ if(dlt_kpi_irq_loop() < DLT_RETURN_OK)
+ dlt_kpi_stop_loops(-1);
+
+ return NULL;
+}
+
+DltReturnValue dlt_kpi_irq_loop()
+{
+ static unsigned long int old_millis, sleep_millis, dif_millis;
+
+ old_millis = get_millis();
+
+ while(!stop_loop)
+ {
+ /*DltReturnValue ret = */ dlt_kpi_log_interrupts(&kpi_ctx, config.log_level);
+ //if(ret < DLT_RETURN_OK)
+ // return ret;
+
+ dif_millis = get_millis() - old_millis;
+
+ if(dif_millis >= (unsigned long)(config.irq_log_interval))
+ sleep_millis = 0;
+ else
+ sleep_millis = config.irq_log_interval - dif_millis;
+
+ usleep(sleep_millis * 1000);
+
+ old_millis = get_millis();
+ }
+
+ return DLT_RETURN_OK;
+}
+
+void *dlt_kpi_start_check_thread()
+{
+ if(dlt_kpi_check_loop() < DLT_RETURN_OK)
+ dlt_kpi_stop_loops(-1);
+
+ return NULL;
+}
+
+DltReturnValue dlt_kpi_check_loop()
+{
+ static unsigned long int old_millis, sleep_millis, dif_millis;
+
+ old_millis = get_millis();
+
+ while(!stop_loop)
+ {
+ /*DltReturnValue ret = */ dlt_kpi_log_check_commandlines();
+ //if(ret < DLT_RETURN_OK)
+ // return ret;
+
+ dif_millis = get_millis() - old_millis;
+
+ if(dif_millis >= (unsigned long)(config.check_log_interval))
+ sleep_millis = 0;
+ else
+ sleep_millis = config.check_log_interval - dif_millis;
+
+ usleep(sleep_millis * 1000);
+
+ old_millis = get_millis();
+ }
+
+ return DLT_RETURN_OK;
+}
+
+DltReturnValue dlt_kpi_log_check_commandlines()
+{
+ if(pthread_mutex_lock(&process_list_mutex) < 0)
+ {
+ fprintf(stderr, "Can't lock mutex\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ DltReturnValue ret = dlt_kpi_log_list(list, dlt_kpi_get_msg_process_commandline, "CHK", 0);
+
+ if(pthread_mutex_unlock(&process_list_mutex) < 0)
+ {
+ fprintf(stderr, "Can't unlock mutex\n");
+ return DLT_RETURN_ERROR;
+ }
+
+ return ret;
+}
diff --git a/src/kpi/dlt-kpi.conf b/src/kpi/dlt-kpi.conf
new file mode 100644
index 0000000..bb93d47
--- /dev/null
+++ b/src/kpi/dlt-kpi.conf
@@ -0,0 +1,18 @@
+# Configuration file for DLT KPI logger
+#
+
+########################################################################
+# General configuration
+########################################################################
+
+# The interval in milliseconds of how often process updates should be logged. (Default: 1000)
+process_interval = 1000
+
+# The interval in milliseconds of how often interrupt stats should be logged. (Default: 3000)
+irq_interval = 3000
+
+# The interval in milliseconds of how often the commandlines of all processes should be logged. (Default: 10000)
+check_interval = 10000
+
+# The used log level. -1 = DEFAULT, 0 = OFF, [...], 6 = VERBOSE (Default: 4)
+log_level = 4 \ No newline at end of file
diff --git a/src/kpi/dlt-kpi.h b/src/kpi/dlt-kpi.h
new file mode 100644
index 0000000..bb5b48c
--- /dev/null
+++ b/src/kpi/dlt-kpi.h
@@ -0,0 +1,62 @@
+/*
+ * @licence app begin@
+ * SPDX license identifier: MPL-2.0
+ *
+ * Copyright (C) 2011-2015, BMW AG
+ *
+ * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
+ *
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License (MPL), v. 2.0.
+ * If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * For further information see http://www.genivi.org/.
+ * @licence end@
+ */
+
+/*!
+ * \author Sven Hassler <sven_hassler@mentor.com>
+ *
+ * \copyright Copyright © 2011-2015 BMW AG. \n
+ * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
+ *
+ * \file dlt-kpi.h
+ */
+
+#ifndef SRC_KPI_DLT_KPI_H_
+#define SRC_KPI_DLT_KPI_H_
+
+#include "dlt.h"
+#include <syslog.h>
+
+#include "dlt-kpi-common.h"
+#include "dlt-kpi-interrupt.h"
+#include "dlt-kpi-process.h"
+#include "dlt-kpi-process-list.h"
+
+// CONSTANT DEFINITIONS
+#define DEFAULT_CONF_FILE ( CONFIGURATION_FILES_DIR "/dlt-kpi.conf")
+
+#define COMMAND_LINE_SIZE 1024
+
+// STRUCTURES
+typedef struct
+{
+ char *configurationFileName;
+ int customConfigFile;
+} DltKpiOptions;
+
+typedef struct
+{
+ int process_log_interval, irq_log_interval, check_log_interval;
+ DltLogLevelType log_level;
+} DltKpiConfig;
+
+// FUNCTION DECLARATIONS:
+DltReturnValue dlt_kpi_read_command_line(DltKpiOptions *options, int argc, char **argv);
+DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_name);
+void dlt_kpi_free_cli_options(DltKpiOptions *options);
+DltReturnValue dlt_kpi_init(int argc, char **argv, DltKpiConfig *config);
+
+#endif /* SRC_KPI_DLT_KPI_H_ */