Skip to content

Commit

Permalink
normalized columns values
Browse files Browse the repository at this point in the history
Signed-off-by: Sohaib Mohamed <[email protected]>
  • Loading branch information
smalinux authored and BenBE committed Feb 4, 2023
1 parent 6c1d937 commit 137ff12
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 26 deletions.
8 changes: 6 additions & 2 deletions pcp/PCPDynamicColumn.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static PCPDynamicColumn* PCPDynamicColumn_new(PCPDynamicColumns* columns, const
String_safeStrncpy(column->super.name, name, sizeof(column->super.name));
column->instances = false;
column->super.enabled = true;
column->scale = false;

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

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

Expand Down Expand Up @@ -309,7 +313,7 @@ void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, Ri
RichString_appendAscii(str, attr, buffer);
break;
default:
attr = CRT_colors[METER_VALUE_ERROR];
attr = CRT_colors[DYNAMIC_RED];
RichString_appendAscii(str, attr, "no type");
break;
}
Expand Down
1 change: 1 addition & 0 deletions pcp/PCPDynamicColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct PCPDynamicColumn_ {
char* metricName;
size_t id; /* identifier for metric array lookups */
bool instances;
bool scale;
} PCPDynamicColumn;

typedef struct PCPDynamicColumns_ {
Expand Down
17 changes: 12 additions & 5 deletions pcp/PCPDynamicScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ in the source distribution for its full text.

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

for (unsigned int column = 0; column < screen->totalColumns; column++) {
screen->columns[column].id = columns->offset + columns->cursor;
for (unsigned int j = 0; j < screen->totalColumns; j++) {
PCPDynamicColumn* column = &screen->columns[j];

column->id = columns->offset + columns->cursor;
columns->cursor++;
Platform_addMetric(screen->columns[column].id, screen->columns[column].metricName);

Platform_addMetric(column->id, column->metricName);
size_t id = columns->count + LAST_PROCESSFIELD;
Hashtable_put(columns->table, id, &screen->columns[column]);
Hashtable_put(columns->table, id, column);
columns->count++;
}
}
Expand Down Expand Up @@ -70,6 +73,7 @@ static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen,
column->instances = false;
column->super.belongToDynamicScreen = true;
column->super.enabled = true;
column->scale = false;

return column;
}
Expand Down Expand Up @@ -121,6 +125,9 @@ static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* p
} else if (String_eq(p, "enabled")) { /* default is True */
if (String_eq(value, "False") || String_eq(value, "false"))
column->super.enabled = false;
} else if (String_eq(p, "scale")) {
if (String_eq(value, "True") || String_eq(value, "true"))
column->scale = true;
}
}
}
Expand Down
142 changes: 123 additions & 19 deletions pcp/PCPGenericData.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ void PCPGenericData_removeAllFields(PCPGenericData* this)
}
}

#define PrintField(format, value) \
xSnprintf(buffer, sizeof(buffer), format, width, value);\
RichString_appendAscii(str, attr, buffer);

#define KBytesField(format, val) \
pmConvScale(format, gf->value, &gf->units, &atom, &kbyte_scale);\
Process_printKBytes(str, val, coloring);

#define TimeField(format, val) \
pmConvScale(format, gf->value, &gf->units, &atom, &sec_scale);\
Process_printTime(str, val, coloring);

#define CountField(format, val) \
pmConvScale(format, gf->value, &gf->units, &atom, &count_scale);\
Process_printCount(str, val, coloring);

