Track process uptime
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
#include "ipc/pipe/pipe.h"
|
#include "ipc/pipe/pipe.h"
|
||||||
#include "sysdefs/proc.h"
|
#include "sysdefs/proc.h"
|
||||||
#include "sysdefs/fs.h"
|
#include "sysdefs/fs.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
#define PROC_REAPER_FREQ 30
|
#define PROC_REAPER_FREQ 30
|
||||||
|
|
||||||
@ -147,6 +148,8 @@ Proc *proc_spawnuser(char *mountpoint, char *path) {
|
|||||||
proc->pipes[1] = dlmalloc(sizeof(IpcPipe));
|
proc->pipes[1] = dlmalloc(sizeof(IpcPipe));
|
||||||
ipc_pipeinit(proc->pipes[1], proc->pid);
|
ipc_pipeinit(proc->pipes[1], proc->pid);
|
||||||
|
|
||||||
|
time_get(&proc->time);
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "vfs/vfs.h"
|
#include "vfs/vfs.h"
|
||||||
#include "ipc/pipe/pipe.h"
|
#include "ipc/pipe/pipe.h"
|
||||||
#include "sysdefs/proc.h"
|
#include "sysdefs/proc.h"
|
||||||
|
#include "sysdefs/time.h"
|
||||||
#include "dev/dev.h"
|
#include "dev/dev.h"
|
||||||
|
|
||||||
#define PROC_NAME_MAX 0x100
|
#define PROC_NAME_MAX 0x100
|
||||||
@ -68,6 +69,8 @@ typedef struct Proc {
|
|||||||
} procargs;
|
} procargs;
|
||||||
|
|
||||||
uint64_t mman_map_base;
|
uint64_t mman_map_base;
|
||||||
|
|
||||||
|
Time time;
|
||||||
} Proc;
|
} Proc;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -226,6 +226,8 @@ int32_t SYSCALL2(sys_proc_stat, pidx, pstat1) {
|
|||||||
LL_FOREACH_SAFE(p->vas, vas, vastmp) {
|
LL_FOREACH_SAFE(p->vas, vas, vastmp) {
|
||||||
stat->usemem += vas->size;
|
stat->usemem += vas->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hal_memcpy(&stat->time, &p->time, sizeof(p->time));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,3 +94,45 @@ timeunix_t time_tounix(Time *time) {
|
|||||||
secs += time->second;
|
secs += time->second;
|
||||||
return secs;
|
return secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timeunix_totime(timeunix_t unix, Time *time) {
|
||||||
|
uint64_t days = unix / 86400;
|
||||||
|
uint32_t rem = days % 86400;
|
||||||
|
|
||||||
|
time->hour = rem / 3600;
|
||||||
|
time->minute = (rem % 3600) / 60;
|
||||||
|
time->second = rem % 60;
|
||||||
|
|
||||||
|
uint32_t year = 1970;
|
||||||
|
for (;;) {
|
||||||
|
uint32_t ydays = time_isleap(year) ? 366 : 365;
|
||||||
|
if (days >= ydays) {
|
||||||
|
days -= ydays;
|
||||||
|
year++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time->year = year;
|
||||||
|
|
||||||
|
bool leap = time_isleap(year);
|
||||||
|
uint32_t month = 0;
|
||||||
|
while (month < 11) {
|
||||||
|
uint32_t next = days_before_month[month + 1];
|
||||||
|
if (leap && month + 1 > 1) {
|
||||||
|
next++;
|
||||||
|
}
|
||||||
|
if (days < next) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
month++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t month_start = days_before_month[month];
|
||||||
|
if (leap && month > 1) {
|
||||||
|
month_start++;
|
||||||
|
}
|
||||||
|
|
||||||
|
time->month = month + 1;
|
||||||
|
time->day = (days - month_start) + 1;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef SHARE_SYSDEFS_PROC_H_
|
#ifndef SHARE_SYSDEFS_PROC_H_
|
||||||
#define SHARE_SYSDEFS_PROC_H_
|
#define SHARE_SYSDEFS_PROC_H_
|
||||||
|
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
#define PROC_ARG_MAX 128
|
#define PROC_ARG_MAX 128
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -8,6 +10,7 @@ typedef struct {
|
|||||||
char name[0x100];
|
char name[0x100];
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
size_t usemem;
|
size_t usemem;
|
||||||
|
Time time;
|
||||||
} ProcStat;
|
} ProcStat;
|
||||||
|
|
||||||
typedef uint64_t PID_t;
|
typedef uint64_t PID_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user