Skip to content

Commit d44dce8

Browse files
committed
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).
1 parent 912269b commit d44dce8

File tree

12 files changed

+186
-186
lines changed

12 files changed

+186
-186
lines changed

Makefile.am

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,17 @@ pcp_platform_headers = \
416416
linux/PressureStallMeter.h \
417417
linux/ZramMeter.h \
418418
linux/ZramStats.h \
419+
pcp/Instance.h \
420+
pcp/InDomTable.h \
421+
pcp/Metric.h \
422+
pcp/Platform.h \
423+
pcp/ProcessField.h \
419424
pcp/PCPDynamicColumn.h \
420425
pcp/PCPDynamicMeter.h \
421426
pcp/PCPDynamicScreen.h \
422-
pcp/Instance.h \
423-
pcp/InDomTable.h \
424427
pcp/PCPMachine.h \
425-
pcp/PCPMetric.h \
426428
pcp/PCPProcess.h \
427429
pcp/PCPProcessList.h \
428-
pcp/Platform.h \
429-
pcp/ProcessField.h \
430430
zfs/ZfsArcMeter.h \
431431
zfs/ZfsArcStats.h \
432432
zfs/ZfsCompressedArcMeter.h
@@ -435,16 +435,16 @@ pcp_platform_sources = \
435435
linux/CGroupUtils.c \
436436
linux/PressureStallMeter.c \
437437
linux/ZramMeter.c \
438+
pcp/Instance.c \
439+
pcp/InDomTable.c \
440+
pcp/Metric.c \
441+
pcp/Platform.c \
438442
pcp/PCPDynamicColumn.c \
439443
pcp/PCPDynamicMeter.c \
440444
pcp/PCPDynamicScreen.c \
441-
pcp/Instance.c \
442-
pcp/InDomTable.c \
443445
pcp/PCPMachine.c \
444-
pcp/PCPMetric.c \
445446
pcp/PCPProcess.c \
446447
pcp/PCPProcessList.c \
447-
pcp/Platform.c \
448448
zfs/ZfsArcMeter.c \
449449
zfs/ZfsCompressedArcMeter.c
450450

pcp/InDomTable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ in the source distribution for its full text.
2222
#include "XUtils.h"
2323

2424
#include "pcp/Instance.h"
25+
#include "pcp/Metric.h"
2526
#include "pcp/PCPDynamicColumn.h"
26-
#include "pcp/PCPMetric.h"
2727

2828

