mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-24 23:15:46 +00:00
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
/*
|
|
htop - UptimeMeter.c
|
|
(C) 2004-2011 Hisham H. Muhammad
|
|
Released under the GNU GPL, see the COPYING file
|
|
in the source distribution for its full text.
|
|
*/
|
|
|
|
#include "UptimeMeter.h"
|
|
#include "Platform.h"
|
|
#include "CRT.h"
|
|
|
|
/*{
|
|
#include "Meter.h"
|
|
}*/
|
|
|
|
int UptimeMeter_attributes[] = {
|
|
UPTIME
|
|
};
|
|
|
|
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
|
int totalseconds = Platform_getUptime();
|
|
if (totalseconds == -1) {
|
|
snprintf(buffer, len, "(unknown)");
|
|
return;
|
|
}
|
|
int seconds = totalseconds % 60;
|
|
int minutes = (totalseconds/60) % 60;
|
|
int hours = (totalseconds/3600) % 24;
|
|
int days = (totalseconds/86400);
|
|
this->values[0] = days;
|
|
if (days > this->total) {
|
|
this->total = days;
|
|
}
|
|
char daysbuf[15];
|
|
if (days > 100) {
|
|
sprintf(daysbuf, "%d days(!), ", days);
|
|
} else if (days > 1) {
|
|
sprintf(daysbuf, "%d days, ", days);
|
|
} else if (days == 1) {
|
|
sprintf(daysbuf, "1 day, ");
|
|
} else {
|
|
daysbuf[0] = '\0';
|
|
}
|
|
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
|
}
|
|
|
|
MeterClass UptimeMeter_class = {
|
|
.super = {
|
|
.extends = Class(Meter),
|
|
.delete = Meter_delete
|
|
},
|
|
.setValues = UptimeMeter_setValues,
|
|
.defaultMode = TEXT_METERMODE,
|
|
.total = 100.0,
|
|
.attributes = UptimeMeter_attributes,
|
|
.name = "Uptime",
|
|
.uiName = "Uptime",
|
|
.caption = "Uptime: "
|
|
};
|