summaryrefslogtreecommitdiffstats
path: root/DynamicMeter.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2021-07-07 16:57:03 +1000
committerNathan Scott <nathans@redhat.com>2021-07-08 10:56:05 +1000
commit01f5b892785014db30db4d6b4b7c23e042c7ffe4 (patch)
tree785c3eec2534ed4654cfda34b3780c91e01372d7 /DynamicMeter.c
parent149774209be588fb0da001e5d9cac224862cc5da (diff)
Pretty-print values in the PCP DynamicMeter code
Several improvements to the way values are displayed in the PCP platform DynamicMeter implementation: - handle the initial 'caption' setting as with regular meters, this required a new meter callback because we no longer have just a single meter caption for the DynamicMeter case - if no label is provided for a metric in a configuration file use the short form metric name as a fallback - honour the suffix setting in the configuration file - convert metric values to the canonical units for htop (kbyte and seconds), and use Meter_humanUnit when it makes sense to do so. Also improves the handling of fatal string error messages in a couple of places, thanks to BenBE for the review feedback.
Diffstat (limited to 'DynamicMeter.c')
-rw-r--r--DynamicMeter.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/DynamicMeter.c b/DynamicMeter.c
index 7b39fdaa..3b567a53 100644
--- a/DynamicMeter.c
+++ b/DynamicMeter.c
@@ -70,12 +70,27 @@ static void DynamicMeter_display(const Object* cast, RichString* out) {
Platform_dynamicMeterDisplay(meter, out);
}
+static const char* DynamicMeter_getCaption(const Meter* this) {
+ const ProcessList* pl = this->pl;
+ const DynamicMeter* meter = Hashtable_get(pl->dynamicMeters, this->param);
+ if (meter)
+ return meter->caption ? meter->caption : meter->name;
+ return this->caption;
+}
+
static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length) {
const ProcessList* pl = this->pl;
const DynamicMeter* meter = Hashtable_get(pl->dynamicMeters, this->param);
if (meter) {
- const char* uiName = meter->caption ? meter->caption : meter->name;
- xSnprintf(name, length, "%s", uiName);
+ const char* uiName = meter->caption;
+ if (uiName) {
+ int len = strlen(uiName);
+ if (len > 2 && uiName[len-2] == ':')
+ len -= 2;
+ xSnprintf(name, length, "%.*s", len, uiName);
+ } else {
+ xSnprintf(name, length, "%s", meter->name);
+ }
}
}
@@ -87,6 +102,7 @@ const MeterClass DynamicMeter_class = {
},
.init = DynamicMeter_init,
.updateValues = DynamicMeter_updateValues,
+ .getCaption = DynamicMeter_getCaption,
.getUiName = DynamicMeter_getUiName,
.defaultMode = TEXT_METERMODE,
.maxItems = 0,

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