diff options
author | Sven Hassler <sven_hassler@mentor.com> | 2015-12-10 13:22:27 +0100 |
---|---|---|
committer | Lutz Helwing <lutz_helwing@mentor.com> | 2015-12-16 17:20:39 +0100 |
commit | ba46036d828fcd5f79ab7609025007b3dba46aee (patch) | |
tree | 0dd678966a0a3d2a4b5da8129f1c495ba99fba7e /src/kpi/dlt-kpi-process.c | |
parent | 77400754611a8e7982a7ee3c4816ee5f070c0dca (diff) | |
download | DLT-daemon-ba46036d828fcd5f79ab7609025007b3dba46aee.tar.gz |
Added documentation, bugfixes, improvements
- Added dlt-kpi.txt as asciidoc document.
- Fixed a bug where extremely high CPU- and IO-Wait times were
calculated.
- CPU- and IO-Wait time are now being divided by CPU count.
Diffstat (limited to 'src/kpi/dlt-kpi-process.c')
-rw-r--r-- | src/kpi/dlt-kpi-process.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/kpi/dlt-kpi-process.c b/src/kpi/dlt-kpi-process.c index d126551..168adf7 100644 --- a/src/kpi/dlt-kpi-process.c +++ b/src/kpi/dlt-kpi-process.c @@ -43,9 +43,11 @@ DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned l unsigned long int total_io_wait = dlt_kpi_read_process_stat_to_ulong(process->pid, 42); + 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) - process->io_wait = process->io_wait * 1000 / time_dif_ms; // busy milliseconds per second + 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; @@ -65,9 +67,16 @@ DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned 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 + 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 + } + else + process->cpu_time = 0; process->last_cpu_time = total_cpu_time; @@ -319,13 +328,14 @@ unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int ind } char *buffer = NULL; - DltReturnValue tmp = dlt_kpi_read_process_file_to_str(pid, &buffer, "stat"); - if(tmp < DLT_RETURN_OK) + 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 tmp; + return 0; } char *tok = strtok(buffer, " \t\n"); |