diff options
author | Ran Benita <ran234@gmail.com> | 2019-02-11 20:04:12 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2019-02-13 22:38:10 +0200 |
commit | 08feb8585bb4aa4bb9b1cc0025a57658f95ef437 (patch) | |
tree | 44ab24516bba2056178283295581b29cf2b54816 /linux | |
parent | 402e46bb82964366746b86d77eb5afa69c279539 (diff) |
Add pressure stall information (PSI) meters on Linux
The pressure stall information (PSI) metrics provide useful information
on delays caused by waiting for CPU, IO and memory. Particularly on busy
servers it can provide a quick overview of what's "slowing things down".
This feature is supported on Linux >= 4.20.
The interface is documented here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/accounting/psi.txt
These links provide rationale:
https://lwn.net/Articles/759781/
https://facebookmicrosites.github.io/psi/
The following metrics are added, corresponding to the currently exposed
lines (see `head /proc/pressure/*`):
- PressureStallCPUSome
- PressureStallIOSome
- PressureStallIOFull
- PressureStallMemorySome
- PressureStallMemoryFull
The color scheme is the same as that used for Load Average, however I
gave it separate entries just in case someone wants to change them
specifically.
Tested on 4.20.7-arch1-1-ARCH, on the linux platform.
Also tested that other platforms still compile (changed configure to use
the unsupported platform).
Closes #879.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/Platform.c | 24 | ||||
-rw-r--r-- | linux/Platform.h | 2 | ||||
-rw-r--r-- | linux/PressureStallMeter.c | 133 | ||||
-rw-r--r-- | linux/PressureStallMeter.h | 25 |
4 files changed, 184 insertions, 0 deletions
diff --git a/linux/Platform.c b/linux/Platform.c index ab90ca74..45582f91 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "UptimeMeter.h" +#include "PressureStallMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" #include "LinuxProcess.h" @@ -126,6 +127,11 @@ MeterClass* Platform_meterTypes[] = { &LeftCPUs2Meter_class, &RightCPUs2Meter_class, &BlankMeter_class, + &PressureStallCPUSomeMeter_class, + &PressureStallIOSomeMeter_class, + &PressureStallIOFullMeter_class, + &PressureStallMemorySomeMeter_class, + &PressureStallMemoryFullMeter_class, NULL }; @@ -237,3 +243,21 @@ char* Platform_getProcessEnv(pid_t pid) { } return env; } + +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { + *ten = *sixty = *threehundred = 0; + char procname[128+1]; + xSnprintf(procname, 128, PROCDIR "/pressure/%s", file); + FILE *fd = fopen(procname, "r"); + if (!fd) { + *ten = *sixty = *threehundred = NAN; + return; + } + int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + if (!some) { + total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); + } + (void) total; + assert(total == 3); + fclose(fd); +} diff --git a/linux/Platform.h b/linux/Platform.h index b0456e5b..129bc07b 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -45,4 +45,6 @@ void Platform_setSwapValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); +void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); + #endif diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c new file mode 100644 index 00000000..56055bff --- /dev/null +++ b/linux/PressureStallMeter.c @@ -0,0 +1,133 @@ +/* +htop - PressureStallMeter.c +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "PressureStallMeter.h" +#include "Platform.h" +#include "CRT.h" + +#include <string.h> + +/*{ +#include "Meter.h" +}*/ + +static int PressureStallMeter_attributes[] = { + PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED +}; + +static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { + const char *file; + if (strstr(Meter_name(this), "CPU")) { + file = "cpu"; + } else if (strstr(Meter_name(this), "IO")) { + file = "io"; + } else { + file = "memory"; + } + + bool some; + if (strstr(Meter_name(this), "Some")) { + some = true; + } else { + some = false; + } + + Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); + xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); +} + +static void PressureStallMeter_display(Object* cast, RichString* out) { + Meter* this = (Meter*)cast; + char buffer[20]; + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]); + RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]); + RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer); + xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]); + RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer); +} + +MeterClass PressureStallCPUSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallCPUSome", + .uiName = "Pressure Stall Information, some CPU", + .caption = "Some CPU pressure: " +}; + +MeterClass PressureStallIOSomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOSome", + .uiName = "Pressure Stall Information, some IO", + .caption = "Some IO pressure: " +}; + +MeterClass PressureStallIOFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallIOFull", + .uiName = "Pressure Stall Information, full IO", + .caption = "Full IO pressure: " +}; + +MeterClass PressureStallMemorySomeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemorySome", + .uiName = "Pressure Stall Information, some memory", + .caption = "Some Mem pressure: " +}; + +MeterClass PressureStallMemoryFullMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = PressureStallMeter_display, + }, + .updateValues = PressureStallMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 3, + .total = 100.0, + .attributes = PressureStallMeter_attributes, + .name = "PressureStallMemoryFull", + .uiName = "Pressure Stall Information, full memory", + .caption = "Full Mem pressure: " +}; diff --git a/linux/PressureStallMeter.h b/linux/PressureStallMeter.h new file mode 100644 index 00000000..22b8b972 --- /dev/null +++ b/linux/PressureStallMeter.h @@ -0,0 +1,25 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_PressureStallMeter +#define HEADER_PressureStallMeter +/* +htop - PressureStallMeter.h +(C) 2004-2011 Hisham H. Muhammad +(C) 2019 Ran Benita +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern MeterClass PressureStallCPUSomeMeter_class; + +extern MeterClass PressureStallIOSomeMeter_class; + +extern MeterClass PressureStallIOFullMeter_class; + +extern MeterClass PressureStallMemorySomeMeter_class; + +extern MeterClass PressureStallMemoryFullMeter_class; + +#endif |