static void PCPGenericData_writeField(const GenericData* this, RichString* str, int field) {
const PCPGenericData* gg = (const PCPGenericData*) this;
PCPGenericDataField* gf = (PCPGenericDataField*)Hashtable_get(gg->fields, field);
Expand All @@ -92,6 +108,7 @@ static void PCPGenericData_writeField(const GenericData* this, RichString* str,
const ProcessField* fields = this->settings->ss->fields;
char buffer[256];
int attr = CRT_colors[DEFAULT_COLOR];
bool coloring = this->settings->highlightMegabytes;

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

bool scaled = column->scale;
pmAtomValue atom;
pmUnits kbyte_scale;

kbyte_scale.dimSpace = 1;
kbyte_scale.scaleSpace = PM_SPACE_KBYTE;

pmUnits sec_scale;
sec_scale.dimTime = 1;
sec_scale.scaleTime = PM_TIME_SEC;

pmUnits count_scale;
count_scale.dimCount = 1;
count_scale.scaleCount = PM_COUNT_ONE;

int width = column->super.width;
if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
Expand All @@ -125,32 +157,104 @@ static void PCPGenericData_writeField(const GenericData* this, RichString* str,
RichString_appendAscii(str, attr, buffer);
break;
case PM_TYPE_32:
xSnprintf(buffer, sizeof(buffer), "%*d ", width, gf->value->l);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_32, atom.l);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_32, atom.l);
break;
} else {
CountField(PM_TYPE_32, atom.l);
break;
}
} else {
PrintField("%*d ", gf->value->l);
break;
}
case PM_TYPE_U32:
xSnprintf(buffer, sizeof(buffer), "%*u ", width, gf->value->ul);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_U32, atom.ul);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_U32, atom.ul);
break;
} else {
CountField(PM_TYPE_U32, atom.ul);
break;
}
} else {
PrintField("%*u ", gf->value->ul);
break;
}
case PM_TYPE_64:
xSnprintf(buffer, sizeof(buffer), "%*lld ", width, (long long) gf->value->ll);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_64, atom.ll);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_64, atom.ll);
break;
} else {
CountField(PM_TYPE_64, atom.ll);
break;
}
} else {
PrintField("%*lld ", (long long)gf->value->ll);
break;
}
case PM_TYPE_U64:
xSnprintf(buffer, sizeof(buffer), "%*llu ", width, (unsigned long long) gf->value->ull);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_U64, atom.ull);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_U64, atom.ull);
break;
} else {
CountField(PM_TYPE_U64, atom.ull);
break;
}
} else {
PrintField("%*llu ", (unsigned long long)gf->value->ull);
break;
}
case PM_TYPE_FLOAT:
xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, (double) gf->value->f);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_FLOAT, atom.f);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_FLOAT, atom.f);
break;
} else {
CountField(PM_TYPE_FLOAT, atom.f);
break;
}
} else {
PrintField("%*.2f ", (double)gf->value->f);
break;
}
case PM_TYPE_DOUBLE:
xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, gf->value->d);
RichString_appendAscii(str, attr, buffer);
break;
if (scaled) {
if (gf->units.dimSpace) {
KBytesField(PM_TYPE_DOUBLE, atom.d);
break;
} else if (gf->units.dimTime) {
TimeField(PM_TYPE_DOUBLE, atom.d);
break;
} else {
CountField(PM_TYPE_DOUBLE, atom.d);
break;
}
} else {
PrintField("%*.2f ", gf->value->d);
break;
}
default:
attr = CRT_colors[DYNAMIC_RED];
RichString_appendAscii(str, attr, "no data");
RichString_appendAscii(str, attr, "no data ");
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions pcp/PCPGenericData.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ typedef struct PCPGenericDataField_ {
int interInst;

int type;

pmUnits units;
} PCPGenericDataField;

typedef struct PCPGenericData_ {
Expand Down
1 change: 1 addition & 0 deletions pcp/PCPGenericDataList.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static int PCPGenericDataList_updateGenericDataList(PCPGenericDataList* this) {
field->pmid = column->id;
field->offset = offset;
field->interInst = interInst;
field->units = PCPMetric_units(column->id);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions pcp/PCPMetric.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ int PCPMetric_type(PCPMetric metric) {
return pcp->descs[metric].type;
}

pmUnits PCPMetric_units(PCPMetric metric) {
return pcp->descs[metric].units;
}

pmAtomValue* PCPMetric_values(PCPMetric metric, pmAtomValue* atom, int count, int type) {
if (pcp->result == NULL)
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions pcp/PCPMetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ bool PCPMetric_iterate(PCPMetric metric, int* instp, int* offsetp);

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

pmUnits PCPMetric_units(PCPMetric metric);

const pmDesc* PCPMetric_desc(PCPMetric metric);

int PCPMetric_type(PCPMetric metric);
Expand Down
11 changes: 11 additions & 0 deletions pcp/screens/filesys
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,68 @@ avail.heading = AVAIL
avail.caption = avail
avail.width = -12
avail.metric = filesys.avail
avail.scale = true

blocksize.heading = BSIZE
blocksize.caption = blocksize
blocksize.width = -12
blocksize.metric = filesys.blocksize
blocksize.enabled = false
blocksize.scale = true

capacity.heading = SIZE
capacity.caption = capacity
capacity.width = -12
capacity.metric = filesys.capacity
capacity.scale = true

free.heading = FREE
free.caption = free
free.width = -12
free.metric = filesys.free
free.scale = true

freefiles.heading = FREEF
freefiles.caption = freefiles
freefiles.width = -12
freefiles.metric = filesys.freefiles
freefiles.scale = true

full.heading = FULL
full.caption = full
full.width = -12
full.metric = filesys.full
#full.percent = true
full.scale = true

maxfiles.heading = MAXF
maxfiles.caption = maxfiles
maxfiles.width = -12
maxfiles.metric = filesys.maxfiles
maxfiles.enabled = false
maxfiles.scale = true

readonly.heading = RO
readonly.caption = readonly
readonly.width = -12
readonly.metric = filesys.readonly
readonly.enabled = false
readonly.scale = true

used.heading = USED
used.caption = used
used.width = -12
used.metric = filesys.used
used.scale = true

usedfiles.heading = USEDF
usedfiles.caption = usedfiles
usedfiles.metric = filesys.usedfiles
usedfiles.enabled = false
usedfiles.scale = true

mountdir.heading = Mount point
mountdir.caption = mountdir
mountdir.width = -12
mountdir.metric = filesys.mountdir
mountdir.scale = true

0 comments on commit 137ff12

Please sign in to comment.