mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Refactor generating starttime string into Process class
This commit is contained in:

committed by
cgzones

parent
783be7711d
commit
a63cfc8b7c
@ -50,14 +50,6 @@ bool Process_isThread(const Process* this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) {
|
||||
struct tm date;
|
||||
|
||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||
(void) localtime_r(&proc->starttime_ctime, &date);
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||
}
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
/* This function is from the old Mac version of htop. Originally from ps? */
|
||||
int mib[3], argmax, nargs, c = 0;
|
||||
@ -201,7 +193,7 @@ ERROR_A:
|
||||
return retval;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists) {
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) {
|
||||
struct extern_proc *ep = &ps->kp_proc;
|
||||
|
||||
/* UNSET HERE :
|
||||
@ -231,7 +223,9 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
|
||||
/* e_tdev == -1 for "no device" */
|
||||
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
||||
|
||||
DarwinProcess_setStartTime(proc, ep, now);
|
||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||
Process_fillStarttimeBuffer(proc);
|
||||
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,9 @@ void Process_delete(Object* cast);
|
||||
|
||||
bool Process_isThread(const Process* this);
|
||||
|
||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now);
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset);
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists);
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl);
|
||||
|
||||
|
@ -150,9 +150,6 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
struct kinfo_proc *ps;
|
||||
size_t count;
|
||||
DarwinProcess *proc;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL); /* Start processing time */
|
||||
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
@ -187,7 +184,7 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
for(size_t i = 0; i < count; ++i) {
|
||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||
|
Reference in New Issue
Block a user