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-common.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-common.c')
-rw-r--r-- | src/kpi/dlt-kpi-common.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/kpi/dlt-kpi-common.c b/src/kpi/dlt-kpi-common.c index c0c7767..26c4e28 100644 --- a/src/kpi/dlt-kpi-common.c +++ b/src/kpi/dlt-kpi-common.c @@ -26,6 +26,8 @@ #include "dlt-kpi-common.h" +static int dlt_kpi_cpu_count = -1; + DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target) { char buffer[BUFFER_SIZE]; @@ -66,3 +68,49 @@ DltReturnValue dlt_kpi_read_file(char* filename, char* buffer, uint maxLength) return DLT_RETURN_OK; } + +int dlt_kpi_read_cpu_count() +{ + char buffer[BUFFER_SIZE]; + int ret = dlt_kpi_read_file("/proc/cpuinfo", buffer, sizeof(buffer)); + if(ret != 0) + { + fprintf(stderr, "dlt_kpi_get_cpu_count(): Could not read /proc/cpuinfo\n"); + return -1; + } + + char* delim = "[] \t\n"; + char* tok = strtok(buffer, delim); + if(tok == NULL) + { + fprintf(stderr, "dlt_kpi_get_cpu_count(): Could not extract token\n"); + return -1; + } + + int num = 0; + do + { + if(strcmp(tok, "processor") == 0) + num++; + + tok = strtok(NULL, delim); + } + while(tok != NULL); + + return num; +} + +int dlt_kpi_get_cpu_count() +{ + if(dlt_kpi_cpu_count <= 0) + { + dlt_kpi_cpu_count = dlt_kpi_read_cpu_count(); + if(dlt_kpi_cpu_count <= 0) + { + fprintf(stderr, "Could not get CPU count\n"); + dlt_kpi_cpu_count = -1; + } + } + + return dlt_kpi_cpu_count; +} |