From dca8ab254aa0a687c32009079d85e4d8f960b213 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Thu, 20 Dec 2018 14:58:19 +0100 Subject: Code beautification using uncrustify Signed-off-by: Christoph Lipka --- src/kpi/dlt-kpi-process.c | 233 ++++++++++++++++++++++------------------------ 1 file changed, 109 insertions(+), 124 deletions(-) (limited to 'src/kpi/dlt-kpi-process.c') diff --git a/src/kpi/dlt-kpi-process.c b/src/kpi/dlt-kpi-process.c index 22a46e6..062a667 100644 --- a/src/kpi/dlt-kpi-process.c +++ b/src/kpi/dlt-kpi-process.c @@ -35,8 +35,7 @@ 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) - { + if (process == NULL) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -45,9 +44,10 @@ DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned l int cpu_count = dlt_kpi_get_cpu_count(); - 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 && cpu_count > 0) - process->io_wait = process->io_wait * 1000 / time_dif_ms / cpu_count; // busy milliseconds per second per CPU + 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) && (cpu_count > 0)) + process->io_wait = process->io_wait * 1000 / time_dif_ms / cpu_count; /* busy milliseconds per second per CPU */ process->last_io_wait = total_io_wait; @@ -56,8 +56,7 @@ DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned l DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned long int time_dif_ms) { - if(process == NULL) - { + if (process == NULL) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -67,16 +66,18 @@ DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned unsigned long total_cpu_time = utime + stime; - if(process->last_cpu_time > 0 && process->last_cpu_time <= total_cpu_time) - { + if ((process->last_cpu_time > 0) && (process->last_cpu_time <= total_cpu_time)) { int cpu_count = dlt_kpi_get_cpu_count(); - 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 && cpu_count > 0) - process->cpu_time = process->cpu_time * 1000 / time_dif_ms / cpu_count; // busy milliseconds per second per CPU + 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) && (cpu_count > 0)) + process->cpu_time = process->cpu_time * 1000 / time_dif_ms / cpu_count; /* busy milliseconds per second per CPU */ + } - else + else { process->cpu_time = 0; + } process->last_cpu_time = total_cpu_time; @@ -85,9 +86,8 @@ DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned DltReturnValue dlt_kpi_process_update_rss(DltKpiProcess *process) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -98,9 +98,8 @@ DltReturnValue dlt_kpi_process_update_rss(DltKpiProcess *process) DltReturnValue dlt_kpi_process_update_ctx_switches(DltKpiProcess *process) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -109,22 +108,21 @@ DltReturnValue dlt_kpi_process_update_ctx_switches(DltKpiProcess *process) last_tok = NULL; DltReturnValue ret; - if((ret = dlt_kpi_read_process_file_to_str(process->pid, &buffer, "status")) < DLT_RETURN_OK) return 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) - { + + 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') - { + if (*chk != '\0') { fprintf(stderr, "Could not parse ctx_switches info from /proc/%d/status", process->pid); free(buffer); return DLT_RETURN_ERROR; @@ -143,9 +141,8 @@ DltReturnValue dlt_kpi_process_update_ctx_switches(DltKpiProcess *process) DltReturnValue dlt_kpi_process_update_io_bytes(DltKpiProcess *process) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -154,23 +151,21 @@ DltReturnValue dlt_kpi_process_update_io_bytes(DltKpiProcess *process) last_tok = NULL; DltReturnValue ret; - if((ret = dlt_kpi_read_process_file_to_str(process->pid, &buffer, "io")) < DLT_RETURN_OK) + + 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) - { + + 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') - { + if (*chk != '\0') { fprintf(stderr, "Could not parse io_bytes info from /proc/%d/io", process->pid); free(buffer); return DLT_RETURN_ERROR; @@ -190,9 +185,8 @@ DltReturnValue dlt_kpi_process_update_io_bytes(DltKpiProcess *process) DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -208,9 +202,9 @@ DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int DltKpiProcess *dlt_kpi_create_process(int pid) { DltKpiProcess *new_process = malloc(sizeof(DltKpiProcess)); - if(new_process == NULL) - { - fprintf(stderr, "%s: Out of Memory \n", __func__); + + if (new_process == NULL) { + fprintf(stderr, "%s: Out of Memory \n", __func__); return NULL; } @@ -220,9 +214,9 @@ DltKpiProcess *dlt_kpi_create_process(int 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) - { + + 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)); } @@ -234,35 +228,35 @@ DltKpiProcess *dlt_kpi_create_process(int pid) DltKpiProcess *dlt_kpi_clone_process(DltKpiProcess *original) { - if(original == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (original == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return NULL; } - // DltKpiProcess *new_process = dlt_kpi_create_process(original->pid); + /* DltKpiProcess *new_process = dlt_kpi_create_process(original->pid); */ DltKpiProcess *new_process = malloc(sizeof(DltKpiProcess)); - if(new_process == NULL) - { - fprintf(stderr, "%s: Out of Memory\n", __func__); + + if (new_process == NULL) { + fprintf(stderr, "%s: Out of Memory\n", __func__); return NULL; } memcpy(new_process, original, sizeof(DltKpiProcess)); - if(original->command_line != NULL) - { + if (original->command_line != NULL) { new_process->command_line = malloc(strlen(original->command_line) + 1); - if(new_process->command_line == NULL) - { + + if (new_process->command_line == NULL) { fprintf(stderr, "%s: Out of Memory\n", __func__); free(new_process); return NULL; } + strncpy(new_process->command_line, original->command_line, strlen(original->command_line) + 1); } - else + else { new_process->command_line = NULL; + } new_process->next = new_process->prev = NULL; @@ -271,13 +265,12 @@ DltKpiProcess *dlt_kpi_clone_process(DltKpiProcess *original) DltReturnValue dlt_kpi_free_process(DltKpiProcess *process) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if(process->command_line != NULL) + if (process->command_line != NULL) free(process->command_line); free(process); @@ -287,9 +280,8 @@ DltReturnValue dlt_kpi_free_process(DltKpiProcess *process) DltReturnValue dlt_kpi_print_process(DltKpiProcess *process) { - if(process == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (process == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -307,23 +299,20 @@ DltReturnValue dlt_kpi_print_process(DltKpiProcess *process) DltReturnValue dlt_kpi_read_process_file_to_str(pid_t pid, char **target_str, char *subdir) { - if(target_str == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (target_str == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_ERROR; } *target_str = NULL; - if(pid <= 0) - { - fprintf(stderr, "%s: Invalid Parameter (PID)\n", __func__); + if (pid <= 0) { + fprintf(stderr, "%s: Invalid Parameter (PID)\n", __func__); return DLT_RETURN_ERROR; } - if(subdir == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (subdir == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_ERROR; } @@ -335,18 +324,17 @@ DltReturnValue dlt_kpi_read_process_file_to_str(pid_t pid, char **target_str, ch unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int index) { - if(pid <= 0) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (pid <= 0) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return 0; } char *buffer = NULL; - if(dlt_kpi_read_process_file_to_str(pid, &buffer, "stat") < DLT_RETURN_OK) - { - // fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Error while reading process stat file. Pid: %d. Requested index: %u\n", pid, index); // can happen if process closed shortly before - if(buffer != NULL) + if (dlt_kpi_read_process_file_to_str(pid, &buffer, "stat") < DLT_RETURN_OK) { + /* fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Error while reading process stat file. Pid: %d. Requested index: %u\n", pid, index); // can happen if process closed shortly before */ + + if (buffer != NULL) free(buffer); return 0; @@ -355,31 +343,30 @@ unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int ind char *tok = strtok(buffer, " \t\n"); unsigned int i = 1, found = 0; - while(tok != NULL) - { - if(i == index) - { + while (tok != NULL) { + if (i == index) { found = 1; break; } + i++; tok = strtok(NULL, " \t\n"); } unsigned long int ret = 0; - if(found) - { + if (found) { char *check = NULL; ret = strtoul(tok, &check, 10); - if(*check != '\0') - { + + if (*check != '\0') { fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Could not extract token\n"); ret = 0; } } - else + else { fprintf(stderr, "dlt_kpi_read_process_stat_to_ulong(): Index not found\n"); + } free(buffer); @@ -388,23 +375,21 @@ unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int ind DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer) { - if(pid <= 0) - { - fprintf(stderr, "%s: Invalid Parameter (PID)\n", __func__); + if (pid <= 0) { + fprintf(stderr, "%s: Invalid Parameter (PID)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if(buffer == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if (buffer == NULL) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); 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) + + if (tmp < DLT_RETURN_OK) { + if (tmp_buffer != NULL) free(tmp_buffer); return tmp; @@ -413,23 +398,19 @@ DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer) char *tok = strtok(tmp_buffer, " \t\n"); unsigned int i = 1; - while(tok != NULL) - { - if(i == 2) - { + while (tok != NULL) { + if (i == 2) break; - } + i++; tok = strtok(NULL, " \t\n"); } - if(i == 2) - { + if (i == 2) { (*buffer) = malloc(strlen(tok) + 1); strncpy(*buffer, tok, strlen(tok) + 1); } - else - { + else { fprintf(stderr, "dlt_kpi_read_process_stat_cmdline(): cmdline entry not found\n"); return DLT_RETURN_ERROR; } @@ -441,22 +422,28 @@ DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer) DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen) { - if(process == NULL || buffer == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if ((process == NULL) || (buffer == NULL)) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); 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); + 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, "%s: Invalid Parameter (NULL)\n", __func__); + if ((process == NULL) || (buffer == NULL)) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -467,9 +454,8 @@ DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen) { - if(process == NULL || buffer == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if ((process == NULL) || (buffer == NULL)) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -480,9 +466,8 @@ DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen) { - if(process == NULL || buffer == NULL) - { - fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); + if ((process == NULL) || (buffer == NULL)) { + fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } -- cgit v1.2.1