Skip to content

Commit 0ede417

Browse files
committed
normalized columns values
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
1 parent 38027e4 commit 0ede417

9 files changed

Lines changed: 162 additions & 26 deletions

File tree

pcp/PCPDynamicColumn.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static PCPDynamicColumn* PCPDynamicColumn_new(PCPDynamicColumns* columns, const
114114
String_safeStrncpy(column->super.name, name, sizeof(column->super.name));
115115
column->instances = false;
116116
column->super.enabled = true;
117+
column->scale = false;
117118

118119
size_t id = columns->count + LAST_PROCESSFIELD;
119120
Hashtable_put(columns->table, id, column);
@@ -172,6 +173,9 @@ static void PCPDynamicColumn_parseFile(PCPDynamicColumns* columns, const char* p
172173
} else if (value && column && String_eq(key, "enabled")) {
173174
if (String_eq(value, "False") || String_eq(value, "false"))
174175
column->super.enabled = false;
176+
} else if (value && column && String_eq(key, "scale")) {
177+
if (String_eq(value, "True") || String_eq(value, "true"))
178+
column->scale = true;
175179
} else if (value && column && String_eq(key, "metric")) {
176180
PCPDynamicColumn_parseMetric(columns, column, path, lineno, value);
177181
}
@@ -263,7 +267,7 @@ void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, Ri
263267

264268
pmAtomValue atom;
265269
if (!PCPMetric_instance(this->id, proc->pid, pp->offset, &atom, type)) {
266-
RichString_appendAscii(str, CRT_colors[METER_VALUE_ERROR], "no data");
270+
RichString_appendAscii(str, CRT_colors[DYNAMIC_RED], "no data");
267271
return;
268272
}
269273

@@ -309,7 +313,7 @@ void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, Ri
309313
RichString_appendAscii(str, attr, buffer);
310314
break;
311315
default:
312-
attr = CRT_colors[METER_VALUE_ERROR];
316+
attr = CRT_colors[DYNAMIC_RED];
313317
RichString_appendAscii(str, attr, "no type");
314318
break;
315319
}

pcp/PCPDynamicColumn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef struct PCPDynamicColumn_ {
1616
char* metricName;
1717
size_t id; /* identifier for metric array lookups */
1818
bool instances;
19+
bool scale;
1920
} PCPDynamicColumn;
2021

2122
typedef struct PCPDynamicColumns_ {

pcp/PCPDynamicScreen.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ in the source distribution for its full text.
2727

2828
void PCPDynamicScreens_appendDynamicColumns(PCPDynamicScreens* screens, PCPDynamicColumns* columns) {
2929
for (unsigned int i = 0; i < screens->count; i++) {
30-
PCPDynamicScreen *screen = Hashtable_get(screens->table, i);
30+
PCPDynamicScreen* screen = Hashtable_get(screens->table, i);
3131
if (!screen)
3232
return;
3333

34-
for (unsigned int column = 0; column < screen->totalColumns; column++) {
35-
screen->columns[column].id = columns->offset + columns->cursor;
34+
for (unsigned int j = 0; j < screen->totalColumns; j++) {
35+
PCPDynamicColumn* column = &screen->columns[j];
36+
37+
column->id = columns->offset + columns->cursor;
3638
columns->cursor++;
37-
Platform_addMetric(screen->columns[column].id, screen->columns[column].metricName);
39+
40+
Platform_addMetric(column->id, column->metricName);
3841
size_t id = columns->count + LAST_PROCESSFIELD;
39-
Hashtable_put(columns->table, id, &screen->columns[column]);
42+
Hashtable_put(columns->table, id, column);
4043
columns->count++;
4144
}
4245
}
@@ -69,6 +72,7 @@ static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen,
6972
column->instances = false;
7073
column->super.belongToDynamicScreen = true;
7174
column->super.enabled = true;
75+
column->scale = false;
7276

7377
return column;
7478
}
@@ -120,6 +124,9 @@ static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* p
120124
} else if (String_eq(p, "enabled")) { /* default is True */
121125
if (String_eq(value, "False") || String_eq(value, "false"))
122126
column->super.enabled = false;
127+
} else if (String_eq(p, "scale")) {
128+
if (String_eq(value, "True") || String_eq(value, "true"))
129+
column->scale = true;
123130
}
124131
}
125132
}

pcp/PCPGenericData.c

Lines changed: 123 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ void PCPGenericData_removeAllFields(PCPGenericData* this)
8383
}
8484
}
8585

