Save text buffer in Meter

This commit is contained in:
Christian Göttsche 2020-10-06 13:13:16 +02:00 committed by BenBE
parent 23c5b9ce3c
commit 2d1042adb3
23 changed files with 73 additions and 68 deletions

View File

@ -21,7 +21,7 @@ static const int BatteryMeter_attributes[] = {
BATTERY BATTERY
}; };
static void BatteryMeter_updateValues(Meter* this, char* buffer, size_t len) { static void BatteryMeter_updateValues(Meter* this) {
ACPresence isOnAC; ACPresence isOnAC;
double percent; double percent;
@ -29,7 +29,7 @@ static void BatteryMeter_updateValues(Meter* this, char* buffer, size_t len) {
if (isnan(percent)) { if (isnan(percent)) {
this->values[0] = NAN; this->values[0] = NAN;
xSnprintf(buffer, len, "N/A"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "N/A");
return; return;
} }
@ -49,7 +49,7 @@ static void BatteryMeter_updateValues(Meter* this, char* buffer, size_t len) {
break; break;
} }
xSnprintf(buffer, len, "%.1f%%%s", percent, text); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1f%%%s", percent, text);
} }
const MeterClass BatteryMeter_class = { const MeterClass BatteryMeter_class = {

View File

@ -50,10 +50,10 @@ static void CPUMeter_init(Meter* this) {
Meter_setCaption(this, "Avg"); Meter_setCaption(this, "Avg");
} }
static void CPUMeter_updateValues(Meter* this, char* buffer, size_t size) { static void CPUMeter_updateValues(Meter* this) {
int cpu = this->param; int cpu = this->param;
if (cpu > this->pl->cpuCount) { if (cpu > this->pl->cpuCount) {
xSnprintf(buffer, size, "absent"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "absent");
for (uint8_t i = 0; i < this->curItems; i++) for (uint8_t i = 0; i < this->curItems; i++)
this->values[i] = 0; this->values[i] = 0;
return; return;
@ -91,7 +91,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, size_t size) {
} }
#endif #endif
xSnprintf(buffer, size, "%s%s%s%s%s", xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s%s%s%s%s",
cpuUsageBuffer, cpuUsageBuffer,
(cpuUsageBuffer[0] && (cpuFrequencyBuffer[0] || cpuTemperatureBuffer[0])) ? " " : "", (cpuUsageBuffer[0] && (cpuFrequencyBuffer[0] || cpuTemperatureBuffer[0])) ? " " : "",
cpuFrequencyBuffer, cpuFrequencyBuffer,

View File

@ -19,12 +19,12 @@ static const int ClockMeter_attributes[] = {
CLOCK CLOCK
}; };
static void ClockMeter_updateValues(Meter* this, char* buffer, size_t size) { static void ClockMeter_updateValues(Meter* this) {
time_t t = time(NULL); time_t t = time(NULL);
struct tm result; struct tm result;
const struct tm* lt = localtime_r(&t, &result); const struct tm* lt = localtime_r(&t, &result);
this->values[0] = lt->tm_hour * 60 + lt->tm_min; this->values[0] = lt->tm_hour * 60 + lt->tm_min;
strftime(buffer, size, "%H:%M:%S", lt); strftime(this->txtBuffer, sizeof(this->txtBuffer), "%H:%M:%S", lt);
} }
const MeterClass ClockMeter_class = { const MeterClass ClockMeter_class = {

View File

@ -19,7 +19,7 @@ static const int DateMeter_attributes[] = {
DATE DATE
}; };
static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) { static void DateMeter_updateValues(Meter* this) {
time_t t = time(NULL); time_t t = time(NULL);
struct tm result; struct tm result;
const struct tm* lt = localtime_r(&t, &result); const struct tm* lt = localtime_r(&t, &result);
@ -30,7 +30,7 @@ static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
} else { } else {
this->total = 365; this->total = 365;
} }
strftime(buffer, size, "%F", lt); strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F", lt);
} }
const MeterClass DateMeter_class = { const MeterClass DateMeter_class = {

View File

@ -19,7 +19,7 @@ static const int DateTimeMeter_attributes[] = {
DATETIME DATETIME
}; };
static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) { static void DateTimeMeter_updateValues(Meter* this) {
time_t t = time(NULL); time_t t = time(NULL);
struct tm result; struct tm result;
const struct tm* lt = localtime_r(&t, &result); const struct tm* lt = localtime_r(&t, &result);
@ -30,7 +30,7 @@ static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) {
this->total = 365; this->total = 365;
} }
this->values[0] = lt->tm_yday; this->values[0] = lt->tm_yday;
strftime(buffer, size, "%F %H:%M:%S", lt); strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F %H:%M:%S", lt);
} }
const MeterClass DateTimeMeter_class = { const MeterClass DateTimeMeter_class = {

View File

@ -30,7 +30,7 @@ static uint32_t cached_read_diff;
static uint32_t cached_write_diff; static uint32_t cached_write_diff;
static double cached_utilisation_diff; static double cached_utilisation_diff;
static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) { static void DiskIOMeter_updateValues(Meter* this) {
static uint64_t cached_last_update; static uint64_t cached_last_update;
struct timeval tv; struct timeval tv;
@ -52,7 +52,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
hasData = Platform_getDiskIO(&data); hasData = Platform_getDiskIO(&data);
if (!hasData) { if (!hasData) {
this->values[0] = 0; this->values[0] = 0;
xSnprintf(buffer, len, "no data"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
return; return;
} }
@ -89,7 +89,7 @@ static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
char bufferRead[12], bufferWrite[12]; char bufferRead[12], bufferWrite[12];
Meter_humanUnit(bufferRead, cached_read_diff, sizeof(bufferRead)); Meter_humanUnit(bufferRead, cached_read_diff, sizeof(bufferRead));
Meter_humanUnit(bufferWrite, cached_write_diff, sizeof(bufferWrite)); Meter_humanUnit(bufferWrite, cached_write_diff, sizeof(bufferWrite));
snprintf(buffer, len, "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff); snprintf(this->txtBuffer, sizeof(this->txtBuffer), "%sB %sB %.1f%%", bufferRead, bufferWrite, cached_utilisation_diff);
} }
static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { static void DiskIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {

View File

@ -20,8 +20,8 @@ static const int HostnameMeter_attributes[] = {
HOSTNAME HOSTNAME
}; };
static void HostnameMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) { static void HostnameMeter_updateValues(Meter* this) {
Platform_getHostname(buffer, size); Platform_getHostname(this->txtBuffer, sizeof(this->txtBuffer));
} }
const MeterClass HostnameMeter_class = { const MeterClass HostnameMeter_class = {

View File

@ -36,7 +36,7 @@ static const int High_attributes[] = {
METER_VALUE_ERROR METER_VALUE_ERROR
}; };
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, size_t size) { static void LoadAverageMeter_updateValues(Meter* this) {
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]); Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
// only show bar for 1min value // only show bar for 1min value
@ -54,7 +54,7 @@ static void LoadAverageMeter_updateValues(Meter* this, char* buffer, size_t size
this->total = 2 * this->pl->cpuCount; this->total = 2 * this->pl->cpuCount;
} }
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
} }
static void LoadAverageMeter_display(const Object* cast, RichString* out) { static void LoadAverageMeter_display(const Object* cast, RichString* out) {
@ -68,7 +68,7 @@ static void LoadAverageMeter_display(const Object* cast, RichString* out) {
RichString_appendAscii(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer); RichString_appendAscii(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
} }
static void LoadMeter_updateValues(Meter* this, char* buffer, size_t size) { static void LoadMeter_updateValues(Meter* this) {
double five, fifteen; double five, fifteen;
Platform_getLoadAverage(&this->values[0], &five, &fifteen); Platform_getLoadAverage(&this->values[0], &five, &fifteen);
@ -84,7 +84,7 @@ static void LoadMeter_updateValues(Meter* this, char* buffer, size_t size) {
this->total = 2 * this->pl->cpuCount; this->total = 2 * this->pl->cpuCount;
} }
xSnprintf(buffer, size, "%.2f", this->values[0]); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f", this->values[0]);
} }
static void LoadMeter_display(const Object* cast, RichString* out) { static void LoadMeter_display(const Object* cast, RichString* out) {

View File

@ -21,7 +21,9 @@ static const int MemoryMeter_attributes[] = {
MEMORY_CACHE MEMORY_CACHE
}; };
static void MemoryMeter_updateValues(Meter* this, char* buffer, size_t size) { static void MemoryMeter_updateValues(Meter* this) {
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);
int written; int written;
/* available memory is not supported on all platforms */ /* available memory is not supported on all platforms */

32
Meter.c
View File

@ -96,11 +96,11 @@ void Meter_setCaption(Meter* this, const char* caption) {
free_and_xStrdup(&this->caption, caption); free_and_xStrdup(&this->caption, caption);
} }
static inline void Meter_displayBuffer(const Meter* this, const char* buffer, RichString* out) { static inline void Meter_displayBuffer(const Meter* this, RichString* out) {
if (Object_displayFn(this)) { if (Object_displayFn(this)) {
Object_display(this, out); Object_display(this, out);
} else { } else {
RichString_writeWide(out, CRT_colors[Meter_attributes(this)[0]], buffer); RichString_writeWide(out, CRT_colors[Meter_attributes(this)[0]], this->txtBuffer);
} }
} }
@ -153,9 +153,8 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
/* ---------- TextMeterMode ---------- */ /* ---------- TextMeterMode ---------- */
static void TextMeterMode_draw(Meter* this, int x, int y, int w) { static void TextMeterMode_draw(Meter* this, int x, int y, ATTR_UNUSED int w) {
char buffer[METER_BUFFER_LEN]; Meter_updateValues(this);
Meter_updateValues(this, buffer, sizeof(buffer));
attrset(CRT_colors[METER_TEXT]); attrset(CRT_colors[METER_TEXT]);
mvaddnstr(y, x, this->caption, w - 1); mvaddnstr(y, x, this->caption, w - 1);
@ -168,7 +167,7 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
return; return;
RichString_begin(out); RichString_begin(out);
Meter_displayBuffer(this, buffer, &out); Meter_displayBuffer(this, &out);
RichString_printoffnVal(out, y, x, 0, w - 1); RichString_printoffnVal(out, y, x, 0, w - 1);
RichString_end(out); RichString_end(out);
} }
@ -178,8 +177,7 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
static const char BarMeterMode_characters[] = "|#*@$%&."; static const char BarMeterMode_characters[] = "|#*@$%&.";
static void BarMeterMode_draw(Meter* this, int x, int y, int w) { static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
char buffer[METER_BUFFER_LEN]; Meter_updateValues(this);
Meter_updateValues(this, buffer, sizeof(buffer));
w -= 2; w -= 2;
attrset(CRT_colors[METER_TEXT]); attrset(CRT_colors[METER_TEXT]);
@ -202,7 +200,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// Pad with maximal spaces and then calculate needed starting position offset // Pad with maximal spaces and then calculate needed starting position offset
RichString_begin(bar); RichString_begin(bar);
RichString_appendChr(&bar, 0, ' ', w); RichString_appendChr(&bar, 0, ' ', w);
RichString_appendWide(&bar, 0, buffer); RichString_appendWide(&bar, 0, this->txtBuffer);
int startPos = RichString_sizeVal(bar) - w; int startPos = RichString_sizeVal(bar) - w;
if (startPos > w) { if (startPos > w) {
// Text is too large for bar // Text is too large for bar
@ -297,7 +295,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
this->drawData = xCalloc(1, sizeof(GraphData)); this->drawData = xCalloc(1, sizeof(GraphData));
} }
GraphData* data = this->drawData; GraphData* data = this->drawData;
const int nValues = METER_BUFFER_LEN; const int nValues = METER_GRAPHDATA_SIZE;
const char* const* GraphMeterMode_dots; const char* const* GraphMeterMode_dots;
int GraphMeterMode_pixPerRow; int GraphMeterMode_pixPerRow;
@ -328,8 +326,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
for (int i = 0; i < nValues - 1; i++) for (int i = 0; i < nValues - 1; i++)
data->values[i] = data->values[i + 1]; data->values[i] = data->values[i + 1];
char buffer[METER_BUFFER_LEN]; Meter_updateValues(this);
Meter_updateValues(this, buffer, sizeof(buffer));
double value = 0.0; double value = 0.0;
for (uint8_t i = 0; i < this->curItems; i++) for (uint8_t i = 0; i < this->curItems; i++)
@ -397,11 +394,10 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
#endif #endif
LEDMeterMode_digits = LEDMeterMode_digitsAscii; LEDMeterMode_digits = LEDMeterMode_digitsAscii;
char buffer[METER_BUFFER_LEN]; Meter_updateValues(this);
Meter_updateValues(this, buffer, sizeof(buffer));
RichString_begin(out); RichString_begin(out);
Meter_displayBuffer(this, buffer, &out); Meter_displayBuffer(this, &out);
int yText = int yText =
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
@ -466,10 +462,8 @@ const MeterMode* const Meter_modes[] = {
/* Blank meter */ /* Blank meter */
static void BlankMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) { static void BlankMeter_updateValues(Meter* this) {
if (size > 0) { this->txtBuffer[0] = '\0';
*buffer = 0;
}
} }
static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { static void BlankMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {

11
Meter.h
View File

@ -18,7 +18,8 @@ in the source distribution for its full text.
#include "ProcessList.h" #include "ProcessList.h"
#define METER_BUFFER_LEN 256 #define METER_TXTBUFFER_LEN 256
#define METER_GRAPHDATA_SIZE 256
#define METER_BUFFER_CHECK(buffer, size, written) \ #define METER_BUFFER_CHECK(buffer, size, written) \
do { \ do { \
@ -49,7 +50,7 @@ typedef struct Meter_ Meter;
typedef void(*Meter_Init)(Meter*); typedef void(*Meter_Init)(Meter*);
typedef void(*Meter_Done)(Meter*); typedef void(*Meter_Done)(Meter*);
typedef void(*Meter_UpdateMode)(Meter*, int); typedef void(*Meter_UpdateMode)(Meter*, int);
typedef void(*Meter_UpdateValues)(Meter*, char*, size_t); typedef void(*Meter_UpdateValues)(Meter*);
typedef void(*Meter_Draw)(Meter*, int, int, int); typedef void(*Meter_Draw)(Meter*, int, int, int);
typedef struct MeterClass_ { typedef struct MeterClass_ {
@ -77,8 +78,7 @@ typedef struct MeterClass_ {
#define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_) #define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_)
#define Meter_drawFn(this_) As_Meter(this_)->draw #define Meter_drawFn(this_) As_Meter(this_)->draw
#define Meter_doneFn(this_) As_Meter(this_)->done #define Meter_doneFn(this_) As_Meter(this_)->done
#define Meter_updateValues(this_, buf_, sz_) \ #define Meter_updateValues(this_) As_Meter(this_)->updateValues((Meter*)(this_))
As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_)
#define Meter_defaultMode(this_) As_Meter(this_)->defaultMode #define Meter_defaultMode(this_) As_Meter(this_)->defaultMode
#define Meter_attributes(this_) As_Meter(this_)->attributes #define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name #define Meter_name(this_) As_Meter(this_)->name
@ -86,7 +86,7 @@ typedef struct MeterClass_ {
typedef struct GraphData_ { typedef struct GraphData_ {
struct timeval time; struct timeval time;
double values[METER_BUFFER_LEN]; double values[METER_GRAPHDATA_SIZE];
} GraphData; } GraphData;
struct Meter_ { struct Meter_ {
@ -102,6 +102,7 @@ struct Meter_ {
const ProcessList* pl; const ProcessList* pl;
uint8_t curItems; uint8_t curItems;
const int* curAttributes; const int* curAttributes;
char txtBuffer[METER_TXTBUFFER_LEN];
double* values; double* values;
double total; double total;
void* meterData; void* meterData;

View File

@ -24,7 +24,7 @@ static uint32_t cached_rxp_diff;
static uint32_t cached_txb_diff; static uint32_t cached_txb_diff;
static uint32_t cached_txp_diff; static uint32_t cached_txp_diff;
static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) { static void NetworkIOMeter_updateValues(Meter* this) {
static uint64_t cached_last_update = 0; static uint64_t cached_last_update = 0;
struct timeval tv; struct timeval tv;
@ -45,7 +45,7 @@ static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
NetworkIOData data; NetworkIOData data;
hasData = Platform_getNetworkIO(&data); hasData = Platform_getNetworkIO(&data);
if (!hasData) { if (!hasData) {
xSnprintf(buffer, len, "no data"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "no data");
return; return;
} }
@ -95,7 +95,7 @@ static void NetworkIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
char bufferBytesReceived[12], bufferBytesTransmitted[12]; char bufferBytesReceived[12], bufferBytesTransmitted[12];
Meter_humanUnit(bufferBytesReceived, cached_rxb_diff, sizeof(bufferBytesReceived)); Meter_humanUnit(bufferBytesReceived, cached_rxb_diff, sizeof(bufferBytesReceived));
Meter_humanUnit(bufferBytesTransmitted, cached_txb_diff, sizeof(bufferBytesTransmitted)); Meter_humanUnit(bufferBytesTransmitted, cached_txb_diff, sizeof(bufferBytesTransmitted));
xSnprintf(buffer, len, "rx:%siB/s tx:%siB/s", bufferBytesReceived, bufferBytesTransmitted); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "rx:%siB/s tx:%siB/s", bufferBytesReceived, bufferBytesTransmitted);
} }
static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) { static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {

View File

@ -18,7 +18,9 @@ static const int SwapMeter_attributes[] = {
SWAP_CACHE SWAP_CACHE
}; };
static void SwapMeter_updateValues(Meter* this, char* buffer, size_t size) { static void SwapMeter_updateValues(Meter* this) {
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);
int written; int written;
Platform_setSwapValues(this); Platform_setSwapValues(this);

View File

@ -14,13 +14,13 @@ in the source distribution for its full text.
static const int SysArchMeter_attributes[] = {HOSTNAME}; static const int SysArchMeter_attributes[] = {HOSTNAME};
static void SysArchMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) { static void SysArchMeter_updateValues(Meter* this) {
static char* string; static char* string;
if (string == NULL) if (string == NULL)
Platform_getRelease(&string); Platform_getRelease(&string);
String_safeStrncpy(buffer, string, size); String_safeStrncpy(this->txtBuffer, string, sizeof(this->txtBuffer));
} }
const MeterClass SysArchMeter_class = { const MeterClass SysArchMeter_class = {

View File

@ -23,7 +23,7 @@ static const int TasksMeter_attributes[] = {
TASKS_RUNNING TASKS_RUNNING
}; };
static void TasksMeter_updateValues(Meter* this, char* buffer, size_t len) { static void TasksMeter_updateValues(Meter* this) {
const ProcessList* pl = this->pl; const ProcessList* pl = this->pl;
this->values[0] = pl->kernelThreads; this->values[0] = pl->kernelThreads;
this->values[1] = pl->userlandThreads; this->values[1] = pl->userlandThreads;
@ -35,7 +35,7 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, size_t len) {
if (pl->settings->hideKernelThreads) { if (pl->settings->hideKernelThreads) {
this->values[0] = 0; this->values[0] = 0;
} }
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%d/%d", (int) this->values[3], (int) this->total);
} }
static void TasksMeter_display(const Object* cast, RichString* out) { static void TasksMeter_display(const Object* cast, RichString* out) {

View File

@ -17,10 +17,10 @@ static const int UptimeMeter_attributes[] = {
UPTIME UPTIME
}; };
static void UptimeMeter_updateValues(Meter* this, char* buffer, size_t len) { static void UptimeMeter_updateValues(Meter* this) {
int totalseconds = Platform_getUptime(); int totalseconds = Platform_getUptime();
if (totalseconds == -1) { if (totalseconds == -1) {
xSnprintf(buffer, len, "(unknown)"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "(unknown)");
return; return;
} }
int seconds = totalseconds % 60; int seconds = totalseconds % 60;
@ -41,7 +41,7 @@ static void UptimeMeter_updateValues(Meter* this, char* buffer, size_t len) {
} else { } else {
daysbuf[0] = '\0'; daysbuf[0] = '\0';
} }
xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
} }
const MeterClass UptimeMeter_class = { const MeterClass UptimeMeter_class = {

View File

@ -31,9 +31,11 @@ static const char* const HugePageMeter_labels[] = {
" 1G:", " 2G:", " 4G:", " 8G:", " 16G:", " 32G:", " 64G:", " 128G:", " 256G:", " 512G:", " 1G:", " 2G:", " 4G:", " 8G:", " 16G:", " 32G:", " 64G:", " 128G:", " 256G:", " 512G:",
}; };
static void HugePageMeter_updateValues(Meter* this, char* buffer, size_t size) { static void HugePageMeter_updateValues(Meter* this) {
assert(ARRAYSIZE(HugePageMeter_labels) == HTOP_HUGEPAGE_COUNT); assert(ARRAYSIZE(HugePageMeter_labels) == HTOP_HUGEPAGE_COUNT);
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);
int written; int written;
memory_t usedTotal = 0; memory_t usedTotal = 0;
unsigned nextUsed = 0; unsigned nextUsed = 0;

View File

@ -25,7 +25,7 @@ static const int PressureStallMeter_attributes[] = {
PRESSURE_STALL_THREEHUNDRED PRESSURE_STALL_THREEHUNDRED
}; };
static void PressureStallMeter_updateValues(Meter* this, char* buffer, size_t len) { static void PressureStallMeter_updateValues(Meter* this) {
const char* file; const char* file;
if (strstr(Meter_name(this), "CPU")) { if (strstr(Meter_name(this), "CPU")) {
file = "cpu"; file = "cpu";
@ -47,7 +47,7 @@ static void PressureStallMeter_updateValues(Meter* this, char* buffer, size_t le
/* only print bar for ten (not sixty and threehundred), cause the sum is meaningless */ /* only print bar for ten (not sixty and threehundred), cause the sum is meaningless */
this->curItems = 1; this->curItems = 1;
xSnprintf(buffer, len, "%s %s %5.2lf%% %5.2lf%% %5.2lf%%", some ? "some" : "full", file, this->values[0], this->values[1], this->values[2]); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s %s %5.2lf%% %5.2lf%% %5.2lf%%", some ? "some" : "full", file, this->values[0], this->values[1], this->values[2]);
} }
static void PressureStallMeter_display(const Object* cast, RichString* out) { static void PressureStallMeter_display(const Object* cast, RichString* out) {

View File

@ -69,11 +69,11 @@ static bool isSelinuxEnforcing(void) {
return !!enforce; return !!enforce;
} }
static void SELinuxMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t len) { static void SELinuxMeter_updateValues(ATTR_UNUSED Meter* this) {
enabled = isSelinuxEnabled(); enabled = isSelinuxEnabled();
enforcing = isSelinuxEnforcing(); enforcing = isSelinuxEnforcing();
xSnprintf(buffer, len, "%s%s", enabled ? "enabled" : "disabled", enabled ? (enforcing ? "; mode: enforcing" : "; mode: permissive") : ""); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s%s", enabled ? "enabled" : "disabled", enabled ? (enforcing ? "; mode: enforcing" : "; mode: permissive") : "");
} }
const MeterClass SELinuxMeter_class = { const MeterClass SELinuxMeter_class = {

View File

@ -262,7 +262,7 @@ static void updateViaExec(void) {
fclose(commandOutput); fclose(commandOutput);
} }
static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) { static void SystemdMeter_updateValues(Meter* this) {
free(systemState); free(systemState);
systemState = NULL; systemState = NULL;
nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE; nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE;
@ -274,7 +274,7 @@ static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, siz
updateViaExec(); updateViaExec();
#endif /* !BUILD_STATIC || HAVE_LIBSYSTEMD */ #endif /* !BUILD_STATIC || HAVE_LIBSYSTEMD */
xSnprintf(buffer, size, "%s", systemState ? systemState : "???"); xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s", systemState ? systemState : "???");
} }
static int zeroDigitColor(unsigned int value) { static int zeroDigitColor(unsigned int value) {

View File

@ -11,7 +11,9 @@ static const int ZramMeter_attributes[] = {
ZRAM ZRAM
}; };
static void ZramMeter_updateValues(Meter* this, char* buffer, size_t size) { static void ZramMeter_updateValues(Meter* this) {
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);
int written; int written;
Platform_setZramValues(this); Platform_setZramValues(this);

View File

@ -33,7 +33,9 @@ void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
this->values[5] = stats->size; this->values[5] = stats->size;
} }
static void ZfsArcMeter_updateValues(Meter* this, char* buffer, size_t size) { static void ZfsArcMeter_updateValues(Meter* this) {
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);
int written; int written;
Platform_setZfsArcValues(this); Platform_setZfsArcValues(this);

View File

@ -36,10 +36,10 @@ static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buff
xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]); xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]);
} }
static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, size_t size) { static void ZfsCompressedArcMeter_updateValues(Meter* this) {
Platform_setZfsCompressedArcValues(this); Platform_setZfsCompressedArcValues(this);
ZfsCompressedArcMeter_printRatioString(this, buffer, size); ZfsCompressedArcMeter_printRatioString(this, this->txtBuffer, sizeof(this->txtBuffer));
} }
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) { static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {