44 #define FIXED_1 (1<<FSHIFT)
45 #define LOAD_INT(x) ((x) >> FSHIFT)
46 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
49 #include <sys/sysinfo.h>
59 #include <linux/limits.h>
61 #include <sys/times.h>
71 typedef long long int num;
141 procuptime = fopen(
"/proc/uptime",
"r");
142 fscanf(procuptime,
"%d.%ds", &sec, &ssec);
149 int running = sinceboot -
x;
153 strftime(buf,
sizeof(buf),
"%m.%d %H:%M", localtime(&rt));
157 void procCpuStat(
unsigned long long &idleJiffies,
unsigned long long &allJiffies) {
160 input = fopen(
"/proc/stat",
"r");
168 if (count==3) idleJiffies+=
last;
171 while (last && count++<20);
180 std::ostringstream ost;
181 ost <<
"/proc/" << getpid() <<
"/stat";
182 input = fopen(ost.str().c_str(),
"r");
312 int updays, uphours, upminutes;
314 struct tm *current_time;
318 current_time = localtime(¤t_secs);
323 << (current_time->tm_hour%12 ? current_time->tm_hour%12 : 12)
325 << current_time->tm_min
326 << (current_time->tm_hour > 11 ?
" pm, " :
" am, ")
328 updays = (int) info.uptime / (60*60*24);
330 *out << updays <<
" day" << ((updays != 1) ?
"s " :
" ");
331 upminutes = (int) info.uptime / 60;
332 uphours = (upminutes / 60) % 24;
335 *out << std::setw(2) << uphours <<
":" << upminutes;
337 *out << upminutes <<
" minutes ";
339 *out <<
" - load average "
346 *out <<
" used memory " << std::setw(3)
347 << (float(info.totalram-info.freeram)/float(info.totalram))*100 <<
"%";
351 *out <<
"Unable to retrieve uptime information on this platform.";
355 *out <<
"<div id=\"" << name <<
"\">";
void printstr(const char *name, char *x)
void readunsigned(unsigned long long *x)
unsigned long long start_time
void procStat(std::ostringstream *out)
void cDiv(std::ostringstream *out)
void printtimediff(const char *name, num x)
void printone(const char *name, num x)
void printunsigned(const char *name, unsigned long long x)
void printchar(const char *name, char x)
void printtime(const char *name, num x)
void printonex(const char *name, num x)
void procCpuStat(unsigned long long &idleJiffies, unsigned long long &allJiffies)
void mDiv(std::ostringstream *out, std::string name)
void uptime(std::ostringstream *out)