From 04fa7b16b6e95a8f4acb2b57ea2d4fe209890645 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Mon, 19 Jun 2023 16:07:57 +1000 Subject: [PATCH] Rename PCPMetric files, structures and related internal functions Simplify names to just Metric in this case as it is not mirroring core htop naming (which is the norm for that naming convention). --- Makefile.am | 18 +++---- pcp/InDomTable.c | 4 +- pcp/Instance.c | 16 +++--- pcp/{PCPMetric.c => Metric.c} | 36 +++++++------- pcp/{PCPMetric.h => Metric.h} | 36 +++++++------- pcp/PCPDynamicColumn.c | 18 +++---- pcp/PCPDynamicMeter.c | 12 ++--- pcp/PCPDynamicScreen.c | 6 +-- pcp/PCPMachine.c | 88 ++++++++++++++++---------------- pcp/PCPProcessList.c | 40 +++++++-------- pcp/Platform.c | 94 +++++++++++++++++------------------ pcp/Platform.h | 4 +- 12 files changed, 186 insertions(+), 186 deletions(-) rename pcp/{PCPMetric.c => Metric.c} (80%) rename pcp/{PCPMetric.h => Metric.h} (89%) diff --git a/Makefile.am b/Makefile.am index b7d3cca39..90bd30ef1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -416,17 +416,17 @@ pcp_platform_headers = \ linux/PressureStallMeter.h \ linux/ZramMeter.h \ linux/ZramStats.h \ + pcp/Instance.h \ + pcp/InDomTable.h \ + pcp/Metric.h \ + pcp/Platform.h \ + pcp/ProcessField.h \ pcp/PCPDynamicColumn.h \ pcp/PCPDynamicMeter.h \ pcp/PCPDynamicScreen.h \ - pcp/Instance.h \ - pcp/InDomTable.h \ pcp/PCPMachine.h \ - pcp/PCPMetric.h \ pcp/PCPProcess.h \ pcp/PCPProcessList.h \ - pcp/Platform.h \ - pcp/ProcessField.h \ zfs/ZfsArcMeter.h \ zfs/ZfsArcStats.h \ zfs/ZfsCompressedArcMeter.h @@ -435,16 +435,16 @@ pcp_platform_sources = \ linux/CGroupUtils.c \ linux/PressureStallMeter.c \ linux/ZramMeter.c \ + pcp/Instance.c \ + pcp/InDomTable.c \ + pcp/Metric.c \ + pcp/Platform.c \ pcp/PCPDynamicColumn.c \ pcp/PCPDynamicMeter.c \ pcp/PCPDynamicScreen.c \ - pcp/Instance.c \ - pcp/InDomTable.c \ pcp/PCPMachine.c \ - pcp/PCPMetric.c \ pcp/PCPProcess.c \ pcp/PCPProcessList.c \ - pcp/Platform.c \ zfs/ZfsArcMeter.c \ zfs/ZfsCompressedArcMeter.c diff --git a/pcp/InDomTable.c b/pcp/InDomTable.c index 120599222..b96f8a81e 100644 --- a/pcp/InDomTable.c +++ b/pcp/InDomTable.c @@ -22,8 +22,8 @@ in the source distribution for its full text. #include "XUtils.h" #include "pcp/Instance.h" +#include "pcp/Metric.h" #include "pcp/PCPDynamicColumn.h" -#include "pcp/PCPMetric.h" InDomTable* InDomTable_new(Machine* host, pmInDom indom, int metricKey) { @@ -68,7 +68,7 @@ static void InDomTable_goThroughEntries(InDomTable* this) { /* for every instance ... */ int instid = -1, offset = -1; - while (PCPMetric_iterate(this->metricKey, &instid, &offset)) { + while (Metric_iterate(this->metricKey, &instid, &offset)) { bool preExisting; Instance* inst = InDomTable_getInstance(this, instid, &preExisting); inst->offset = offset >= 0 ? offset : 0; diff --git a/pcp/Instance.c b/pcp/Instance.c index 1d56c108b..e70e7b703 100644 --- a/pcp/Instance.c +++ b/pcp/Instance.c @@ -19,16 +19,16 @@ in the source distribution for its full text. #include "Hashtable.h" #include "Machine.h" #include "Macros.h" +#include "Metric.h" +#include "Platform.h" #include "PCPDynamicColumn.h" #include "PCPDynamicScreen.h" -#include "PCPMetric.h" -#include "Platform.h" #include "Row.h" #include "RichString.h" #include "XUtils.h" #include "pcp/InDomTable.h" -#include "pcp/PCPMetric.h" +#include "pcp/Metric.h" Instance* Instance_new(const Machine* host, const InDomTable* indom) { @@ -62,11 +62,11 @@ static void Instance_writeField(const Row* super, RichString* str, RowField fiel const Settings* settings = super->host->settings; DynamicColumn* column = Hashtable_get(settings->dynamicColumns, field); PCPDynamicColumn* cp = (PCPDynamicColumn*) column; - const pmDesc* descp = PCPMetric_desc(cp->id); + const pmDesc* descp = Metric_desc(cp->id); pmAtomValue atom; pmAtomValue *ap = &atom; - if (!PCPMetric_instance(cp->id, instid, this->offset, ap, descp->type)) + if (!Metric_instance(cp->id, instid, this->offset, ap, descp->type)) ap = NULL; PCPDynamicColumn_writeAtomValue(cp, str, settings, cp->id, instid, descp, ap); @@ -96,11 +96,11 @@ static int Instance_compareByKey(const Row* v1, const Row* v2, int key) { return -1; size_t metric = column->id; - unsigned int type = PCPMetric_type(metric); + unsigned int type = Metric_type(metric); pmAtomValue atom1 = {0}, atom2 = {0}; - if (!PCPMetric_instance(metric, i1->offset, i1->offset, &atom1, type) || - !PCPMetric_instance(metric, i2->offset, i2->offset, &atom2, type)) { + if (!Metric_instance(metric, i1->offset, i1->offset, &atom1, type) || + !Metric_instance(metric, i2->offset, i2->offset, &atom2, type)) { if (type == PM_TYPE_STRING) { free(atom1.cp); free(atom2.cp); diff --git a/pcp/PCPMetric.c b/pcp/Metric.c similarity index 80% rename from pcp/PCPMetric.c rename to pcp/Metric.c index f7886bb84..a07bcc6e8 100644 --- a/pcp/PCPMetric.c +++ b/pcp/Metric.c @@ -1,5 +1,5 @@ /* -htop - PCPMetric.c +htop - Metric.c (C) 2020-2021 htop dev team (C) 2020-2021 Red Hat, Inc. Released under the GNU GPLv2+, see the COPYING file @@ -8,7 +8,7 @@ in the source distribution for its full text. #include "config.h" // IWYU pragma: keep -#include "pcp/PCPMetric.h" +#include "pcp/Metric.h" #include #include @@ -21,15 +21,15 @@ in the source distribution for its full text. extern Platform* pcp; -const pmDesc* PCPMetric_desc(PCPMetric metric) { +const pmDesc* Metric_desc(Metric metric) { return &pcp->descs[metric]; } -int PCPMetric_type(PCPMetric metric) { +int Metric_type(Metric metric) { return pcp->descs[metric].type; } -pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type) { +pmAtomValue* Metric_values(Metric metric, pmAtomValue* atom, int count, int type) { if (pcp->result == NULL) return NULL; @@ -54,14 +54,14 @@ pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, in return atom; } -int PCPMetric_instanceCount(PCPMetric metric) { +int Metric_instanceCount(Metric metric) { pmValueSet* vset = pcp->result->vset[metric]; if (vset) return vset->numval; return 0; } -int PCPMetric_instanceOffset(PCPMetric metric, int inst) { +int Metric_instanceOffset(Metric metric, int inst) { pmValueSet* vset = pcp->result->vset[metric]; if (!vset || vset->numval <= 0) return 0; @@ -74,7 +74,7 @@ int PCPMetric_instanceOffset(PCPMetric metric, int inst) { return 0; } -static pmAtomValue* PCPMetric_extract(PCPMetric metric, int inst, int offset, pmValueSet* vset, pmAtomValue* atom, int type) { +static pmAtomValue* Metric_extract(Metric metric, int inst, int offset, pmValueSet* vset, pmAtomValue* atom, int type) { /* extract value (using requested type) of given metric instance */ const pmDesc* desc = &pcp->descs[metric]; @@ -89,7 +89,7 @@ static pmAtomValue* PCPMetric_extract(PCPMetric metric, int inst, int offset, pm return atom; } -pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomValue* atom, int type) { +pmAtomValue* Metric_instance(Metric metric, int inst, int offset, pmAtomValue* atom, int type) { pmValueSet* vset = pcp->result->vset[metric]; if (!vset || vset->numval <= 0) @@ -97,12 +97,12 @@ pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomVa /* fast-path using heuristic offset based on expected location */ if (offset >= 0 && offset < vset->numval && inst == vset->vlist[offset].inst) - return PCPMetric_extract(metric, inst, offset, vset, atom, type); + return Metric_extract(metric, inst, offset, vset, atom, type); /* slow-path using a linear search for the requested instance */ for (int i = 0; i < vset->numval; i++) { if (inst == vset->vlist[i].inst) - return PCPMetric_extract(metric, inst, i, vset, atom, type); + return Metric_extract(metric, inst, i, vset, atom, type); } return NULL; } @@ -113,7 +113,7 @@ pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomVa * * Start it off by passing offset -1 into the routine. */ -bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp) { +bool Metric_iterate(Metric metric, int* instp, int* offsetp) { if (!pcp->result) return false; @@ -132,15 +132,15 @@ bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp) { } /* Switch on/off a metric for value fetching (sampling) */ -void PCPMetric_enable(PCPMetric metric, bool enable) { +void Metric_enable(Metric metric, bool enable) { pcp->fetch[metric] = enable ? pcp->pmids[metric] : PM_ID_NULL; } -bool PCPMetric_enabled(PCPMetric metric) { +bool Metric_enabled(Metric metric) { return pcp->fetch[metric] != PM_ID_NULL; } -void PCPMetric_enableThreads(void) { +void Metric_enableThreads(void) { pmValueSet* vset = xCalloc(1, sizeof(pmValueSet)); vset->vlist[0].inst = PM_IN_NULL; vset->vlist[0].value.lval = 1; @@ -159,7 +159,7 @@ void PCPMetric_enableThreads(void) { pmFreeResult(result); } -bool PCPMetric_fetch(struct timeval* timestamp) { +bool Metric_fetch(struct timeval* timestamp) { if (pcp->result) { pmFreeResult(pcp->result); pcp->result = NULL; @@ -179,12 +179,12 @@ bool PCPMetric_fetch(struct timeval* timestamp) { return true; } -void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName) { +void Metric_externalName(Metric metric, int inst, char** externalName) { const pmDesc* desc = &pcp->descs[metric]; pmNameInDom(desc->indom, inst, externalName); } -int PCPMetric_lookupText(const char* metric, char** desc) { +int Metric_lookupText(const char* metric, char** desc) { pmID pmid; int sts; diff --git a/pcp/PCPMetric.h b/pcp/Metric.h similarity index 89% rename from pcp/PCPMetric.h rename to pcp/Metric.h index b53b82de9..789ef4b24 100644 --- a/pcp/PCPMetric.h +++ b/pcp/Metric.h @@ -1,7 +1,7 @@ -#ifndef HEADER_PCPMetric -#define HEADER_PCPMetric +#ifndef HEADER_Metric +#define HEADER_Metric /* -htop - PCPMetric.h +htop - Metric.h (C) 2020-2021 htop dev team (C) 2020-2021 Red Hat, Inc. Released under the GNU GPLv2+, see the COPYING file @@ -22,7 +22,7 @@ in the source distribution for its full text. #undef PACKAGE_BUGREPORT -typedef enum PCPMetric_ { +typedef enum Metric_ { PCP_CONTROL_THREADS, /* proc.control.perclient.threads */ PCP_HINV_NCPU, /* hinv.ncpu */ @@ -156,32 +156,32 @@ typedef enum PCPMetric_ { PCP_PROC_SMAPS_SWAPPSS, /* proc.smaps.swappss */ PCP_METRIC_COUNT /* total metric count */ -} PCPMetric; +} Metric; -void PCPMetric_enable(PCPMetric metric, bool enable); +void Metric_enable(Metric metric, bool enable); -bool PCPMetric_enabled(PCPMetric metric); +bool Metric_enabled(Metric metric); -void PCPMetric_enableThreads(void); +void Metric_enableThreads(void); -bool PCPMetric_fetch(struct timeval* timestamp); +bool Metric_fetch(struct timeval* timestamp); -bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp); +bool Metric_iterate(Metric metric, int* instp, int* offsetp); -pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type); +pmAtomValue* Metric_values(Metric metric, pmAtomValue* atom, int count, int type); -const pmDesc* PCPMetric_desc(PCPMetric metric); +const pmDesc* Metric_desc(Metric metric); -int PCPMetric_type(PCPMetric metric); +int Metric_type(Metric metric); -int PCPMetric_instanceCount(PCPMetric metric); +int Metric_instanceCount(Metric metric); -int PCPMetric_instanceOffset(PCPMetric metric, int inst); +int Metric_instanceOffset(Metric metric, int inst); -pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomValue* atom, int type); +pmAtomValue* Metric_instance(Metric metric, int inst, int offset, pmAtomValue* atom, int type); -void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName); +void Metric_externalName(Metric metric, int inst, char** externalName); -int PCPMetric_lookupText(const char* metric, char** desc); +int Metric_lookupText(const char* metric, char** desc); #endif diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c index 335ca0d86..0ca2e2462 100644 --- a/pcp/PCPDynamicColumn.c +++ b/pcp/PCPDynamicColumn.c @@ -28,8 +28,8 @@ in the source distribution for its full text. #include "XUtils.h" #include "linux/CGroupUtils.h" +#include "pcp/Metric.h" #include "pcp/PCPProcess.h" -#include "pcp/PCPMetric.h" static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicColumn* column) { @@ -51,7 +51,7 @@ static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicCol static void PCPDynamicColumn_parseMetric(PCPDynamicColumns* columns, PCPDynamicColumn* column, const char* path, unsigned int line, char* value) { /* pmLookupText */ if (!column->super.description) - PCPMetric_lookupText(value, &column->super.description); + Metric_lookupText(value, &column->super.description); /* lookup a dynamic metric with this name, else create */ if (PCPDynamicColumn_addMetric(columns, column) == false) @@ -268,7 +268,7 @@ static void PCPDynamicColumn_setupWidth(ATTR_UNUSED ht_key_t key, void* value, A PCPDynamicColumn* column = (PCPDynamicColumn*) value; /* calculate column size based on config file and metric units */ - const pmDesc* desc = PCPMetric_desc(column->id); + const pmDesc* desc = Metric_desc(column->id); if (column->instances || desc->type == PM_TYPE_STRING) { column->super.width = column->width; @@ -376,7 +376,7 @@ void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str, char* dupd1 = NULL; if (column->instances) { attr = CRT_colors[DYNAMIC_GRAY]; - PCPMetric_externalName(metric, instance, &dupd1); + Metric_externalName(metric, instance, &dupd1); value = dupd1; } else { attr = CRT_colors[DYNAMIC_GREEN]; @@ -454,12 +454,12 @@ void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str, void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, RichString* str) { const Settings* settings = proc->super.host->settings; const PCPProcess* pp = (const PCPProcess*) proc; - const pmDesc* desc = PCPMetric_desc(this->id); + const pmDesc* desc = Metric_desc(this->id); pid_t pid = Process_getPid(proc); pmAtomValue atom; pmAtomValue *ap = &atom; - if (!PCPMetric_instance(this->id, pid, pp->offset, ap, desc->type)) + if (!Metric_instance(this->id, pid, pp->offset, ap, desc->type)) ap = NULL; PCPDynamicColumn_writeAtomValue(this, str, settings, this->id, pid, desc, ap); @@ -474,11 +474,11 @@ int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, Pr return -1; size_t metric = column->id; - unsigned int type = PCPMetric_type(metric); + unsigned int type = Metric_type(metric); pmAtomValue atom1 = {0}, atom2 = {0}; - if (!PCPMetric_instance(metric, Process_getPid(&p1->super), p1->offset, &atom1, type) || - !PCPMetric_instance(metric, Process_getPid(&p2->super), p2->offset, &atom2, type)) { + if (!Metric_instance(metric, Process_getPid(&p1->super), p1->offset, &atom1, type) || + !Metric_instance(metric, Process_getPid(&p2->super), p2->offset, &atom2, type)) { if (type == PM_TYPE_STRING) { free(atom1.cp); free(atom2.cp); diff --git a/pcp/PCPDynamicMeter.c b/pcp/PCPDynamicMeter.c index e89998813..87e51700c 100644 --- a/pcp/PCPDynamicMeter.c +++ b/pcp/PCPDynamicMeter.c @@ -25,7 +25,7 @@ in the source distribution for its full text. #include "RichString.h" #include "XUtils.h" -#include "pcp/PCPMetric.h" +#include "pcp/Metric.h" static PCPDynamicMetric* PCPDynamicMeter_lookupMetric(PCPDynamicMeters* meters, PCPDynamicMeter* meter, const char* name) { @@ -309,7 +309,7 @@ void PCPDynamicMeters_done(Hashtable* table) { void PCPDynamicMeter_enable(PCPDynamicMeter* this) { for (size_t i = 0; i < this->totalMetrics; i++) - PCPMetric_enable(this->metrics[i].id, true); + Metric_enable(this->metrics[i].id, true); } void PCPDynamicMeter_updateValues(PCPDynamicMeter* this, Meter* meter) { @@ -322,10 +322,10 @@ void PCPDynamicMeter_updateValues(PCPDynamicMeter* this, Meter* meter) { buffer[bytes++] = '/'; /* separator */ PCPDynamicMetric* metric = &this->metrics[i]; - const pmDesc* desc = PCPMetric_desc(metric->id); + const pmDesc* desc = Metric_desc(metric->id); pmAtomValue atom, raw; - if (!PCPMetric_values(metric->id, &raw, 1, desc->type)) { + if (!Metric_values(metric->id, &raw, 1, desc->type)) { bytes--; /* clear the separator */ continue; } @@ -393,11 +393,11 @@ void PCPDynamicMeter_display(PCPDynamicMeter* this, ATTR_UNUSED const Meter* met for (size_t i = 0; i < this->totalMetrics; i++) { PCPDynamicMetric* metric = &this->metrics[i]; - const pmDesc* desc = PCPMetric_desc(metric->id); + const pmDesc* desc = Metric_desc(metric->id); pmAtomValue atom, raw; char buffer[64]; - if (!PCPMetric_values(metric->id, &raw, 1, desc->type)) + if (!Metric_values(metric->id, &raw, 1, desc->type)) continue; pmUnits conv = desc->units; /* convert to canonical units */ diff --git a/pcp/PCPDynamicScreen.c b/pcp/PCPDynamicScreen.c index d4ad3fd7f..fca03aa46 100644 --- a/pcp/PCPDynamicScreen.c +++ b/pcp/PCPDynamicScreen.c @@ -55,8 +55,8 @@ static void PCPDynamicScreens_appendDynamicColumns(PCPDynamicScreens* screens, P columns->count++; if (j == 0) { - const pmDesc* desc = PCPMetric_desc(column->id); - assert(desc->indom != PM_INDOM_NULL); + const pmDesc* desc = Metric_desc(column->id); + assert(desc->indom != PM_INDOM_NULL); screen->indom = desc->indom; screen->key = column->id; } @@ -124,7 +124,7 @@ static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* p /* pmLookupText - add optional metric help text */ if (!column->super.description) - PCPMetric_lookupText(value, &column->super.description); + Metric_lookupText(value, &column->super.description); } else { /* this is a property of a dynamic column - the column expression */ diff --git a/pcp/PCPMachine.c b/pcp/PCPMachine.c index 726218d99..801f39784 100644 --- a/pcp/PCPMachine.c +++ b/pcp/PCPMachine.c @@ -25,13 +25,13 @@ in the source distribution for its full text. #include "Settings.h" #include "XUtils.h" -#include "pcp/PCPMetric.h" +#include "pcp/Metric.h" #include "pcp/PCPProcess.h" static void PCPMachine_updateCPUcount(PCPMachine* this) { Machine* super = &this->super; - super->activeCPUs = PCPMetric_instanceCount(PCP_PERCPU_SYSTEM); + super->activeCPUs = Metric_instanceCount(PCP_PERCPU_SYSTEM); unsigned int cpus = Platform_getMaxCPU(); if (cpus == super->existingCPUs) return; @@ -58,30 +58,30 @@ static void PCPMachine_updateMemoryInfo(Machine* host) { host->usedSwap = host->totalSwap = host->sharedMem = 0; pmAtomValue value; - if (PCPMetric_values(PCP_MEM_TOTAL, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_TOTAL, &value, 1, PM_TYPE_U64) != NULL) host->totalMem = value.ull; - if (PCPMetric_values(PCP_MEM_FREE, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_FREE, &value, 1, PM_TYPE_U64) != NULL) freeMem = value.ull; - if (PCPMetric_values(PCP_MEM_BUFFERS, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_BUFFERS, &value, 1, PM_TYPE_U64) != NULL) host->buffersMem = value.ull; - if (PCPMetric_values(PCP_MEM_SRECLAIM, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_SRECLAIM, &value, 1, PM_TYPE_U64) != NULL) sreclaimableMem = value.ull; - if (PCPMetric_values(PCP_MEM_SHARED, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_SHARED, &value, 1, PM_TYPE_U64) != NULL) host->sharedMem = value.ull; - if (PCPMetric_values(PCP_MEM_CACHED, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_CACHED, &value, 1, PM_TYPE_U64) != NULL) host->cachedMem = value.ull + sreclaimableMem - host->sharedMem; const memory_t usedDiff = freeMem + host->cachedMem + sreclaimableMem + host->buffersMem; host->usedMem = (host->totalMem >= usedDiff) ? host->totalMem - usedDiff : host->totalMem - freeMem; - if (PCPMetric_values(PCP_MEM_AVAILABLE, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_AVAILABLE, &value, 1, PM_TYPE_U64) != NULL) host->availableMem = MINIMUM(value.ull, host->totalMem); else host->availableMem = freeMem; - if (PCPMetric_values(PCP_MEM_SWAPFREE, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_SWAPFREE, &value, 1, PM_TYPE_U64) != NULL) swapFreeMem = value.ull; - if (PCPMetric_values(PCP_MEM_SWAPTOTAL, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_SWAPTOTAL, &value, 1, PM_TYPE_U64) != NULL) host->totalSwap = value.ull; - if (PCPMetric_values(PCP_MEM_SWAPCACHED, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_MEM_SWAPCACHED, &value, 1, PM_TYPE_U64) != NULL) host->cachedSwap = value.ull; host->usedSwap = host->totalSwap - swapFreeMem - host->cachedSwap; } @@ -153,26 +153,26 @@ static void PCPMachine_deriveCPUTime(pmAtomValue* values) { PCPMachine_saveCPUTimePeriod(values, CPU_TOTAL_PERIOD, totaltime); } -static void PCPMachine_updateAllCPUTime(PCPMachine* this, PCPMetric metric, CPUMetric cpumetric) +static void PCPMachine_updateAllCPUTime(PCPMachine* this, Metric metric, CPUMetric cpumetric) { pmAtomValue* value = &this->cpu[cpumetric]; - if (PCPMetric_values(metric, value, 1, PM_TYPE_U64) == NULL) + if (Metric_values(metric, value, 1, PM_TYPE_U64) == NULL) memset(value, 0, sizeof(pmAtomValue)); } -static void PCPMachine_updatePerCPUTime(PCPMachine* this, PCPMetric metric, CPUMetric cpumetric) +static void PCPMachine_updatePerCPUTime(PCPMachine* this, Metric metric, CPUMetric cpumetric) { int cpus = this->super.existingCPUs; - if (PCPMetric_values(metric, this->values, cpus, PM_TYPE_U64) == NULL) + if (Metric_values(metric, this->values, cpus, PM_TYPE_U64) == NULL) memset(this->values, 0, cpus * sizeof(pmAtomValue)); for (int i = 0; i < cpus; i++) this->percpu[i][cpumetric].ull = this->values[i].ull; } -static void PCPMachine_updatePerCPUReal(PCPMachine* this, PCPMetric metric, CPUMetric cpumetric) +static void PCPMachine_updatePerCPUReal(PCPMachine* this, Metric metric, CPUMetric cpumetric) { int cpus = this->super.existingCPUs; - if (PCPMetric_values(metric, this->values, cpus, PM_TYPE_DOUBLE) == NULL) + if (Metric_values(metric, this->values, cpus, PM_TYPE_DOUBLE) == NULL) memset(this->values, 0, cpus * sizeof(pmAtomValue)); for (int i = 0; i < cpus; i++) this->percpu[i][cpumetric].d = this->values[i].d; @@ -185,29 +185,29 @@ static inline void PCPMachine_scanZfsArcstats(PCPMachine* this) { pmAtomValue value; memset(&this->zfs, 0, sizeof(ZfsArcStats)); - if (PCPMetric_values(PCP_ZFS_ARC_ANON_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_ANON_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.anon = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_C_MIN, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_C_MIN, &value, 1, PM_TYPE_U64)) this->zfs.min = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_C_MAX, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_C_MAX, &value, 1, PM_TYPE_U64)) this->zfs.max = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_BONUS_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_BONUS_SIZE, &value, 1, PM_TYPE_U64)) bonusSize = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_DBUF_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_DBUF_SIZE, &value, 1, PM_TYPE_U64)) dbufSize = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_DNODE_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_DNODE_SIZE, &value, 1, PM_TYPE_U64)) dnodeSize = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_COMPRESSED_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_COMPRESSED_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.compressed = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_UNCOMPRESSED_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_UNCOMPRESSED_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.uncompressed = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_HDR_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_HDR_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.header = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_MFU_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_MFU_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.MFU = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_MRU_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_MRU_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.MRU = value.ull / ONE_K; - if (PCPMetric_values(PCP_ZFS_ARC_SIZE, &value, 1, PM_TYPE_U64)) + if (Metric_values(PCP_ZFS_ARC_SIZE, &value, 1, PM_TYPE_U64)) this->zfs.size = value.ull / ONE_K; this->zfs.other = (dbufSize + dnodeSize + bonusSize) / ONE_K; @@ -260,31 +260,31 @@ void Machine_scan(Machine* super) { bool flagged; for (int metric = PCP_PROC_PID; metric < PCP_METRIC_COUNT; metric++) - PCPMetric_enable(metric, true); + Metric_enable(metric, true); flagged = settings->showCPUFrequency; - PCPMetric_enable(PCP_HINV_CPUCLOCK, flagged); + Metric_enable(PCP_HINV_CPUCLOCK, flagged); flagged = flags & PROCESS_FLAG_LINUX_CGROUP; - PCPMetric_enable(PCP_PROC_CGROUPS, flagged); + Metric_enable(PCP_PROC_CGROUPS, flagged); flagged = flags & PROCESS_FLAG_LINUX_OOM; - PCPMetric_enable(PCP_PROC_OOMSCORE, flagged); + Metric_enable(PCP_PROC_OOMSCORE, flagged); flagged = flags & PROCESS_FLAG_LINUX_CTXT; - PCPMetric_enable(PCP_PROC_VCTXSW, flagged); - PCPMetric_enable(PCP_PROC_NVCTXSW, flagged); + Metric_enable(PCP_PROC_VCTXSW, flagged); + Metric_enable(PCP_PROC_NVCTXSW, flagged); flagged = flags & PROCESS_FLAG_LINUX_SECATTR; - PCPMetric_enable(PCP_PROC_LABELS, flagged); + Metric_enable(PCP_PROC_LABELS, flagged); flagged = flags & PROCESS_FLAG_LINUX_AUTOGROUP; - PCPMetric_enable(PCP_PROC_AUTOGROUP_ID, flagged); - PCPMetric_enable(PCP_PROC_AUTOGROUP_NICE, flagged); + Metric_enable(PCP_PROC_AUTOGROUP_ID, flagged); + Metric_enable(PCP_PROC_AUTOGROUP_NICE, flagged); /* Sample smaps metrics on every second pass to improve performance */ host->smaps_flag = !!host->smaps_flag; - PCPMetric_enable(PCP_PROC_SMAPS_PSS, host->smaps_flag); - PCPMetric_enable(PCP_PROC_SMAPS_SWAP, host->smaps_flag); - PCPMetric_enable(PCP_PROC_SMAPS_SWAPPSS, host->smaps_flag); + Metric_enable(PCP_PROC_SMAPS_PSS, host->smaps_flag); + Metric_enable(PCP_PROC_SMAPS_SWAP, host->smaps_flag); + Metric_enable(PCP_PROC_SMAPS_SWAPPSS, host->smaps_flag); struct timeval timestamp; - if (PCPMetric_fetch(×tamp) != true) + if (Metric_fetch(×tamp) != true) return; double sample = host->timestamp; @@ -328,7 +328,7 @@ bool Machine_isCPUonline(const Machine* host, unsigned int id) { (void) host; pmAtomValue value; - if (PCPMetric_instance(PCP_PERCPU_SYSTEM, id, id, &value, PM_TYPE_U32)) + if (Metric_instance(PCP_PERCPU_SYSTEM, id, id, &value, PM_TYPE_U32)) return true; return false; } diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c index f320ba61d..7492b2c1c 100644 --- a/pcp/PCPProcessList.c +++ b/pcp/PCPProcessList.c @@ -26,8 +26,8 @@ in the source distribution for its full text. #include "Settings.h" #include "XUtils.h" +#include "pcp/Metric.h" #include "pcp/PCPMachine.h" -#include "pcp/PCPMetric.h" #include "pcp/PCPProcess.h" @@ -49,49 +49,49 @@ void ProcessList_delete(Object* cast) { static inline long Metric_instance_s32(int metric, int pid, int offset, long fallback) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_32)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_32)) return value.l; return fallback; } static inline long long Metric_instance_s64(int metric, int pid, int offset, long long fallback) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_64)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_64)) return value.l; return fallback; } static inline unsigned long Metric_instance_u32(int metric, int pid, int offset, unsigned long fallback) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_U32)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_U32)) return value.ul; return fallback; } static inline unsigned long long Metric_instance_u64(int metric, int pid, int offset, unsigned long long fallback) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_U64)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_U64)) return value.ull; return fallback; } static inline unsigned long long Metric_instance_time(int metric, int pid, int offset) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_U64)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_U64)) return value.ull / 10; return 0; } static inline unsigned long long Metric_instance_ONE_K(int metric, int pid, int offset) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_U64)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_U64)) return value.ull / ONE_K; return ULLONG_MAX; } static inline char Metric_instance_char(int metric, int pid, int offset, char fallback) { pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_STRING)) { + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_STRING)) { char uchar = value.cp[0]; free(value.cp); return uchar; @@ -105,7 +105,7 @@ static char* setUser(UsersTable* this, unsigned int uid, int pid, int offset) { return name; pmAtomValue value; - if (PCPMetric_instance(PCP_PROC_ID_USER, pid, offset, &value, PM_TYPE_STRING)) { + if (Metric_instance(PCP_PROC_ID_USER, pid, offset, &value, PM_TYPE_STRING)) { Hashtable_put(this->users, uid, value.cp); name = value.cp; } @@ -139,7 +139,7 @@ static void PCPProcessList_updateInfo(PCPProcess* pp, int pid, int offset, char* Process* process = &pp->super; pmAtomValue value; - if (!PCPMetric_instance(PCP_PROC_CMD, pid, offset, &value, PM_TYPE_STRING)) + if (!Metric_instance(PCP_PROC_CMD, pid, offset, &value, PM_TYPE_STRING)) value.cp = xStrdup(""); String_safeStrncpy(command, value.cp, commLen); free(value.cp); @@ -174,7 +174,7 @@ static void PCPProcessList_updateIO(PCPProcess* pp, int pid, int offset, unsigne pp->io_syscw = Metric_instance_u64(PCP_PROC_IO_SYSCW, pid, offset, ULLONG_MAX); pp->io_cancelled_write_bytes = Metric_instance_ONE_K(PCP_PROC_IO_CANCELLED, pid, offset); - if (PCPMetric_instance(PCP_PROC_IO_READB, pid, offset, &value, PM_TYPE_U64)) { + if (Metric_instance(PCP_PROC_IO_READB, pid, offset, &value, PM_TYPE_U64)) { unsigned long long last_read = pp->io_read_bytes; pp->io_read_bytes = value.ull / ONE_K; pp->io_rate_read_bps = ONE_K * (pp->io_read_bytes - last_read) / @@ -184,7 +184,7 @@ static void PCPProcessList_updateIO(PCPProcess* pp, int pid, int offset, unsigne pp->io_rate_read_bps = NAN; } - if (PCPMetric_instance(PCP_PROC_IO_WRITEB, pid, offset, &value, PM_TYPE_U64)) { + if (Metric_instance(PCP_PROC_IO_WRITEB, pid, offset, &value, PM_TYPE_U64)) { unsigned long long last_write = pp->io_write_bytes; pp->io_write_bytes = value.ull; pp->io_rate_write_bps = ONE_K * (pp->io_write_bytes - last_write) / @@ -226,20 +226,20 @@ static void PCPProcessList_readCtxtData(PCPProcess* pp, int pid, int offset) { pmAtomValue value; unsigned long ctxt = 0; - if (PCPMetric_instance(PCP_PROC_VCTXSW, pid, offset, &value, PM_TYPE_U32)) + if (Metric_instance(PCP_PROC_VCTXSW, pid, offset, &value, PM_TYPE_U32)) ctxt += value.ul; - if (PCPMetric_instance(PCP_PROC_NVCTXSW, pid, offset, &value, PM_TYPE_U32)) + if (Metric_instance(PCP_PROC_NVCTXSW, pid, offset, &value, PM_TYPE_U32)) ctxt += value.ul; pp->ctxt_diff = ctxt > pp->ctxt_total ? ctxt - pp->ctxt_total : 0; pp->ctxt_total = ctxt; } -static char* setString(PCPMetric metric, int pid, int offset, char* string) { +static char* setString(Metric metric, int pid, int offset, char* string) { if (string) free(string); pmAtomValue value; - if (PCPMetric_instance(metric, pid, offset, &value, PM_TYPE_STRING)) + if (Metric_instance(metric, pid, offset, &value, PM_TYPE_STRING)) string = value.cp; else string = NULL; @@ -269,7 +269,7 @@ static void PCPProcessList_updateUsername(Process* process, int pid, int offset, static void PCPProcessList_updateCmdline(Process* process, int pid, int offset, const char* comm) { pmAtomValue value; - if (!PCPMetric_instance(PCP_PROC_PSARGS, pid, offset, &value, PM_TYPE_STRING)) { + if (!Metric_instance(PCP_PROC_PSARGS, pid, offset, &value, PM_TYPE_STRING)) { if (process->state != ZOMBIE) process->isKernelThread = true; Process_updateCmdline(process, NULL, 0, 0); @@ -303,7 +303,7 @@ static void PCPProcessList_updateCmdline(Process* process, int pid, int offset, Process_updateComm(process, comm); - if (PCPMetric_instance(PCP_PROC_EXE, pid, offset, &value, PM_TYPE_STRING)) { + if (Metric_instance(PCP_PROC_EXE, pid, offset, &value, PM_TYPE_STRING)) { Process_updateExe(process, value.cp[0] ? value.cp : NULL); free(value.cp); } @@ -323,7 +323,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this) { int pid = -1, offset = -1; /* for every process ... */ - while (PCPMetric_iterate(PCP_PROC_PID, &pid, &offset)) { + while (Metric_iterate(PCP_PROC_PID, &pid, &offset)) { bool preExisting; Process* proc = ProcessList_getProcess(pl, pid, &preExisting, PCPProcess_new); @@ -364,7 +364,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this) { if ((flags & PROCESS_FLAG_LINUX_SMAPS) && (Process_isKernelThread(proc) == false)) { - if (PCPMetric_enabled(PCP_PROC_SMAPS_PSS)) + if (Metric_enabled(PCP_PROC_SMAPS_PSS)) PCPProcessList_updateSmaps(pp, pid, offset); } diff --git a/pcp/Platform.c b/pcp/Platform.c index 470a5f2d4..fb0447f78 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -45,11 +45,11 @@ in the source distribution for its full text. #include "linux/PressureStallMeter.h" #include "linux/ZramMeter.h" #include "linux/ZramStats.h" +#include "pcp/Metric.h" #include "pcp/PCPDynamicColumn.h" #include "pcp/PCPDynamicMeter.h" #include "pcp/PCPDynamicScreen.h" #include "pcp/PCPMachine.h" -#include "pcp/PCPMetric.h" #include "pcp/PCPProcessList.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsArcStats.h" @@ -288,7 +288,7 @@ int pmLookupDescs(int numpmid, pmID* pmids, pmDesc* descs) { } #endif -size_t Platform_addMetric(PCPMetric id, const char* name) { +size_t Platform_addMetric(Metric id, const char* name) { unsigned int i = (unsigned int)id; if (i >= PCP_METRIC_COUNT && i >= pcp->totalMetrics) { @@ -377,32 +377,32 @@ bool Platform_init(void) { } /* set proc.control.perclient.threads to 1 for live contexts */ - PCPMetric_enableThreads(); + Metric_enableThreads(); /* extract values needed for setup - e.g. cpu count, pid_max */ - PCPMetric_enable(PCP_PID_MAX, true); - PCPMetric_enable(PCP_BOOTTIME, true); - PCPMetric_enable(PCP_HINV_NCPU, true); - PCPMetric_enable(PCP_PERCPU_SYSTEM, true); - PCPMetric_enable(PCP_UNAME_SYSNAME, true); - PCPMetric_enable(PCP_UNAME_RELEASE, true); - PCPMetric_enable(PCP_UNAME_MACHINE, true); - PCPMetric_enable(PCP_UNAME_DISTRO, true); + Metric_enable(PCP_PID_MAX, true); + Metric_enable(PCP_BOOTTIME, true); + Metric_enable(PCP_HINV_NCPU, true); + Metric_enable(PCP_PERCPU_SYSTEM, true); + Metric_enable(PCP_UNAME_SYSNAME, true); + Metric_enable(PCP_UNAME_RELEASE, true); + Metric_enable(PCP_UNAME_MACHINE, true); + Metric_enable(PCP_UNAME_DISTRO, true); /* enable metrics for all dynamic columns (including those from dynamic screens) */ for (size_t i = pcp->columns.offset; i < pcp->columns.offset + pcp->columns.count; i++) - PCPMetric_enable(i, true); + Metric_enable(i, true); - PCPMetric_fetch(NULL); + Metric_fetch(NULL); - for (PCPMetric metric = 0; metric < PCP_PROC_PID; metric++) - PCPMetric_enable(metric, true); - PCPMetric_enable(PCP_PID_MAX, false); /* needed one time only */ - PCPMetric_enable(PCP_BOOTTIME, false); - PCPMetric_enable(PCP_UNAME_SYSNAME, false); - PCPMetric_enable(PCP_UNAME_RELEASE, false); - PCPMetric_enable(PCP_UNAME_MACHINE, false); - PCPMetric_enable(PCP_UNAME_DISTRO, false); + for (Metric metric = 0; metric < PCP_PROC_PID; metric++) + Metric_enable(metric, true); + Metric_enable(PCP_PID_MAX, false); /* needed one time only */ + Metric_enable(PCP_BOOTTIME, false); + Metric_enable(PCP_UNAME_SYSNAME, false); + Metric_enable(PCP_UNAME_RELEASE, false); + Metric_enable(PCP_UNAME_MACHINE, false); + Metric_enable(PCP_UNAME_DISTRO, false); /* first sample (fetch) performed above, save constants */ Platform_getBootTime(); @@ -444,7 +444,7 @@ void Platform_setBindings(Htop_Action* keys) { int Platform_getUptime(void) { pmAtomValue value; - if (PCPMetric_values(PCP_UPTIME, &value, 1, PM_TYPE_32) == NULL) + if (Metric_values(PCP_UPTIME, &value, 1, PM_TYPE_32) == NULL) return 0; return value.l; } @@ -453,7 +453,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *one = *five = *fifteen = 0.0; pmAtomValue values[3] = {0}; - if (PCPMetric_values(PCP_LOAD_AVERAGE, values, 3, PM_TYPE_DOUBLE) != NULL) { + if (Metric_values(PCP_LOAD_AVERAGE, values, 3, PM_TYPE_DOUBLE) != NULL) { *one = values[0].d; *five = values[1].d; *fifteen = values[2].d; @@ -465,7 +465,7 @@ unsigned int Platform_getMaxCPU(void) { return pcp->ncpu; pmAtomValue value; - if (PCPMetric_values(PCP_HINV_NCPU, &value, 1, PM_TYPE_U32) != NULL) + if (Metric_values(PCP_HINV_NCPU, &value, 1, PM_TYPE_U32) != NULL) pcp->ncpu = value.ul; else pcp->ncpu = 1; @@ -477,7 +477,7 @@ int Platform_getMaxPid(void) { return pcp->pidmax; pmAtomValue value; - if (PCPMetric_values(PCP_PID_MAX, &value, 1, PM_TYPE_32) == NULL) + if (Metric_values(PCP_PID_MAX, &value, 1, PM_TYPE_32) == NULL) return -1; pcp->pidmax = value.l; return pcp->pidmax; @@ -488,7 +488,7 @@ long long Platform_getBootTime(void) { return pcp->btime; pmAtomValue value; - if (PCPMetric_values(PCP_BOOTTIME, &value, 1, PM_TYPE_64) != NULL) + if (Metric_values(PCP_BOOTTIME, &value, 1, PM_TYPE_64) != NULL) pcp->btime = value.ll; return pcp->btime; } @@ -575,7 +575,7 @@ void Platform_setSwapValues(Meter* this) { } void Platform_setZramValues(Meter* this) { - int i, count = PCPMetric_instanceCount(PCP_ZRAM_CAPACITY); + int i, count = Metric_instanceCount(PCP_ZRAM_CAPACITY); if (!count) { this->total = 0; this->values[0] = 0; @@ -586,15 +586,15 @@ void Platform_setZramValues(Meter* this) { pmAtomValue* values = xCalloc(count, sizeof(pmAtomValue)); ZramStats stats = {0}; - if (PCPMetric_values(PCP_ZRAM_CAPACITY, values, count, PM_TYPE_U64)) { + if (Metric_values(PCP_ZRAM_CAPACITY, values, count, PM_TYPE_U64)) { for (i = 0; i < count; i++) stats.totalZram += values[i].ull; } - if (PCPMetric_values(PCP_ZRAM_ORIGINAL, values, count, PM_TYPE_U64)) { + if (Metric_values(PCP_ZRAM_ORIGINAL, values, count, PM_TYPE_U64)) { for (i = 0; i < count; i++) stats.usedZramOrig += values[i].ull; } - if (PCPMetric_values(PCP_ZRAM_COMPRESSED, values, count, PM_TYPE_U64)) { + if (Metric_values(PCP_ZRAM_COMPRESSED, values, count, PM_TYPE_U64)) { for (i = 0; i < count; i++) stats.usedZramComp += values[i].ull; } @@ -632,13 +632,13 @@ void Platform_getRelease(char** string) { /* first call, extract just-sampled values */ pmAtomValue sysname, release, machine, distro; - if (!PCPMetric_values(PCP_UNAME_SYSNAME, &sysname, 1, PM_TYPE_STRING)) + if (!Metric_values(PCP_UNAME_SYSNAME, &sysname, 1, PM_TYPE_STRING)) sysname.cp = NULL; - if (!PCPMetric_values(PCP_UNAME_RELEASE, &release, 1, PM_TYPE_STRING)) + if (!Metric_values(PCP_UNAME_RELEASE, &release, 1, PM_TYPE_STRING)) release.cp = NULL; - if (!PCPMetric_values(PCP_UNAME_MACHINE, &machine, 1, PM_TYPE_STRING)) + if (!Metric_values(PCP_UNAME_MACHINE, &machine, 1, PM_TYPE_STRING)) machine.cp = NULL; - if (!PCPMetric_values(PCP_UNAME_DISTRO, &distro, 1, PM_TYPE_STRING)) + if (!Metric_values(PCP_UNAME_DISTRO, &distro, 1, PM_TYPE_STRING)) distro.cp = NULL; size_t length = 16; /* padded for formatting characters */ @@ -686,7 +686,7 @@ void Platform_getRelease(char** string) { char* Platform_getProcessEnv(pid_t pid) { pmAtomValue value; - if (!PCPMetric_instance(PCP_PROC_ENVIRON, pid, 0, &value, PM_TYPE_STRING)) + if (!Metric_instance(PCP_PROC_ENVIRON, pid, 0, &value, PM_TYPE_STRING)) return NULL; return value.cp; } @@ -699,7 +699,7 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred) { *ten = *sixty = *threehundred = 0; - PCPMetric metric; + Metric metric; if (String_eq(file, "cpu")) metric = PCP_PSI_CPUSOME; else if (String_eq(file, "io")) @@ -712,7 +712,7 @@ void Platform_getPressureStall(const char* file, bool some, double* ten, double* return; pmAtomValue values[3] = {0}; - if (PCPMetric_values(metric, values, 3, PM_TYPE_DOUBLE) != NULL) { + if (Metric_values(metric, values, 3, PM_TYPE_DOUBLE) != NULL) { *ten = values[0].d; *sixty = values[1].d; *threehundred = values[2].d; @@ -723,11 +723,11 @@ bool Platform_getDiskIO(DiskIOData* data) { memset(data, 0, sizeof(*data)); pmAtomValue value; - if (PCPMetric_values(PCP_DISK_READB, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_DISK_READB, &value, 1, PM_TYPE_U64) != NULL) data->totalBytesRead = value.ull; - if (PCPMetric_values(PCP_DISK_WRITEB, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_DISK_WRITEB, &value, 1, PM_TYPE_U64) != NULL) data->totalBytesWritten = value.ull; - if (PCPMetric_values(PCP_DISK_ACTIVE, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_DISK_ACTIVE, &value, 1, PM_TYPE_U64) != NULL) data->totalMsTimeSpend = value.ull; return true; } @@ -736,13 +736,13 @@ bool Platform_getNetworkIO(NetworkIOData* data) { memset(data, 0, sizeof(*data)); pmAtomValue value; - if (PCPMetric_values(PCP_NET_RECVB, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_NET_RECVB, &value, 1, PM_TYPE_U64) != NULL) data->bytesReceived = value.ull; - if (PCPMetric_values(PCP_NET_SENDB, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_NET_SENDB, &value, 1, PM_TYPE_U64) != NULL) data->bytesTransmitted = value.ull; - if (PCPMetric_values(PCP_NET_RECVP, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_NET_RECVP, &value, 1, PM_TYPE_U64) != NULL) data->packetsReceived = value.ull; - if (PCPMetric_values(PCP_NET_SENDP, &value, 1, PM_TYPE_U64) != NULL) + if (Metric_values(PCP_NET_SENDP, &value, 1, PM_TYPE_U64) != NULL) data->packetsTransmitted = value.ull; return true; } @@ -752,9 +752,9 @@ void Platform_getFileDescriptors(double* used, double* max) { *max = 65536; pmAtomValue value; - if (PCPMetric_values(PCP_VFS_FILES_COUNT, &value, 1, PM_TYPE_32) != NULL) + if (Metric_values(PCP_VFS_FILES_COUNT, &value, 1, PM_TYPE_32) != NULL) *used = value.l; - if (PCPMetric_values(PCP_VFS_FILES_MAX, &value, 1, PM_TYPE_32) != NULL) + if (Metric_values(PCP_VFS_FILES_MAX, &value, 1, PM_TYPE_32) != NULL) *max = value.l; } @@ -857,7 +857,7 @@ Hashtable* Platform_dynamicColumns(void) { const char* Platform_dynamicColumnName(unsigned int key) { PCPDynamicColumn* this = Hashtable_get(pcp->columns.table, key); if (this) { - PCPMetric_enable(this->id, true); + Metric_enable(this->id, true); if (this->super.caption) return this->super.caption; if (this->super.heading) diff --git a/pcp/Platform.h b/pcp/Platform.h index f2e8a49d4..ce21f845b 100644 --- a/pcp/Platform.h +++ b/pcp/Platform.h @@ -36,10 +36,10 @@ in the source distribution for its full text. #include "SignalsPanel.h" #include "CommandLine.h" +#include "pcp/Metric.h" #include "pcp/PCPDynamicColumn.h" #include "pcp/PCPDynamicMeter.h" #include "pcp/PCPDynamicScreen.h" -#include "pcp/PCPMetric.h" typedef struct Platform_ { @@ -131,7 +131,7 @@ CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv); extern pmOptions opts; -size_t Platform_addMetric(PCPMetric id, const char* name); +size_t Platform_addMetric(Metric id, const char* name); void Platform_getFileDescriptors(double* used, double* max);