diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-01-31 00:52:08 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-02-26 20:13:09 -0300 |
commit | a72439c9b73fbd6255dcec844332356ab3028a6d (patch) | |
tree | 93f8c5ff55d68349a6f650491f2c3e85f98bfc1f /Process.c | |
parent | 61e94c1b5b32a8c4c6db1c8037412ac1ac727833 (diff) |
Implemented various performance counters
Diffstat (limited to 'Process.c')
-rw-r--r-- | Process.c | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -34,6 +34,7 @@ in the source distribution for its full text. (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) #include <sys/sysmacros.h> #endif +#include <inttypes.h> #ifdef __ANDROID__ #define SYS_ioprio_get __NR_ioprio_get @@ -156,7 +157,7 @@ typedef struct ProcessFieldData_ { const char* name; const char* title; const char* description; - int flags; + uint64_t flags; } ProcessFieldData; // Implemented in platform-specific code: @@ -368,6 +369,21 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c } } +void Process_printPercentage(float val, char* buffer, int n, int* attr) { + if (val >= 0) { + if (val < 100) { + xSnprintf(buffer, n, "%4.1f ", val); + } else if (val < 1000) { + xSnprintf(buffer, n, "%3d. ", (unsigned int)val); + } else { + xSnprintf(buffer, n, "%4d ", (unsigned int)val); + } + } else { + *attr = CRT_colors[PROCESS_SHADOW]; + xSnprintf(buffer, n, " N/A "); + } +} + void Process_writeField(Process* this, RichString* str, ProcessField field) { char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; @@ -376,24 +392,8 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { bool coloring = this->settings->highlightMegabytes; switch (field) { - case PERCENT_CPU: { - if (this->percent_cpu > 999.9) { - xSnprintf(buffer, n, "%4d ", (unsigned int)this->percent_cpu); - } else if (this->percent_cpu > 99.9) { - xSnprintf(buffer, n, "%3d. ", (unsigned int)this->percent_cpu); - } else { - xSnprintf(buffer, n, "%4.1f ", this->percent_cpu); - } - break; - } - case PERCENT_MEM: { - if (this->percent_mem > 99.9) { - xSnprintf(buffer, n, "100. "); - } else { - xSnprintf(buffer, n, "%4.1f ", this->percent_mem); - } - break; - } + case PERCENT_CPU: Process_printPercentage(this->percent_cpu, buffer, n, &attr); break; + case PERCENT_MEM: Process_printPercentage(this->percent_mem, buffer, n, &attr); break; case COMM: { if (this->settings->highlightThreads && Process_isThread(this)) { attr = CRT_colors[PROCESS_THREAD]; |