top gets pcpu work
This commit is contained in:
parent
667b1bc2fa
commit
21c9ffa15e
@ -7,6 +7,7 @@
|
|||||||
\***********************************************************************/
|
\***********************************************************************/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "procps.h"
|
||||||
|
|
||||||
void *xcalloc(void *pointer, int size) {
|
void *xcalloc(void *pointer, int size) {
|
||||||
void * ret;
|
void * ret;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "procps.h"
|
||||||
|
|
||||||
/* output a string, converting unprintables to octal as we go, and stopping after
|
/* output a string, converting unprintables to octal as we go, and stopping after
|
||||||
processing max chars of output (accounting for expansion due to octal rep).
|
processing max chars of output (accounting for expansion due to octal rep).
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "sig.h"
|
||||||
|
|
||||||
/* Linux signals:
|
/* Linux signals:
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "proc/procps.h"
|
#include "proc/procps.h"
|
||||||
#include "proc/readproc.h"
|
#include "proc/readproc.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
char * status(proc_t* task) {
|
char * status(proc_t* task) {
|
||||||
static char buf[4] = " ";
|
static char buf[4] = " ";
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#ifdef MINORVERSION
|
#ifdef MINORVERSION
|
||||||
char procps_version[] = "procps version " VERSION "." SUBVERSION "." MINORVERSION;
|
char procps_version[] = "procps version " VERSION "." SUBVERSION "." MINORVERSION;
|
||||||
|
44
top.c
44
top.c
@ -149,11 +149,13 @@ static WIN_t *Winstk [GROUPSMAX],
|
|||||||
|
|
||||||
/* Frame oriented stuff that can't remain local to any 1 function
|
/* Frame oriented stuff that can't remain local to any 1 function
|
||||||
and/or that would be too cumbersome managed as parms */
|
and/or that would be too cumbersome managed as parms */
|
||||||
static int Frame_maxtask, /* last known number of active tasks */
|
static int Frame_maxtask; /* last known number of active tasks */
|
||||||
/* ie. current 'size' of proc table */
|
/* ie. current 'size' of proc table */
|
||||||
Frame_srtflg, /* the subject window sort direction */
|
static float Frame_etime, /* elapsed time twix this & prior */
|
||||||
Frame_ctimes, /* the subject window's ctimes flag */
|
Frame_scale; /* so we can '*' vs. '/' IF 'pcpu' */
|
||||||
Frame_cmdlin; /* the subject window's cmdlin flag */
|
static int Frame_srtflg, /* the subject window sort direction */
|
||||||
|
Frame_ctimes, /* the subject window's ctimes flag */
|
||||||
|
Frame_cmdlin; /* the subject window's cmdlin flag */
|
||||||
/* ////////////////////////////////////////////////////////////// */
|
/* ////////////////////////////////////////////////////////////// */
|
||||||
|
|
||||||
|
|
||||||
@ -753,9 +755,10 @@ static char *scale_tics (TICS_t tics, const int width)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate and return the elapsed time since the last update
|
* Calculate and the elapsed time since the last update along with the
|
||||||
* which is then used in % CPU calc's. */
|
* scaling factor used in multiplication (vs. division) when calculating
|
||||||
static float time_elapsed (void)
|
* a displayable task's %CPU. */
|
||||||
|
static void time_elapsed (void)
|
||||||
{
|
{
|
||||||
static struct timeval oldtimev;
|
static struct timeval oldtimev;
|
||||||
struct timeval timev;
|
struct timeval timev;
|
||||||
@ -767,7 +770,9 @@ static float time_elapsed (void)
|
|||||||
+ (float)(timev.tv_usec - oldtimev.tv_usec) / 1000000.0;
|
+ (float)(timev.tv_usec - oldtimev.tv_usec) / 1000000.0;
|
||||||
oldtimev.tv_sec = timev.tv_sec;
|
oldtimev.tv_sec = timev.tv_sec;
|
||||||
oldtimev.tv_usec = timev.tv_usec;
|
oldtimev.tv_usec = timev.tv_usec;
|
||||||
return et;
|
Frame_etime = et;
|
||||||
|
/* if in Solaris mode, adjust our scaling for all cpus */
|
||||||
|
Frame_scale = 100.0f / ((float)Hertz * (float)et * (Mode_irixps ? 1 : Cpu_tot));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1731,7 +1736,7 @@ static void cpudo (CPUS_t *cpu, const char *pfx)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Calc the number of tasks in each state (run, sleep, etc)
|
* Calc the number of tasks in each state (run, sleep, etc)
|
||||||
* Calc percent cpu usage for each task (pcpu)
|
* Prepare for the possible calculation of percent cpu usage (pcpu)
|
||||||
* Calc the cpu(s) percent in each state (user, system, nice, idle)
|
* Calc the cpu(s) percent in each state (user, system, nice, idle)
|
||||||
* AND establish the total number of tasks for this frame! */
|
* AND establish the total number of tasks for this frame! */
|
||||||
static void frame_states (proc_t **ppt, int show)
|
static void frame_states (proc_t **ppt, int show)
|
||||||
@ -1740,7 +1745,6 @@ static void frame_states (proc_t **ppt, int show)
|
|||||||
static unsigned hist_siz;
|
static unsigned hist_siz;
|
||||||
HIST_t *hist_new;
|
HIST_t *hist_new;
|
||||||
unsigned total, running, sleeping, stopped, zombie;
|
unsigned total, running, sleeping, stopped, zombie;
|
||||||
float etime;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!hist_sav) {
|
if (!hist_sav) {
|
||||||
@ -1750,7 +1754,7 @@ static void frame_states (proc_t **ppt, int show)
|
|||||||
}
|
}
|
||||||
hist_new = alloc_c(hist_siz);
|
hist_new = alloc_c(hist_siz);
|
||||||
total = running = sleeping = stopped = zombie = 0;
|
total = running = sleeping = stopped = zombie = 0;
|
||||||
etime = time_elapsed();
|
time_elapsed();
|
||||||
|
|
||||||
/* make a pass through the data to get stats */
|
/* make a pass through the data to get stats */
|
||||||
while (-1 != ppt[total]->pid) { /* calculations //// */
|
while (-1 != ppt[total]->pid) { /* calculations //// */
|
||||||
@ -1790,13 +1794,9 @@ static void frame_states (proc_t **ppt, int show)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* finally calculate an integer version of %cpu for this task
|
/* we're just saving elapsed tics, to be converted into %cpu if
|
||||||
and plug it into the unfilled slot in proc_t */
|
this task wins it's displayable screen row lottery... */
|
||||||
this->pcpu = (tics * 1000 / (TICS_t)Hertz) / etime;
|
this->pcpu = tics;
|
||||||
if (this->pcpu > 999) this->pcpu = 999;
|
|
||||||
/* if in Solaris mode, adjust cpu percentage not only for the cpu
|
|
||||||
the process is running on, but for all cpus together */
|
|
||||||
if (!Mode_irixps) this->pcpu /= Cpu_tot;
|
|
||||||
|
|
||||||
total++;
|
total++;
|
||||||
} /* end: while 'pids' */
|
} /* end: while 'pids' */
|
||||||
@ -1982,7 +1982,11 @@ static void show_a_task (WIN_t *q, proc_t *task)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case P_CPU:
|
case P_CPU:
|
||||||
MKCOL(q, i, a, &pad, cbuf, (float)task->pcpu / 10);
|
{ float u = (float)task->pcpu * Frame_scale;
|
||||||
|
|
||||||
|
if (99.9 < u) u = 99.9;
|
||||||
|
MKCOL(q, i, a, &pad, cbuf, u);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case P_DAT:
|
case P_DAT:
|
||||||
MKCOL(q, i, a, &pad, cbuf, scale_num(PAGES_2K(task->drs), w, s));
|
MKCOL(q, i, a, &pad, cbuf, scale_num(PAGES_2K(task->drs), w, s));
|
||||||
@ -2465,7 +2469,7 @@ static proc_t **do_summary (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Display Tasks and Cpu(s) states and also calc 'pcpu',
|
** Display Tasks and Cpu(s) states and also prime for potential 'pcpu',
|
||||||
** but NO table sort yet -- that's done on a per window basis! */
|
** but NO table sort yet -- that's done on a per window basis! */
|
||||||
p_table = refreshprocs(p_table);
|
p_table = refreshprocs(p_table);
|
||||||
frame_states(p_table, CHKw(Curwin, View_STATES));
|
frame_states(p_table, CHKw(Curwin, View_STATES));
|
||||||
|
2
top.h
2
top.h
@ -528,7 +528,7 @@ typedef struct win {
|
|||||||
//atic int get_int (const char *prompt);
|
//atic int get_int (const char *prompt);
|
||||||
//atic char *scale_num (unsigned num, const int width, const unsigned type);
|
//atic char *scale_num (unsigned num, const int width, const unsigned type);
|
||||||
//atic char *scale_tics (TICS_t tics, const int width);
|
//atic char *scale_tics (TICS_t tics, const int width);
|
||||||
//atic float time_elapsed (void);
|
//atic void time_elapsed (void);
|
||||||
/*------ Library Alternatives ------------------------------------------*/
|
/*------ Library Alternatives ------------------------------------------*/
|
||||||
//atic void *alloc_c (unsigned numb);
|
//atic void *alloc_c (unsigned numb);
|
||||||
//atic void *alloc_r (void *q, unsigned numb);
|
//atic void *alloc_r (void *q, unsigned numb);
|
||||||
|
Loading…
Reference in New Issue
Block a user