Do not use extra starttime process field on Linux

This commit is contained in:
Christian Göttsche 2020-10-12 12:51:18 +02:00 committed by cgzones
parent d744dac7ee
commit 783be7711d
3 changed files with 10 additions and 17 deletions

View File

@ -225,13 +225,6 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
case STIME: Process_printTime(str, lp->stime); return; case STIME: Process_printTime(str, lp->stime); return;
case CUTIME: Process_printTime(str, lp->cutime); return; case CUTIME: Process_printTime(str, lp->cutime); return;
case CSTIME: Process_printTime(str, lp->cstime); return; case CSTIME: Process_printTime(str, lp->cstime); return;
case STARTTIME: {
struct tm date;
time_t starttimewall = btime + (lp->starttime / sysconf(_SC_CLK_TCK));
(void) localtime_r(&starttimewall, &date);
strftime(buffer, n, ((starttimewall > time(NULL) - 86400) ? "%R " : "%b%d "), &date);
break;
}
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
case RCHAR: Process_colorNumber(str, lp->io_rchar, coloring); return; case RCHAR: Process_colorNumber(str, lp->io_rchar, coloring); return;
case WCHAR: Process_colorNumber(str, lp->io_wchar, coloring); return; case WCHAR: Process_colorNumber(str, lp->io_wchar, coloring); return;
@ -334,12 +327,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff; case CUTIME: diff = p2->cutime - p1->cutime; goto test_diff;
case STIME: diff = p2->stime - p1->stime; goto test_diff; case STIME: diff = p2->stime - p1->stime; goto test_diff;
case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff; case CSTIME: diff = p2->cstime - p1->cstime; goto test_diff;
case STARTTIME: {
if (p1->starttime == p2->starttime)
return (p1->super.pid - p2->super.pid);
else
return (p1->starttime - p2->starttime);
}
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff; case RCHAR: diff = p2->io_rchar - p1->io_rchar; goto test_diff;
case WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff; case WCHAR: diff = p2->io_wchar - p1->io_wchar; goto test_diff;

View File

@ -107,7 +107,6 @@ typedef struct LinuxProcess_ {
long m_drs; long m_drs;
long m_lrs; long m_lrs;
long m_dt; long m_dt;
unsigned long long starttime;
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
unsigned long long io_rchar; unsigned long long io_rchar;
unsigned long long io_wchar; unsigned long long io_wchar;

View File

@ -260,9 +260,8 @@ void ProcessList_delete(ProcessList* pl) {
free(this); free(this);
} }
static double jiffy = NAN;
static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) {
static double jiffy = NAN;
if(isnan(jiffy)) { if(isnan(jiffy)) {
errno = 0; errno = 0;
long sc_jiffy = sysconf(_SC_CLK_TCK); long sc_jiffy = sysconf(_SC_CLK_TCK);
@ -345,7 +344,11 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname,
process->nlwp = strtol(location, &location, 10); process->nlwp = strtol(location, &location, 10);
location += 1; location += 1;
location = strchr(location, ' ')+1; location = strchr(location, ' ')+1;
lp->starttime = strtoll(location, &location, 10); if (process->starttime_ctime == 0) {
process->starttime_ctime = btime + LinuxProcess_adjustTime(strtoll(location, &location, 10)) / 100;
} else {
location = strchr(location, ' ')+1;
}
location += 1; location += 1;
for (int i=0; i<15; i++) location = strchr(location, ' ')+1; for (int i=0; i<15; i++) location = strchr(location, ' ')+1;
process->exit_signal = strtol(location, &location, 10); process->exit_signal = strtol(location, &location, 10);
@ -1032,6 +1035,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
goto errorReadingProcess; goto errorReadingProcess;
} }
struct tm date;
(void) localtime_r(&proc->starttime_ctime, &date);
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
ProcessList_add(pl, proc); ProcessList_add(pl, proc);
} else { } else {
if (settings->updateProcessNames && proc->state != 'Z') { if (settings->updateProcessNames && proc->state != 'Z') {