summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-01-31 00:52:08 -0200
committerHisham Muhammad <hisham@gobolinux.org>2018-02-04 08:57:35 +0100
commit36d5018c0c3802ce430137f08ad72928cc92c03b (patch)
tree97390322379ce26dce198e734116e79cf60b877a /Process.c
parentf8d6560d714c99b010aeadee09924d636c83cd02 (diff)
Implemented various performance counters
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/Process.c b/Process.c
index e08ea93b..6ec0d386 100644
--- a/Process.c
+++ b/Process.c
@@ -28,6 +28,7 @@ in the source distribution for its full text.
#include <time.h>
#include <assert.h>
#include <math.h>
+#include <inttypes.h>
#ifdef __ANDROID__
#define SYS_ioprio_get __NR_ioprio_get
@@ -150,7 +151,7 @@ typedef struct ProcessFieldData_ {
const char* name;
const char* title;
const char* description;
- int flags;
+ uint64_t flags;
} ProcessFieldData;
// Implemented in platform-specific code:
@@ -360,6 +361,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];
@@ -368,24 +384,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];

© 2014-2024 Faster IT GmbH | imprint | privacy policy