2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop
|
|
|
|
(C) 2004-2006 Hisham H. Muhammad
|
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UptimeMeter.h"
|
|
|
|
#include "Meter.h"
|
|
|
|
|
|
|
|
#include "ProcessList.h"
|
|
|
|
|
|
|
|
#include "CRT.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2006-06-06 20:41:01 +00:00
|
|
|
int UptimeMeter_attributes[] = {
|
|
|
|
UPTIME
|
|
|
|
};
|
2006-04-10 20:40:38 +00:00
|
|
|
|
|
|
|
MeterType UptimeMeter = {
|
|
|
|
.setValues = UptimeMeter_setValues,
|
|
|
|
.display = NULL,
|
|
|
|
.mode = TEXT_METERMODE,
|
|
|
|
.items = 1,
|
|
|
|
.total = 100.0,
|
|
|
|
.attributes = UptimeMeter_attributes,
|
|
|
|
.name = "Uptime",
|
|
|
|
.uiName = "Uptime",
|
|
|
|
.caption = "Uptime: "
|
2006-03-04 18:16:49 +00:00
|
|
|
};
|
|
|
|
|
2006-04-10 20:40:38 +00:00
|
|
|
void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
2006-03-04 18:16:49 +00:00
|
|
|
double uptime;
|
|
|
|
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
|
|
|
fscanf(fd, "%lf", &uptime);
|
|
|
|
fclose(fd);
|
|
|
|
int totalseconds = (int) ceil(uptime);
|
2006-04-10 20:40:38 +00:00
|
|
|
int seconds = totalseconds % 60;
|
|
|
|
int minutes = (totalseconds-seconds) % 3600 / 60;
|
|
|
|
int hours = (totalseconds-seconds-(minutes*60)) % 86400 / 3600;
|
|
|
|
int days = (totalseconds-seconds-(minutes*60)-(hours*3600)) / 86400;
|
|
|
|
this->values[0] = days;
|
|
|
|
if (days > this->total) {
|
|
|
|
this->total = days;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2006-08-30 04:37:20 +00:00
|
|
|
char daysbuf[15];
|
2006-04-10 20:40:38 +00:00
|
|
|
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';
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2006-04-10 20:40:38 +00:00
|
|
|
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|