2021-06-23 07:44:56 +00:00
|
|
|
/*
|
|
|
|
htop - PCPDynamicMeter.c
|
|
|
|
(C) 2021 htop dev team
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
(C) 2021 Red Hat, Inc.
|
2021-09-22 09:33:00 +00:00
|
|
|
Released under the GNU GPLv2+, see the COPYING file
|
2021-06-23 07:44:56 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
|
|
|
#include "pcp/PCPDynamicMeter.h"
|
|
|
|
|
2021-08-14 21:30:19 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pcp/pmapi.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "Macros.h"
|
2021-06-23 07:44:56 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
#include "RichString.h"
|
|
|
|
#include "XUtils.h"
|
|
|
|
|
2021-08-14 21:30:19 +00:00
|
|
|
#include "pcp/PCPMetric.h"
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
|
2021-06-23 07:44:56 +00:00
|
|
|
static PCPDynamicMetric* PCPDynamicMeter_lookupMetric(PCPDynamicMeters* meters, PCPDynamicMeter* meter, const char* name) {
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
size_t bytes = 16 + strlen(meter->super.name) + strlen(name);
|
2021-06-23 07:44:56 +00:00
|
|
|
char* metricName = xMalloc(bytes);
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
xSnprintf(metricName, bytes, "htop.meter.%s.%s", meter->super.name, name);
|
2021-06-23 07:44:56 +00:00
|
|
|
|
|
|
|
PCPDynamicMetric* metric;
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
for (size_t i = 0; i < meter->totalMetrics; i++) {
|
2021-06-23 07:44:56 +00:00
|
|
|
metric = &meter->metrics[i];
|
|
|
|
if (String_eq(metric->name, metricName)) {
|
|
|
|
free(metricName);
|
|
|
|
return metric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not an existing metric in this meter - add it */
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
size_t n = meter->totalMetrics + 1;
|
2021-06-23 07:44:56 +00:00
|
|
|
meter->metrics = xReallocArray(meter->metrics, n, sizeof(PCPDynamicMetric));
|
|
|
|
meter->totalMetrics = n;
|
2021-07-14 17:18:27 +00:00
|
|
|
metric = &meter->metrics[n - 1];
|
2021-06-23 07:44:56 +00:00
|
|
|
memset(metric, 0, sizeof(PCPDynamicMetric));
|
|
|
|
metric->name = metricName;
|
2021-07-07 06:57:03 +00:00
|
|
|
metric->label = String_cat(name, ": ");
|
2021-06-23 07:44:56 +00:00
|
|
|
metric->id = meters->offset + meters->cursor;
|
|
|
|
meters->cursor++;
|
|
|
|
|
|
|
|
Platform_addMetric(metric->id, metricName);
|
|
|
|
|
|
|
|
return metric;
|
|
|
|
}
|
|
|
|
|
2021-07-09 02:42:36 +00:00
|
|
|
static void PCPDynamicMeter_parseMetric(PCPDynamicMeters* meters, PCPDynamicMeter* meter, const char* path, unsigned int line, char* key, char* value) {
|
|
|
|
PCPDynamicMetric* metric;
|
2021-06-23 07:44:56 +00:00
|
|
|
char* p;
|
|
|
|
|
|
|
|
if ((p = strchr(key, '.')) == NULL)
|
|
|
|
return;
|
|
|
|
*p++ = '\0'; /* end the name, p is now the attribute, e.g. 'label' */
|
|
|
|
|
|
|
|
if (String_eq(p, "metric")) {
|
|
|
|
/* lookup a dynamic metric with this name, else create */
|
|
|
|
metric = PCPDynamicMeter_lookupMetric(meters, meter, key);
|
|
|
|
|
|
|
|
/* use derived metrics in dynamic meters for simplicity */
|
|
|
|
char* error;
|
|
|
|
if (pmRegisterDerivedMetric(metric->name, value, &error) < 0) {
|
2021-07-07 06:57:03 +00:00
|
|
|
char* note;
|
|
|
|
xAsprintf(¬e,
|
2021-07-12 06:51:19 +00:00
|
|
|
"%s: failed to parse expression in %s at line %u\n%s\n%s",
|
|
|
|
pmGetProgname(), path, line, error, pmGetProgname());
|
2021-06-23 07:44:56 +00:00
|
|
|
free(error);
|
|
|
|
errno = EINVAL;
|
|
|
|
CRT_fatalError(note);
|
2021-07-07 06:57:03 +00:00
|
|
|
free(note);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* this is a property of a dynamic metric - the metric expression */
|
|
|
|
/* may not have been observed yet - i.e. we allow for any ordering */
|
|
|
|
metric = PCPDynamicMeter_lookupMetric(meters, meter, key);
|
|
|
|
if (String_eq(p, "color")) {
|
|
|
|
if (String_eq(value, "gray"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_GRAY;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "darkgray"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_DARKGRAY;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "red"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_RED;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "green"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_GREEN;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "blue"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_BLUE;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "cyan"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_CYAN;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "magenta"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_MAGENTA;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "yellow"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_YELLOW;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(value, "white"))
|
2021-07-14 17:15:09 +00:00
|
|
|
metric->color = DYNAMIC_WHITE;
|
2021-06-23 07:44:56 +00:00
|
|
|
} else if (String_eq(p, "label")) {
|
2021-07-07 06:57:03 +00:00
|
|
|
char* label = String_cat(value, ": ");
|
|
|
|
free_and_xStrdup(&metric->label, label);
|
|
|
|
free(label);
|
2021-06-23 07:44:56 +00:00
|
|
|
} else if (String_eq(p, "suffix")) {
|
|
|
|
free_and_xStrdup(&metric->suffix, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure a valid name for use in a PCP metric name and in htoprc
|
2021-07-12 06:51:19 +00:00
|
|
|
static bool PCPDynamicMeter_validateMeterName(char* key, const char* path, unsigned int line) {
|
2021-06-23 07:44:56 +00:00
|
|
|
char* p = key;
|
|
|
|
char* end = strrchr(key, ']');
|
|
|
|
|
|
|
|
if (end) {
|
|
|
|
*end = '\0';
|
|
|
|
} else {
|
2021-07-12 06:51:19 +00:00
|
|
|
fprintf(stderr,
|
2021-07-14 17:20:16 +00:00
|
|
|
"%s: no closing brace on meter name at %s line %u\n\"%s\"\n",
|
|
|
|
pmGetProgname(), path, line, key);
|
2021-07-12 06:51:19 +00:00
|
|
|
return false;
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
if (p == key) {
|
|
|
|
if (!isalpha(*p) && *p != '_')
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (!isalnum(*p) && *p != '_')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (*p != '\0') { /* badness */
|
2021-07-12 06:51:19 +00:00
|
|
|
fprintf(stderr,
|
2021-07-14 17:20:16 +00:00
|
|
|
"%s: invalid meter name at %s line %u\n\"%s\"\n",
|
|
|
|
pmGetProgname(), path, line, key);
|
2021-07-12 06:51:19 +00:00
|
|
|
return false;
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
2021-07-12 06:51:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure a meter name has not been defined previously
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
static bool PCPDynamicMeter_uniqueName(char* key, PCPDynamicMeters* meters) {
|
|
|
|
return !DynamicMeter_search(meters->table, key, NULL);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PCPDynamicMeter* PCPDynamicMeter_new(PCPDynamicMeters* meters, const char* name) {
|
|
|
|
PCPDynamicMeter* meter = xCalloc(1, sizeof(*meter));
|
|
|
|
String_safeStrncpy(meter->super.name, name, sizeof(meter->super.name));
|
|
|
|
Hashtable_put(meters->table, ++meters->count, meter);
|
|
|
|
return meter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PCPDynamicMeter_parseFile(PCPDynamicMeters* meters, const char* path) {
|
|
|
|
FILE* file = fopen(path, "r");
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PCPDynamicMeter* meter = NULL;
|
|
|
|
unsigned int lineno = 0;
|
2021-07-12 06:51:19 +00:00
|
|
|
bool ok = true;
|
2021-06-23 07:44:56 +00:00
|
|
|
for (;;) {
|
|
|
|
char* line = String_readLine(file);
|
|
|
|
if (!line)
|
|
|
|
break;
|
|
|
|
lineno++;
|
|
|
|
|
|
|
|
/* cleanup whitespace, skip comment lines */
|
|
|
|
char* trimmed = String_trim(line);
|
|
|
|
free(line);
|
|
|
|
if (trimmed[0] == '#' || trimmed[0] == '\0') {
|
|
|
|
free(trimmed);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t n;
|
|
|
|
char** config = String_split(trimmed, '=', &n);
|
|
|
|
free(trimmed);
|
|
|
|
if (config == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char* key = String_trim(config[0]);
|
|
|
|
char* value = n > 1 ? String_trim(config[1]) : NULL;
|
|
|
|
if (key[0] == '[') { /* new section heading - i.e. new meter */
|
2021-07-14 17:18:27 +00:00
|
|
|
ok = PCPDynamicMeter_validateMeterName(key + 1, path, lineno);
|
2021-07-12 06:51:19 +00:00
|
|
|
if (ok)
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
ok = PCPDynamicMeter_uniqueName(key + 1, meters);
|
2021-07-12 06:51:19 +00:00
|
|
|
if (ok)
|
2021-07-14 17:18:27 +00:00
|
|
|
meter = PCPDynamicMeter_new(meters, key + 1);
|
2021-07-12 06:51:19 +00:00
|
|
|
} else if (!ok) {
|
|
|
|
; /* skip this one, we're looking for a new header */
|
2021-07-12 07:01:40 +00:00
|
|
|
} else if (value && meter && String_eq(key, "caption")) {
|
2021-07-07 06:57:03 +00:00
|
|
|
char* caption = String_cat(value, ": ");
|
2021-07-12 07:01:40 +00:00
|
|
|
if (caption) {
|
|
|
|
free_and_xStrdup(&meter->super.caption, caption);
|
|
|
|
free(caption);
|
2021-07-14 07:08:36 +00:00
|
|
|
caption = NULL;
|
2021-07-12 07:01:40 +00:00
|
|
|
}
|
|
|
|
} else if (value && meter && String_eq(key, "description")) {
|
2021-06-23 07:44:56 +00:00
|
|
|
free_and_xStrdup(&meter->super.description, value);
|
2021-07-12 07:01:40 +00:00
|
|
|
} else if (value && meter && String_eq(key, "type")) {
|
2021-06-23 07:44:56 +00:00
|
|
|
if (String_eq(config[1], "bar"))
|
2021-07-14 17:15:09 +00:00
|
|
|
meter->super.type = BAR_METERMODE;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(config[1], "text"))
|
2021-07-14 17:15:09 +00:00
|
|
|
meter->super.type = TEXT_METERMODE;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(config[1], "graph"))
|
2021-07-14 17:15:09 +00:00
|
|
|
meter->super.type = GRAPH_METERMODE;
|
2021-06-23 07:44:56 +00:00
|
|
|
else if (String_eq(config[1], "led"))
|
2021-07-14 17:15:09 +00:00
|
|
|
meter->super.type = LED_METERMODE;
|
2021-07-12 07:01:40 +00:00
|
|
|
} else if (value && meter && String_eq(key, "maximum")) {
|
2021-06-23 07:44:56 +00:00
|
|
|
meter->super.maximum = strtod(value, NULL);
|
2021-07-12 07:01:40 +00:00
|
|
|
} else if (value && meter) {
|
2021-06-23 07:44:56 +00:00
|
|
|
PCPDynamicMeter_parseMetric(meters, meter, path, lineno, key, value);
|
|
|
|
}
|
|
|
|
String_freeArray(config);
|
|
|
|
free(value);
|
|
|
|
free(key);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PCPDynamicMeter_scanDir(PCPDynamicMeters* meters, char* path) {
|
|
|
|
DIR* dir = opendir(path);
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
2021-07-09 02:42:36 +00:00
|
|
|
struct dirent* dirent;
|
2021-06-23 07:44:56 +00:00
|
|
|
while ((dirent = readdir(dir)) != NULL) {
|
|
|
|
if (dirent->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
|
2021-07-09 02:42:36 +00:00
|
|
|
char* file = String_cat(path, dirent->d_name);
|
2021-06-23 07:44:56 +00:00
|
|
|
PCPDynamicMeter_parseFile(meters, file);
|
|
|
|
free(file);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCPDynamicMeters_init(PCPDynamicMeters* meters) {
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
const char* share = pmGetConfig("PCP_SHARE_DIR");
|
2021-06-23 07:44:56 +00:00
|
|
|
const char* sysconf = pmGetConfig("PCP_SYSCONF_DIR");
|
|
|
|
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
const char* override = getenv("PCP_HTOP_DIR");
|
2021-06-23 07:44:56 +00:00
|
|
|
const char* home = getenv("HOME");
|
|
|
|
char* path;
|
|
|
|
|
|
|
|
meters->table = Hashtable_new(0, true);
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
/* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */
|
|
|
|
if (override) {
|
|
|
|
path = String_cat(override, "/meters/");
|
|
|
|
PCPDynamicMeter_scanDir(meters, path);
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next, search in home directory alongside htoprc */
|
|
|
|
if (xdgConfigHome)
|
2021-06-23 07:44:56 +00:00
|
|
|
path = String_cat(xdgConfigHome, "/htop/meters/");
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
else if (home)
|
2021-06-23 07:44:56 +00:00
|
|
|
path = String_cat(home, "/.config/htop/meters/");
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
else
|
|
|
|
path = NULL;
|
|
|
|
if (path) {
|
|
|
|
PCPDynamicMeter_scanDir(meters, path);
|
|
|
|
free(path);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
/* next, search in the system meters directory */
|
2021-06-23 07:44:56 +00:00
|
|
|
path = String_cat(sysconf, "/htop/meters/");
|
|
|
|
PCPDynamicMeter_scanDir(meters, path);
|
|
|
|
free(path);
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
/* next, try the readonly system meters directory */
|
|
|
|
path = String_cat(share, "/htop/meters/");
|
|
|
|
PCPDynamicMeter_scanDir(meters, path);
|
|
|
|
free(path);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:11:31 +00:00
|
|
|
static void PCPDynamicMeter_free(ATTR_UNUSED ht_key_t key, void* value, ATTR_UNUSED void* data) {
|
|
|
|
PCPDynamicMeter* meter = (PCPDynamicMeter*) value;
|
|
|
|
for (size_t i = 0; i < meter->totalMetrics; i++) {
|
|
|
|
free(meter->metrics[i].name);
|
|
|
|
free(meter->metrics[i].label);
|
|
|
|
free(meter->metrics[i].suffix);
|
|
|
|
}
|
|
|
|
free(meter->metrics);
|
|
|
|
free(meter->super.caption);
|
|
|
|
free(meter->super.description);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCPDynamicMeters_done(Hashtable* table) {
|
|
|
|
Hashtable_foreach(table, PCPDynamicMeter_free, NULL);
|
|
|
|
}
|
|
|
|
|
2021-06-23 07:44:56 +00:00
|
|
|
void PCPDynamicMeter_enable(PCPDynamicMeter* this) {
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
for (size_t i = 0; i < this->totalMetrics; i++)
|
2021-08-14 21:30:19 +00:00
|
|
|
PCPMetric_enable(this->metrics[i].id, true);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCPDynamicMeter_updateValues(PCPDynamicMeter* this, Meter* meter) {
|
|
|
|
char* buffer = meter->txtBuffer;
|
|
|
|
size_t size = sizeof(meter->txtBuffer);
|
|
|
|
size_t bytes = 0;
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
for (size_t i = 0; i < this->totalMetrics; i++) {
|
2021-06-23 07:44:56 +00:00
|
|
|
if (i > 0 && bytes < size - 1)
|
|
|
|
buffer[bytes++] = '/'; /* separator */
|
|
|
|
|
|
|
|
PCPDynamicMetric* metric = &this->metrics[i];
|
2021-08-14 21:30:19 +00:00
|
|
|
const pmDesc* desc = PCPMetric_desc(metric->id);
|
2021-07-07 06:57:03 +00:00
|
|
|
pmAtomValue atom, raw;
|
2021-06-23 07:44:56 +00:00
|
|
|
|
2021-08-14 21:30:19 +00:00
|
|
|
if (!PCPMetric_values(metric->id, &raw, 1, desc->type)) {
|
2021-06-23 07:44:56 +00:00
|
|
|
bytes--; /* clear the separator */
|
|
|
|
continue;
|
|
|
|
}
|
2021-07-07 06:57:03 +00:00
|
|
|
|
|
|
|
pmUnits conv = desc->units; /* convert to canonical units */
|
|
|
|
if (conv.dimSpace)
|
|
|
|
conv.scaleSpace = PM_SPACE_KBYTE;
|
|
|
|
if (conv.dimTime)
|
|
|
|
conv.scaleTime = PM_TIME_SEC;
|
|
|
|
if (desc->type == PM_TYPE_STRING)
|
|
|
|
atom = raw;
|
|
|
|
else if (pmConvScale(desc->type, &raw, &desc->units, &atom, &conv) < 0) {
|
|
|
|
bytes--; /* clear the separator */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t saved = bytes;
|
2021-06-23 07:44:56 +00:00
|
|
|
switch (desc->type) {
|
|
|
|
case PM_TYPE_STRING:
|
|
|
|
bytes += xSnprintf(buffer + bytes, size - bytes, "%s", atom.cp);
|
|
|
|
free(atom.cp);
|
|
|
|
break;
|
|
|
|
case PM_TYPE_32:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.l, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%d", atom.l);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_U32:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.ul, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%u", atom.ul);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_64:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.ll, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%lld", (long long) atom.ll);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_U64:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.ull, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%llu", (unsigned long long) atom.ull);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_FLOAT:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.f, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%.2f", (double) atom.f);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_DOUBLE:
|
2021-07-07 06:57:03 +00:00
|
|
|
bytes += conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer + bytes, atom.d, size - bytes) :
|
|
|
|
xSnprintf(buffer + bytes, size - bytes, "%.2f", atom.d);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-07-07 06:57:03 +00:00
|
|
|
if (saved != bytes && metric->suffix)
|
|
|
|
bytes += xSnprintf(buffer + bytes, size - bytes, "%s", metric->suffix);
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
if (!bytes)
|
|
|
|
xSnprintf(buffer, size, "no data");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCPDynamicMeter_display(PCPDynamicMeter* this, ATTR_UNUSED const Meter* meter, RichString* out) {
|
|
|
|
int nodata = 1;
|
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
for (size_t i = 0; i < this->totalMetrics; i++) {
|
2021-06-23 07:44:56 +00:00
|
|
|
PCPDynamicMetric* metric = &this->metrics[i];
|
2021-08-14 21:30:19 +00:00
|
|
|
const pmDesc* desc = PCPMetric_desc(metric->id);
|
2021-07-07 06:57:03 +00:00
|
|
|
pmAtomValue atom, raw;
|
2021-06-23 07:44:56 +00:00
|
|
|
char buffer[64];
|
|
|
|
|
2021-08-14 21:30:19 +00:00
|
|
|
if (!PCPMetric_values(metric->id, &raw, 1, desc->type))
|
2021-06-23 07:44:56 +00:00
|
|
|
continue;
|
2021-07-07 06:57:03 +00:00
|
|
|
|
|
|
|
pmUnits conv = desc->units; /* convert to canonical units */
|
|
|
|
if (conv.dimSpace)
|
|
|
|
conv.scaleSpace = PM_SPACE_KBYTE;
|
|
|
|
if (conv.dimTime)
|
|
|
|
conv.scaleTime = PM_TIME_SEC;
|
|
|
|
if (desc->type == PM_TYPE_STRING)
|
|
|
|
atom = raw;
|
|
|
|
else if (pmConvScale(desc->type, &raw, &desc->units, &atom, &conv) < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nodata = 0; /* we will use this metric so *some* data will be added */
|
2021-06-23 07:44:56 +00:00
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
RichString_appendnAscii(out, CRT_colors[metric->color], " ", 1);
|
|
|
|
|
2021-07-07 06:57:03 +00:00
|
|
|
if (metric->label)
|
|
|
|
RichString_appendAscii(out, CRT_colors[METER_TEXT], metric->label);
|
2021-06-23 07:44:56 +00:00
|
|
|
|
2021-07-07 06:57:03 +00:00
|
|
|
int len = 0;
|
2021-06-23 07:44:56 +00:00
|
|
|
switch (desc->type) {
|
|
|
|
case PM_TYPE_STRING:
|
|
|
|
len = xSnprintf(buffer, sizeof(buffer), "%s", atom.cp);
|
|
|
|
free(atom.cp);
|
|
|
|
break;
|
|
|
|
case PM_TYPE_32:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.l, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%d", atom.l);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_U32:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.ul, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%u", atom.ul);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_64:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.ll, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%lld", (long long) atom.ll);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_U64:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.ull, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%llu", (unsigned long long) atom.ull);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_FLOAT:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.f, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f", (double) atom.f);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
case PM_TYPE_DOUBLE:
|
2021-07-07 06:57:03 +00:00
|
|
|
len = conv.dimSpace ?
|
|
|
|
Meter_humanUnit(buffer, atom.d, sizeof(buffer)) :
|
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f", atom.d);
|
2021-06-23 07:44:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-07-07 06:57:03 +00:00
|
|
|
if (len) {
|
2021-06-23 07:44:56 +00:00
|
|
|
RichString_appendnAscii(out, CRT_colors[metric->color], buffer, len);
|
2021-07-07 06:57:03 +00:00
|
|
|
if (metric->suffix)
|
|
|
|
RichString_appendAscii(out, CRT_colors[METER_TEXT], metric->suffix);
|
|
|
|
}
|
2021-06-23 07:44:56 +00:00
|
|
|
}
|
|
|
|
if (nodata)
|
|
|
|
RichString_writeAscii(out, CRT_colors[METER_VALUE_ERROR], "no data");
|
|
|
|
}
|