Package: htop
Version: 1.0.3-1
Severity: wishlist
Tags: patch

Dear Maintainer,

It would be nice if htop had the possibility to output the time
elapsed since the start of a process (as "ps -o etime" does).

Attached is a patch that implements this feature. It is probably not
optimal, but it is a proof of concept that it is possible.

Cheers,

-- 
Stéphane

-- System Information:
Debian Release: 8.0
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages htop depends on:
ii  libc6         2.19-17
ii  libncursesw5  5.9+20140913-1+b1
ii  libtinfo5     5.9+20140913-1+b1

htop recommends no packages.

Versions of packages htop suggests:
ii  ltrace  0.7.3-4
ii  strace  4.9-2

-- no debconf information
>From 16694355e1a4116584975ea08e9a7f2207842bd7 Mon Sep 17 00:00:00 2001
From: Stephane Glondu <st...@glondu.net>
Date: Wed, 15 Apr 2015 11:12:12 +0200
Subject: [PATCH] Add ELAPSED

---
 Process.c     | 8 ++++++++
 Process.h     | 2 ++
 ProcessList.c | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/Process.c b/Process.c
index 4efd854..173e04a 100644
--- a/Process.c
+++ b/Process.c
@@ -85,6 +85,7 @@ typedef enum ProcessField_ {
    OOM,
    #endif
    IO_PRIORITY,
+   ELAPSED,
    LAST_PROCESSFIELD
 } ProcessField;
 
@@ -115,6 +116,7 @@ typedef struct Process_ {
    float percent_mem;
    char* user;
 
+   unsigned long long int etime;
    unsigned long long int utime;
    unsigned long long int stime;
    unsigned long long int cutime;
@@ -221,6 +223,7 @@ const char *Process_fieldNames[] = {
    "OOM",
 #endif
    "IO_PRIORITY",
+   "ELAPSED",
 "*** report bug! ***"
 };
 
@@ -278,6 +281,7 @@ const char *Process_fieldTitles[] = {
    "    OOM ",
 #endif
    "IO ",
+   " ELAPSED ",
 "*** report bug! ***"
 };
 
@@ -568,6 +572,7 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
       }
       break;
    }
+   case ELAPSED: Process_printTime(str, this->etime); return;
    case UTIME: Process_printTime(str, this->utime); return;
    case STIME: Process_printTime(str, this->stime); return;
    case CUTIME: Process_printTime(str, this->cutime); return;
@@ -680,6 +685,7 @@ Process* Process_new(struct ProcessList_ *pl) {
    this->showChildren = true;
    this->show = true;
    this->updated = false;
+   this->etime = 0;
    this->utime = 0;
    this->stime = 0;
    this->comm = NULL;
@@ -845,6 +851,8 @@ int Process_compare(const void* v1, const void* v2) {
       return (p2->percent_cpu > p1->percent_cpu ? 1 : -1);
    case PERCENT_MEM:
       return (p2->m_resident - p1->m_resident);
+   case ELAPSED:
+      return (p2->etime - p1->etime);
    case UTIME:
       return (p2->utime - p1->utime);
    case STIME:
diff --git a/Process.h b/Process.h
index 19083fd..56dfa0d 100644
--- a/Process.h
+++ b/Process.h
@@ -64,6 +64,7 @@ typedef enum ProcessField_ {
    OOM,
    #endif
    IO_PRIORITY,
+   ELAPSED,
    LAST_PROCESSFIELD
 } ProcessField;
 
@@ -94,6 +95,7 @@ typedef struct Process_ {
    float percent_mem;
    char* user;
 
+   unsigned long long int etime;
    unsigned long long int utime;
    unsigned long long int stime;
    unsigned long long int cutime;
diff --git a/ProcessList.c b/ProcessList.c
index d362115..f374581 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -722,6 +722,8 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
 }
 
 
+static double jiffy = 0.0;
+
 static bool ProcessList_processEntries(ProcessList* this, const char* dirname, Process* parent, double period, struct timeval tv) {
    DIR* dir;
    struct dirent* entry;
@@ -798,6 +800,9 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
       if (isnan(process->percent_cpu)) process->percent_cpu = 0.0;
       process->percent_mem = (process->m_resident * PAGE_SIZE_KB) / (double)(this->totalMem) * 100.0;
 
+      if(jiffy == 0.0) jiffy = sysconf(_SC_CLK_TCK);
+      process->etime = difftime(time(NULL), process->starttime_ctime) * jiffy;
+
       if(!existingProcess) {
 
          if (! ProcessList_statProcessDir(process, dirname, name, curTime))
-- 
2.1.4

Reply via email to