Skip to content

Commit

Permalink
Rename PCPMetric files, structures and related internal functions
Browse files Browse the repository at this point in the history
Simplify names to just Metric in this case as it is not mirroring
core htop naming (which is the norm for that naming convention).
  • Loading branch information
natoscott committed Aug 22, 2023
1 parent 281427f commit 04fa7b1
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 186 deletions.
18 changes: 9 additions & 9 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pcp/InDomTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions pcp/Instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions pcp/PCPMetric.c → pcp/Metric.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <stddef.h>
#include <stdio.h>
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -89,20 +89,20 @@ 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)
return NULL;

/* 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;
}
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down
36 changes: 18 additions & 18 deletions pcp/PCPMetric.h → pcp/Metric.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 */
Expand Down Expand Up @@ -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
18 changes: 9 additions & 9 deletions pcp/PCPDynamicColumn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 04fa7b1

Please sign in to comment.