2929
InDomTable* InDomTable_new(Machine* host, pmInDom indom, int metricKey) {
@@ -68,7 +68,7 @@ static void InDomTable_goThroughEntries(InDomTable* this) {
6868

6969
/* for every instance ... */
7070
int instid = -1, offset = -1;
71-
while (PCPMetric_iterate(this->metricKey, &instid, &offset)) {
71+
while (Metric_iterate(this->metricKey, &instid, &offset)) {
7272
bool preExisting;
7373
Instance* inst = InDomTable_getInstance(this, instid, &preExisting);
7474
inst->offset = offset >= 0 ? offset : 0;

pcp/Instance.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ in the source distribution for its full text.
1919
#include "Hashtable.h"
2020
#include "Machine.h"
2121
#include "Macros.h"
22+
#include "Metric.h"
23+
#include "Platform.h"
2224
#include "PCPDynamicColumn.h"
2325
#include "PCPDynamicScreen.h"
24-
#include "PCPMetric.h"
25-
#include "Platform.h"
2626
#include "Row.h"
2727
#include "RichString.h"
2828
#include "XUtils.h"
2929

3030
#include "pcp/InDomTable.h"
31-
#include "pcp/PCPMetric.h"
31+
#include "pcp/Metric.h"
3232

3333

3434
Instance* Instance_new(const Machine* host, const InDomTable* indom) {
@@ -62,11 +62,11 @@ static void Instance_writeField(const Row* super, RichString* str, RowField fiel
6262
const Settings* settings = super->host->settings;
6363
DynamicColumn* column = Hashtable_get(settings->dynamicColumns, field);
6464
PCPDynamicColumn* cp = (PCPDynamicColumn*) column;
65-
const pmDesc* descp = PCPMetric_desc(cp->id);
65+
const pmDesc* descp = Metric_desc(cp->id);
6666

6767
pmAtomValue atom;
6868
pmAtomValue *ap = &atom;
69-
if (!PCPMetric_instance(cp->id, instid, this->offset, ap, descp->type))
69+
if (!Metric_instance(cp->id, instid, this->offset, ap, descp->type))
7070
ap = NULL;
7171

7272
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) {
9696
return -1;
9797

9898
size_t metric = column->id;
99-
unsigned int type = PCPMetric_type(metric);
99+
unsigned int type = Metric_type(metric);
100100

101101
pmAtomValue atom1 = {0}, atom2 = {0};
102-
if (!PCPMetric_instance(metric, i1->offset, i1->offset, &atom1, type) ||
103-
!PCPMetric_instance(metric, i2->offset, i2->offset, &atom2, type)) {
102+
if (!Metric_instance(metric, i1->offset, i1->offset, &atom1, type) ||
103+
!Metric_instance(metric, i2->offset, i2->offset, &atom2, type)) {
104104
if (type == PM_TYPE_STRING) {
105105
free(atom1.cp);
106106
free(atom2.cp);

pcp/PCPMetric.c renamed to pcp/Metric.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
htop - PCPMetric.c
2+
htop - Metric.c
33
(C) 2020-2021 htop dev team
44
(C) 2020-2021 Red Hat, Inc.
55
Released under the GNU GPLv2+, see the COPYING file
@@ -8,7 +8,7 @@ in the source distribution for its full text.
88

99
#include "config.h" // IWYU pragma: keep
1010

11-
#include "pcp/PCPMetric.h"
11+
#include "pcp/Metric.h"
1212

1313
#include <stddef.h>
1414
#include <stdio.h>
@@ -21,15 +21,15 @@ in the source distribution for its full text.
2121

2222
extern Platform* pcp;
2323

24-
const pmDesc* PCPMetric_desc(PCPMetric metric) {
24+
const pmDesc* Metric_desc(Metric metric) {
2525
return &pcp->descs[metric];
2626
}
2727

28-
int PCPMetric_type(PCPMetric metric) {
28+
int Metric_type(Metric metric) {
2929
return pcp->descs[metric].type;
3030
}
3131

32-
pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type) {
32+
pmAtomValue* Metric_values(Metric metric, pmAtomValue* atom, int count, int type) {
3333
if (pcp->result == NULL)
3434
return NULL;
3535

@@ -54,14 +54,14 @@ pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, in
5454
return atom;
5555
}
5656

57-
int PCPMetric_instanceCount(PCPMetric metric) {
57+
int Metric_instanceCount(Metric metric) {
5858
pmValueSet* vset = pcp->result->vset[metric];
5959
if (vset)
6060
return vset->numval;
6161
return 0;
6262
}
6363

64-
int PCPMetric_instanceOffset(PCPMetric metric, int inst) {
64+
int Metric_instanceOffset(Metric metric, int inst) {
6565
pmValueSet* vset = pcp->result->vset[metric];
6666
if (!vset || vset->numval <= 0)
6767
return 0;
@@ -74,7 +74,7 @@ int PCPMetric_instanceOffset(PCPMetric metric, int inst) {
7474
return 0;
7575
}
7676

77-
static pmAtomValue* PCPMetric_extract(PCPMetric metric, int inst, int offset, pmValueSet* vset, pmAtomValue* atom, int type) {
77+
static pmAtomValue* Metric_extract(Metric metric, int inst, int offset, pmValueSet* vset, pmAtomValue* atom, int type) {
7878

7979
/* extract value (using requested type) of given metric instance */
8080
const pmDesc* desc = &pcp->descs[metric];
@@ -89,20 +89,20 @@ static pmAtomValue* PCPMetric_extract(PCPMetric metric, int inst, int offset, pm
8989
return atom;
9090
}
9191

92-
pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomValue* atom, int type) {
92+
pmAtomValue* Metric_instance(Metric metric, int inst, int offset, pmAtomValue* atom, int type) {
9393

9494
pmValueSet* vset = pcp->result->vset[metric];
9595
if (!vset || vset->numval <= 0)
9696
return NULL;
9797

9898
/* fast-path using heuristic offset based on expected location */
9999
if (offset >= 0 && offset < vset->numval && inst == vset->vlist[offset].inst)
100-
return PCPMetric_extract(metric, inst, offset, vset, atom, type);
100+
return Metric_extract(metric, inst, offset, vset, atom, type);
101101

102102
/* slow-path using a linear search for the requested instance */
103103
for (int i = 0; i < vset->numval; i++) {
104104
if (inst == vset->vlist[i].inst)
105-
return PCPMetric_extract(metric, inst, i, vset, atom, type);
105+
return Metric_extract(metric, inst, i, vset, atom, type);
106106
}
107107
return NULL;
108108
}
@@ -113,7 +113,7 @@ pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomVa
113113
*
114114
* Start it off by passing offset -1 into the routine.
115115
*/
116-
bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp) {
116+
bool Metric_iterate(Metric metric, int* instp, int* offsetp) {
117117
if (!pcp->result)
118118
return false;
119119

@@ -132,15 +132,15 @@ bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp) {
132132
}
133133

134134
/* Switch on/off a metric for value fetching (sampling) */
135-
void PCPMetric_enable(PCPMetric metric, bool enable) {
135+
void Metric_enable(Metric metric, bool enable) {
136136
pcp->fetch[metric] = enable ? pcp->pmids[metric] : PM_ID_NULL;
137137
}
138138

139-
bool PCPMetric_enabled(PCPMetric metric) {
139+
bool Metric_enabled(Metric metric) {
140140
return pcp->fetch[metric] != PM_ID_NULL;
141141
}
142142

143-
void PCPMetric_enableThreads(void) {
143+
void Metric_enableThreads(void) {
144144
pmValueSet* vset = xCalloc(1, sizeof(pmValueSet));
145145
vset->vlist[0].inst = PM_IN_NULL;
146146
vset->vlist[0].value.lval = 1;
@@ -159,7 +159,7 @@ void PCPMetric_enableThreads(void) {
159159
pmFreeResult(result);
160160
}
161161

162-
bool PCPMetric_fetch(struct timeval* timestamp) {
162+
bool Metric_fetch(struct timeval* timestamp) {
163163
if (pcp->result) {
164164
pmFreeResult(pcp->result);
165165
pcp->result = NULL;
@@ -179,12 +179,12 @@ bool PCPMetric_fetch(struct timeval* timestamp) {
179179
return true;
180180
}
181181

182-
void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName) {
182+
void Metric_externalName(Metric metric, int inst, char** externalName) {
183183
const pmDesc* desc = &pcp->descs[metric];
184184
pmNameInDom(desc->indom, inst, externalName);
185185
}
186186

187-
int PCPMetric_lookupText(const char* metric, char** desc) {
187+
int Metric_lookupText(const char* metric, char** desc) {
188188
pmID pmid;
189189
int sts;
190190

pcp/PCPMetric.h renamed to pcp/Metric.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ifndef HEADER_PCPMetric
2-
#define HEADER_PCPMetric
1+
#ifndef HEADER_Metric
2+
#define HEADER_Metric
33
/*
4-
htop - PCPMetric.h
4+
htop - Metric.h
55
(C) 2020-2021 htop dev team
66
(C) 2020-2021 Red Hat, Inc.
77
Released under the GNU GPLv2+, see the COPYING file
@@ -22,7 +22,7 @@ in the source distribution for its full text.
2222
#undef PACKAGE_BUGREPORT
2323

2424

25-
typedef enum PCPMetric_ {
25+
typedef enum Metric_ {
2626
PCP_CONTROL_THREADS, /* proc.control.perclient.threads */
2727

2828
PCP_HINV_NCPU, /* hinv.ncpu */
@@ -156,32 +156,32 @@ typedef enum PCPMetric_ {
156156
PCP_PROC_SMAPS_SWAPPSS, /* proc.smaps.swappss */
157157

158158
PCP_METRIC_COUNT /* total metric count */
159-
} PCPMetric;
159+
} Metric;
160160

161-
void PCPMetric_enable(PCPMetric metric, bool enable);
161+
void Metric_enable(Metric metric, bool enable);
162162

163-
bool PCPMetric_enabled(PCPMetric metric);
163+
bool Metric_enabled(Metric metric);
164164

165-
void PCPMetric_enableThreads(void);
165+
void Metric_enableThreads(void);
166166

167-
bool PCPMetric_fetch(struct timeval* timestamp);
167+
bool Metric_fetch(struct timeval* timestamp);
168168

169-
bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp);
169+
bool Metric_iterate(Metric metric, int* instp, int* offsetp);
170170

171-
pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type);
171+
pmAtomValue* Metric_values(Metric metric, pmAtomValue* atom, int count, int type);
172172

173-
const pmDesc* PCPMetric_desc(PCPMetric metric);
173+
const pmDesc* Metric_desc(Metric metric);
174174

175-
int PCPMetric_type(PCPMetric metric);
175+
int Metric_type(Metric metric);
176176

177-
int PCPMetric_instanceCount(PCPMetric metric);
177+
int Metric_instanceCount(Metric metric);
178178

179-
int PCPMetric_instanceOffset(PCPMetric metric, int inst);
179+
int Metric_instanceOffset(Metric metric, int inst);
180180

181-
pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomValue* atom, int type);
181+
pmAtomValue* Metric_instance(Metric metric, int inst, int offset, pmAtomValue* atom, int type);
182182

183-
void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName);
183+
void Metric_externalName(Metric metric, int inst, char** externalName);
184184

185-
int PCPMetric_lookupText(const char* metric, char** desc);
185+
int Metric_lookupText(const char* metric, char** desc);
186186

187187
#endif

pcp/PCPDynamicColumn.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ in the source distribution for its full text.
2828
#include "XUtils.h"
2929

3030
#include "linux/CGroupUtils.h"
31+
#include "pcp/Metric.h"
3132
#include "pcp/PCPProcess.h"
32-
#include "pcp/PCPMetric.h"
3333

3434

3535
static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicColumn* column) {
@@ -51,7 +51,7 @@ static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicCol
5151
static void PCPDynamicColumn_parseMetric(PCPDynamicColumns* columns, PCPDynamicColumn* column, const char* path, unsigned int line, char* value) {
5252
/* pmLookupText */
5353
if (!column->super.description)
54-
PCPMetric_lookupText(value, &column->super.description);
54+
Metric_lookupText(value, &column->super.description);
5555

5656
/* lookup a dynamic metric with this name, else create */
5757
if (PCPDynamicColumn_addMetric(columns, column) == false)
@@ -268,7 +268,7 @@ static void PCPDynamicColumn_setupWidth(ATTR_UNUSED ht_key_t key, void* value, A
268268
PCPDynamicColumn* column = (PCPDynamicColumn*) value;
269269

270270
/* calculate column size based on config file and metric units */
271-
const pmDesc* desc = PCPMetric_desc(column->id);
271+
const pmDesc* desc = Metric_desc(column->id);
272272

273273
if (column->instances || desc->type == PM_TYPE_STRING) {
274274
column->super.width = column->width;
@@ -376,7 +376,7 @@ void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str,
376376
char* dupd1 = NULL;
377377
if (column->instances) {
378378
attr = CRT_colors[DYNAMIC_GRAY];
379-
PCPMetric_externalName(metric, instance, &dupd1);
379+
Metric_externalName(metric, instance, &dupd1);
380380
value = dupd1;
381381
} else {
382382
attr = CRT_colors[DYNAMIC_GREEN];
@@ -454,12 +454,12 @@ void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str,
454454
void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, RichString* str) {
455455
const Settings* settings = proc->super.host->settings;
456456
const PCPProcess* pp = (const PCPProcess*) proc;
457-
const pmDesc* desc = PCPMetric_desc(this->id);
457+
const pmDesc* desc = Metric_desc(this->id);
458458
pid_t pid = Process_getPid(proc);
459459

460460
pmAtomValue atom;
461461
pmAtomValue *ap = &atom;
462-
if (!PCPMetric_instance(this->id, pid, pp->offset, ap, desc->type))
462+
if (!Metric_instance(this->id, pid, pp->offset, ap, desc->type))
463463
ap = NULL;
464464

465465
PCPDynamicColumn_writeAtomValue(this, str, settings, this->id, pid, desc, ap);
@@ -474,11 +474,11 @@ int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, Pr
474474
return -1;
475475

476476
size_t metric = column->id;
477-
unsigned int type = PCPMetric_type(metric);
477+
unsigned int type = Metric_type(metric);
478478

479479
pmAtomValue atom1 = {0}, atom2 = {0};
480-
if (!PCPMetric_instance(metric, Process_getPid(&p1->super), p1->offset, &atom1, type) ||
481-
!PCPMetric_instance(metric, Process_getPid(&p2->super), p2->offset, &atom2, type)) {
480+
if (!Metric_instance(metric, Process_getPid(&p1->super), p1->offset, &atom1, type) ||
481+
!Metric_instance(metric, Process_getPid(&p2->super), p2->offset, &atom2, type)) {
482482
if (type == PM_TYPE_STRING) {
483483
free(atom1.cp);
484484
free(atom2.cp);

0 commit comments

Comments
 (0)