summaryrefslogtreecommitdiff
path: root/src/kpi/dlt-kpi.c
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@de.adit-jv.com>2018-12-20 14:58:19 +0100
committerChristoph Lipka <clipka@de.adit-jv.com>2018-12-21 10:23:41 +0100
commitdca8ab254aa0a687c32009079d85e4d8f960b213 (patch)
treee63b6a552fd9f61873892110a56a89ef354864cd /src/kpi/dlt-kpi.c
parent0d0c74640c8b792db37cb9f884f89f7561ea551f (diff)
downloadDLT-daemon-dca8ab254aa0a687c32009079d85e4d8f960b213.tar.gz
Code beautification using uncrustify
Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
Diffstat (limited to 'src/kpi/dlt-kpi.c')
-rw-r--r--src/kpi/dlt-kpi.c231
1 files changed, 109 insertions, 122 deletions
diff --git a/src/kpi/dlt-kpi.c b/src/kpi/dlt-kpi.c
index 8ba019e..0fbff3a 100644
--- a/src/kpi/dlt-kpi.c
+++ b/src/kpi/dlt-kpi.c
@@ -69,22 +69,19 @@ int main(int argc, char **argv)
{
printf("Launching dlt-kpi...\n");
- if(dlt_kpi_init(argc, argv, &config) < DLT_RETURN_OK)
- {
+ 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)
- {
+ 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)
- {
+ if (pthread_mutex_init(&process_list_mutex, NULL) < 0) {
fprintf(stderr, "Error occurred initializing mutex\n");
return -1;
}
@@ -96,18 +93,17 @@ int main(int argc, char **argv)
pthread_t irq_thread;
pthread_t check_thread;
- if(pthread_create(&process_thread, NULL, &dlt_kpi_start_process_thread, NULL) != 0)
- {
+ 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)
- {
+
+ 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)
- {
+
+ if (pthread_create(&check_thread, NULL, &dlt_kpi_start_check_thread, NULL) != 0) {
fprintf(stderr, "Could not create thread\n");
return -1;
}
@@ -124,7 +120,7 @@ int main(int argc, char **argv)
dlt_kpi_free_process_lists();
printf("Done.\n");
-
+
return 0;
}
@@ -139,7 +135,7 @@ void dlt_kpi_init_sigterm_handler()
void dlt_kpi_stop_loops(int sig)
{
- if(sig > -1)
+ 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");
@@ -149,10 +145,13 @@ void dlt_kpi_stop_loops(int sig)
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;
+ 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;
}
@@ -161,16 +160,16 @@ DltReturnValue dlt_kpi_free_process_lists()
{
DltReturnValue ret = DLT_RETURN_OK;
- if(dlt_kpi_free_process_list(list) < 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)
+ 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)
+ 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)
+ if (dlt_kpi_free_process_list(update_process_list) < DLT_RETURN_OK)
ret = DLT_RETURN_ERROR;
return ret;
@@ -178,7 +177,7 @@ DltReturnValue dlt_kpi_free_process_lists()
void *dlt_kpi_start_process_thread()
{
- if(dlt_kpi_process_loop() < DLT_RETURN_OK)
+ if (dlt_kpi_process_loop() < DLT_RETURN_OK)
dlt_kpi_stop_loops(-1);
return NULL;
@@ -190,15 +189,14 @@ DltReturnValue dlt_kpi_process_loop()
old_millis = get_millis();
- while(!stop_loop)
- {
+ while (!stop_loop) {
/*DltReturnValue ret = */ dlt_kpi_update_process_list(list, config.process_log_interval);
- //if(ret < DLT_RETURN_OK)
- // return ret;
+ /*if(ret < DLT_RETURN_OK) */
+ /* return ret; */
dif_millis = get_millis() - old_millis;
- if(dif_millis >= (unsigned long)(config.process_log_interval))
+ if (dif_millis >= (unsigned long)(config.process_log_interval))
sleep_millis = 0;
else
sleep_millis = config.process_log_interval - dif_millis;
@@ -211,19 +209,22 @@ DltReturnValue dlt_kpi_process_loop()
return DLT_RETURN_OK;
}
-DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, DltReturnValue(*process_callback)(DltKpiProcess*, char*, int), char *title, int delete_elements)
+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, "%s: Invalid Parameter (NULL)\n", __func__);
+ if ((list == NULL) || (process_callback == NULL) || (title == NULL)) {
+ fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__);
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
+ 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;
@@ -232,63 +233,53 @@ DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, DltReturnValue(*process
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, "%s: dlt_user_log_write_start() returned error.\n", __func__);
+ if ((ret = dlt_user_log_write_start(&kpi_ctx, &data, config.log_level)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_start() returned error.\n", __func__);
return ret;
}
- if((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK)
- {
- fprintf(stderr, "%s: dlt_user_log_write_string() returned error.\n", __func__);
+ if ((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_string() returned error.\n", __func__);
return ret;
}
- do
- {
- if((ret = (*process_callback)(list->cursor, buffer, sizeof(buffer) - 1)) < DLT_RETURN_OK)
+ 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)
- {
+ 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, "%s: dlt_user_log_write_finish() returned error.\n",__func__);
+ if ((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_finish() returned error.\n", __func__);
return ret;
}
- if((ret = dlt_user_log_write_start(&kpi_ctx, &data, config.log_level)) < DLT_RETURN_OK)
- {
- fprintf(stderr, "%s: dlt_user_log_write_start() returned error.\n",__func__);
+ if ((ret = dlt_user_log_write_start(&kpi_ctx, &data, config.log_level)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_start() returned error.\n", __func__);
return ret;
}
- if((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK)
- {
- fprintf(stderr, "%s: dlt_user_log_write_string() returned error.\n",__func__);
+ if ((ret = dlt_user_log_write_string(&data, title)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_string() returned error.\n", __func__);
return ret;
}
}
- else if(delete_elements)
+ else if (delete_elements)
{
- if((ret = dlt_kpi_remove_process_at_cursor(list)) < DLT_RETURN_OK)
+ if ((ret = dlt_kpi_remove_process_at_cursor(list)) < DLT_RETURN_OK)
return ret;
}
- else
- {
+ else {
list->cursor = list->cursor->next;
}
- }
- while(list->cursor != NULL);
+ } while (list->cursor != NULL);
- if((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK)
- {
- fprintf(stderr, "%s: dlt_user_log_write_finish() returned error.\n",__func__);
+ if ((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK) {
+ fprintf(stderr, "%s: dlt_user_log_write_finish() returned error.\n", __func__);
return ret;
}
- // Synchronization message
+ /* Synchronization message */
DLT_LOG(kpi_ctx, config.log_level, DLT_STRING(title), DLT_STRING("END"));
return DLT_RETURN_OK;
@@ -301,15 +292,14 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon
static struct dirent *current_dir;
static pid_t current_dir_pid;
- if(list == NULL)
- {
+ 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)
- {
+
+ if (proc_dir == NULL) {
dlt_log(LOG_ERR, "Could not open /proc/ !\n");
return DLT_RETURN_ERROR;
}
@@ -319,21 +309,19 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon
int debug_process_count = 0;
- if(pthread_mutex_lock(&process_list_mutex) < 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)
- {
+ 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)
+ 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);
@@ -343,80 +331,83 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon
}
current_dir_pid = strtol(current_dir->d_name, &strchk, 10);
- if(*strchk != '\0' || current_dir_pid <= 0)
- {
+
+ if ((*strchk != '\0') || (current_dir_pid <= 0)) {
/* no valid PID */
- current_dir = readdir(proc_dir); // next process in proc-fs
+ 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
- {
+ 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)
- {
+
+ 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)
+ 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)
+ 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
+ current_dir = readdir(proc_dir); /* next process in proc-fs */
debug_process_count++;
}
- else if(current_dir_pid > list->cursor->pid) // Process ended
+ 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)
+ 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)
+ 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
+ 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 ((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)
- {
+ 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
+ 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
+ current_dir = readdir(proc_dir); /* next process in proc-fs */
debug_process_count++;
}
}
- if(pthread_mutex_unlock(&process_list_mutex) < 0)
- {
+ 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)
+ 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)
+ 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)
+ 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)
+ if (closedir(proc_dir) < 0)
fprintf(stderr, "Could not close /proc/ directory\n");
return DLT_RETURN_OK;
@@ -424,7 +415,7 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon
void *dlt_kpi_start_irq_thread()
{
- if(dlt_kpi_irq_loop() < DLT_RETURN_OK)
+ if (dlt_kpi_irq_loop() < DLT_RETURN_OK)
dlt_kpi_stop_loops(-1);
return NULL;
@@ -436,15 +427,14 @@ DltReturnValue dlt_kpi_irq_loop()
old_millis = get_millis();
- while(!stop_loop)
- {
+ while (!stop_loop) {
/*DltReturnValue ret = */ dlt_kpi_log_interrupts(&kpi_ctx, config.log_level);
- //if(ret < DLT_RETURN_OK)
- // return ret;
+ /*if(ret < DLT_RETURN_OK) */
+ /* return ret; */
dif_millis = get_millis() - old_millis;
- if(dif_millis >= (unsigned long)(config.irq_log_interval))
+ if (dif_millis >= (unsigned long)(config.irq_log_interval))
sleep_millis = 0;
else
sleep_millis = config.irq_log_interval - dif_millis;
@@ -459,7 +449,7 @@ DltReturnValue dlt_kpi_irq_loop()
void *dlt_kpi_start_check_thread()
{
- if(dlt_kpi_check_loop() < DLT_RETURN_OK)
+ if (dlt_kpi_check_loop() < DLT_RETURN_OK)
dlt_kpi_stop_loops(-1);
return NULL;
@@ -471,15 +461,14 @@ DltReturnValue dlt_kpi_check_loop()
old_millis = get_millis();
- while(!stop_loop)
- {
+ while (!stop_loop) {
/*DltReturnValue ret = */ dlt_kpi_log_check_commandlines();
- //if(ret < DLT_RETURN_OK)
- // return ret;
+ /*if(ret < DLT_RETURN_OK) */
+ /* return ret; */
dif_millis = get_millis() - old_millis;
- if(dif_millis >= (unsigned long)(config.check_log_interval))
+ if (dif_millis >= (unsigned long)(config.check_log_interval))
sleep_millis = 0;
else
sleep_millis = config.check_log_interval - dif_millis;
@@ -494,16 +483,14 @@ DltReturnValue dlt_kpi_check_loop()
DltReturnValue dlt_kpi_log_check_commandlines()
{
- if(pthread_mutex_lock(&process_list_mutex) < 0)
- {
+ 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)
- {
+ if (pthread_mutex_unlock(&process_list_mutex) < 0) {
fprintf(stderr, "Can't unlock mutex\n");
return DLT_RETURN_ERROR;
}