86+
#define PrintField(format, value) \
87+
xSnprintf(buffer, sizeof(buffer), format, width, value);\
88+
RichString_appendAscii(str, attr, buffer);
89+
90+
#define KBytesField(format, val) \
91+
pmConvScale(format, gf->value, &gf->units, &atom, &kbyte_scale);\
92+
Process_printKBytes(str, val, coloring);
93+
94+
#define TimeField(format, val) \
95+
pmConvScale(format, gf->value, &gf->units, &atom, &sec_scale);\
96+
Process_printTime(str, val, coloring);
97+
98+
#define CountField(format, val) \
99+
pmConvScale(format, gf->value, &gf->units, &atom, &count_scale);\
100+
Process_printCount(str, val, coloring);
101+
86102
static void PCPGenericData_writeField(const GenericData* this, RichString* str, int field) {
87103
const PCPGenericData* gg = (const PCPGenericData*) this;
88104
PCPGenericDataField* gf = (PCPGenericDataField*)Hashtable_get(gg->fields, field);
@@ -92,6 +108,7 @@ static void PCPGenericData_writeField(const GenericData* this, RichString* str,
92108
const ProcessField* fields = this->settings->ss->fields;
93109
char buffer[256];
94110
int attr = CRT_colors[DEFAULT_COLOR];
111+
bool coloring = this->settings->highlightMegabytes;
95112

96113
DynamicColumn* dc = Hashtable_get(this->settings->dynamicColumns, fields[field]);
97114
if (!dc || !dc->enabled)
@@ -100,6 +117,21 @@ static void PCPGenericData_writeField(const GenericData* this, RichString* str,
100117
PCPDynamicColumn* column = (PCPDynamicColumn*) dc;
101118
bool instances = column->instances;
102119

120+
bool scaled = column->scale;
121+
pmAtomValue atom;
122+
pmUnits kbyte_scale;
123+
124+
kbyte_scale.dimSpace = 1;
125+
kbyte_scale.scaleSpace = PM_SPACE_KBYTE;
126+
127+
pmUnits sec_scale;
128+
sec_scale.dimTime = 1;
129+
sec_scale.scaleTime = PM_TIME_SEC;
130+
131+
pmUnits count_scale;
132+
count_scale.dimCount = 1;
133+
count_scale.scaleCount = PM_COUNT_ONE;
134+
103135
int width = column->super.width;
104136
if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
105137
width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
@@ -125,32 +157,104 @@ static void PCPGenericData_writeField(const GenericData* this, RichString* str,
125157
RichString_appendAscii(str, attr, buffer);
126158
break;
127159
case PM_TYPE_32:
128-
xSnprintf(buffer, sizeof(buffer), "%*d ", width, gf->value->l);
129-
RichString_appendAscii(str, attr, buffer);
130-
break;
160+
if (scaled) {
161+
if (gf->units.dimSpace) {
162+
KBytesField(PM_TYPE_32, atom.l);
163+
break;
164+
} else if (gf->units.dimTime) {
165+
TimeField(PM_TYPE_32, atom.l);
166+
break;
167+
} else {
168+
CountField(PM_TYPE_32, atom.l);
169+
break;
170+
}
171+
} else {
172+
PrintField("%*d ", gf->value->l);
173+
break;
174+
}
131175
case PM_TYPE_U32:
132-
xSnprintf(buffer, sizeof(buffer), "%*u ", width, gf->value->ul);
133-
RichString_appendAscii(str, attr, buffer);
134-
break;
176+
if (scaled) {
177+
if (gf->units.dimSpace) {
178+
KBytesField(PM_TYPE_U32, atom.ul);
179+
break;
180+
} else if (gf->units.dimTime) {
181+
TimeField(PM_TYPE_U32, atom.ul);
182+
break;
183+
} else {
184+
CountField(PM_TYPE_U32, atom.ul);
185+
break;
186+
}
187+
} else {
188+
PrintField("%*u ", gf->value->ul);
189+
break;
190+
}
135191
case PM_TYPE_64:
136-
xSnprintf(buffer, sizeof(buffer), "%*lld ", width, (long long) gf->value->ll);
137-
RichString_appendAscii(str, attr, buffer);
138-
break;
192+
if (scaled) {
193+
if (gf->units.dimSpace) {
194+
KBytesField(PM_TYPE_64, atom.ll);
195+
break;
196+
} else if (gf->units.dimTime) {
197+
TimeField(PM_TYPE_64, atom.ll);
198+
break;
199+
} else {
200+
CountField(PM_TYPE_64, atom.ll);
201+
break;
202+
}
203+
} else {
204+
PrintField("%*lld ", (long long)gf->value->ll);
205+
break;
206+
}
139207
case PM_TYPE_U64:
140-
xSnprintf(buffer, sizeof(buffer), "%*llu ", width, (unsigned long long) gf->value->ull);
141-
RichString_appendAscii(str, attr, buffer);
142-
break;
208+
if (scaled) {
209+
if (gf->units.dimSpace) {
210+
KBytesField(PM_TYPE_U64, atom.ull);
211+
break;
212+
} else if (gf->units.dimTime) {
213+
TimeField(PM_TYPE_U64, atom.ull);
214+
break;
215+
} else {
216+
CountField(PM_TYPE_U64, atom.ull);
217+
break;
218+
}
219+
} else {
220+
PrintField("%*llu ", (unsigned long long)gf->value->ull);
221+
break;
222+
}
143223
case PM_TYPE_FLOAT:
144-
xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, (double) gf->value->f);
145-
RichString_appendAscii(str, attr, buffer);
146-
break;
224+
if (scaled) {
225+
if (gf->units.dimSpace) {
226+
KBytesField(PM_TYPE_FLOAT, atom.f);
227+
break;
228+
} else if (gf->units.dimTime) {
229+
TimeField(PM_TYPE_FLOAT, atom.f);
230+
break;
231+
} else {
232+
CountField(PM_TYPE_FLOAT, atom.f);
233+
break;
234+
}
235+
} else {
236+
PrintField("%*.2f ", (double)gf->value->f);
237+
break;
238+
}
147239
case PM_TYPE_DOUBLE:
148-
xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, gf->value->d);
149-
RichString_appendAscii(str, attr, buffer);
150-
break;
240+
if (scaled) {
241+
if (gf->units.dimSpace) {
242+
KBytesField(PM_TYPE_DOUBLE, atom.d);
243+
break;
244+
} else if (gf->units.dimTime) {
245+
TimeField(PM_TYPE_DOUBLE, atom.d);
246+
break;
247+
} else {
248+
CountField(PM_TYPE_DOUBLE, atom.d);
249+
break;
250+
}
251+
} else {
252+
PrintField("%*.2f ", gf->value->d);
253+
break;
254+
}
151255
default:
152256
attr = CRT_colors[DYNAMIC_RED];
153-
RichString_appendAscii(str, attr, "no data");
257+
RichString_appendAscii(str, attr, "no data ");
154258
break;
155259
}
156260
}

