diff options
author | Ingo Bürk <admin@airblader.de> | 2018-07-13 15:17:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-13 15:17:51 +0200 |
commit | fc9da67e65819cb14071db4fd5b7941ab01a1134 (patch) | |
tree | 5f6ab7b574e6fad71cdd2d8ac21c19ba0768d936 /src/print_cpu_usage.c | |
parent | 9aafc38370e5f2b337643d22aa04f4d34208fb03 (diff) | |
parent | 52e9f6f63b74db2a6a1d67524851649b18794950 (diff) |
Merge pull request #297 from Stunkymonkey/percent-first
able to print percentage
Diffstat (limited to 'src/print_cpu_usage.c')
-rw-r--r-- | src/print_cpu_usage.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index c1ea3fd..615fe5d 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -144,15 +144,13 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const for (walk = selected_format; *walk != '\0'; walk++) { if (*walk != '%') { *(outwalk++) = *walk; - continue; - } - if (BEGINS_WITH(walk + 1, "usage")) { + } else if (BEGINS_WITH(walk + 1, "usage")) { outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark); walk += strlen("usage"); } #if defined(LINUX) - if (BEGINS_WITH(walk + 1, "cpu")) { + else if (BEGINS_WITH(walk + 1, "cpu")) { int number = 0; sscanf(walk + 1, "cpu%d", &number); if (number < 0 || number >= cpu_count) { @@ -172,6 +170,9 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const walk += strlen("cpu") + padding; } #endif + else { + *(outwalk++) = '%'; + } } for (int i = 0; i < cpu_count; i++) |