2006-03-04 18:16:49 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - UptimeMeter.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UptimeMeter.h"
|
|
|
|
|
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "CRT.h"
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/*{
|
|
|
|
#include "Meter.h"
|
|
|
|
}*/
|
|
|
|
|
2006-06-06 20:41:01 +00:00
|
|
|
int UptimeMeter_attributes[] = {
|
|
|
|
UPTIME
|
|
|
|
};
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
2009-10-16 20:03:18 +00:00
|
|
|
double uptime = 0;
|
2006-03-04 18:16:49 +00:00
|
|
|
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
2011-09-08 02:54:02 +00:00
|
|
|
if (fd) {
|
2011-10-25 00:05:46 +00:00
|
|
|
fscanf(fd, "%64lf", &uptime);
|
2011-09-08 02:54:02 +00:00
|
|
|
fclose(fd);
|
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
int totalseconds = (int) ceil(uptime);
|
2006-04-10 20:40:38 +00:00
|
|
|
int seconds = totalseconds % 60;
|
2009-03-11 13:26:39 +00:00
|
|
|
int minutes = (totalseconds/60) % 60;
|
|
|
|
int hours = (totalseconds/3600) % 24;
|
|
|
|
int days = (totalseconds/86400);
|
2006-04-10 20:40:38 +00:00
|
|
|
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
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
MeterClass UptimeMeter_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete
|
|
|
|
},
|
2008-03-09 08:58:38 +00:00
|
|
|
.setValues = UptimeMeter_setValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2008-03-09 08:58:38 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = UptimeMeter_attributes,
|
|
|
|
.name = "Uptime",
|
|
|
|
.uiName = "Uptime",
|
|
|
|
.caption = "Uptime: "
|
|
|
|
};
|