pcp/PCPGenericData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ typedef struct PCPGenericDataField_ {
2828
int interInst;
2929

3030
int type;
31+
32+
pmUnits units;
3133
} PCPGenericDataField;
3234

3335
typedef struct PCPGenericData_ {

pcp/PCPGenericDataList.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static int PCPGenericDataList_updateGenericDataList(PCPGenericDataList* this) {
173173
field->pmid = column->id;
174174
field->offset = offset;
175175
field->interInst = interInst;
176+
field->units = PCPMetric_units(column->id);
176177
}
177178
}
178179
}

pcp/PCPMetric.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ int PCPMetric_type(PCPMetric metric) {
2929
return pcp->descs[metric].type;
3030
}
3131

32+
pmUnits PCPMetric_units(PCPMetric metric) {
33+
return pcp->descs[metric].units;
34+
}
35+
3236
pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type) {
3337
if (pcp->result == NULL)
3438
return NULL;

pcp/PCPMetric.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp);
166166

167167
pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type);
168168

169+
pmUnits PCPMetric_units(PCPMetric metric);
170+
169171
const pmDesc* PCPMetric_desc(PCPMetric metric);
170172

171173
int PCPMetric_type(PCPMetric metric);

pcp/screens/filesys

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,68 @@ avail.heading = AVAIL
1010
avail.caption = avail
1111
avail.width = -12
1212
avail.metric = filesys.avail
13+
avail.scale = true
1314

1415
blocksize.heading = BSIZE
1516
blocksize.caption = blocksize
1617
blocksize.width = -12
1718
blocksize.metric = filesys.blocksize
1819
blocksize.enabled = false
20+
blocksize.scale = true
1921

2022
capacity.heading = SIZE
2123
capacity.caption = capacity
2224
capacity.width = -12
2325
capacity.metric = filesys.capacity
26+
capacity.scale = true
2427

2528
free.heading = FREE
2629
free.caption = free
2730
free.width = -12
2831
free.metric = filesys.free
32+
free.scale = true
2933

3034
freefiles.heading = FREEF
3135
freefiles.caption = freefiles
3236
freefiles.width = -12
3337
freefiles.metric = filesys.freefiles
38+
freefiles.scale = true
3439

3540
full.heading = FULL
3641
full.caption = full
3742
full.width = -12
3843
full.metric = filesys.full
3944
#full.percent = true
45+
full.scale = true
4046

4147
maxfiles.heading = MAXF
4248
maxfiles.caption = maxfiles
4349
maxfiles.width = -12
4450
maxfiles.metric = filesys.maxfiles
4551
maxfiles.enabled = false
52+
maxfiles.scale = true
4653

4754
readonly.heading = RO
4855
readonly.caption = readonly
4956
readonly.width = -12
5057
readonly.metric = filesys.readonly
5158
readonly.enabled = false
59+
readonly.scale = true
5260

5361
used.heading = USED
5462
used.caption = used
5563
used.width = -12
5664
used.metric = filesys.used
65+
used.scale = true
5766

5867
usedfiles.heading = USEDF
5968
usedfiles.caption = usedfiles
6069
usedfiles.metric = filesys.usedfiles
6170
usedfiles.enabled = false
71+
usedfiles.scale = true
6272

6373
mountdir.heading = Mount point
6474
mountdir.caption = mountdir
6575
mountdir.width = -12
6676
mountdir.metric = filesys.mountdir
77+
mountdir.scale = true

0 commit comments

Comments
 (0)