void-packages/srcpkgs/procps/patches/procps-3.2.7-top-env-cpuloop.patch

84 lines
2.9 KiB
Diff

diff -up procps-3.2.7/top.c.p15 procps-3.2.7/top.c
--- procps-3.2.7/top.c.p15 2008-09-01 11:37:51.000000000 +0200
+++ procps-3.2.7/top.c 2008-09-01 11:37:51.000000000 +0200
@@ -121,6 +121,7 @@ static int No_ksyms = -1, // set t
Batch = 0, // batch mode, collect no input, dumb output
Loops = -1, // number of iterations, -1 loops forever
Secure_mode = 0; // set if some functionality restricted
+static int CPU_loop = 0; // wait for reliable CPU data
/* Some cap's stuff to reduce runtime calls --
to accomodate 'Batch' mode, they begin life as empty strings */
@@ -1679,6 +1680,9 @@ static void before (char *me)
Fieldstab[P_PPD].fmts = pid_fmt;
Fieldstab[P_PPD].head = " PPID" + 10 - pid_digits;
}
+
+ if (( getenv("CPULOOP")) && ( atoi(getenv("CPULOOP")) == 1 ))
+ CPU_loop = 1;
}
@@ -2978,6 +2981,7 @@ static proc_t **summary_show (void)
{
static proc_t **p_table = NULL;
static CPU_t *smpcpu = NULL;
+ static int first = 0;
// whoa first time, gotta' prime the pump...
if (!p_table) {
@@ -3025,6 +3029,28 @@ static proc_t **summary_show (void)
smpcpu = cpus_refresh(smpcpu);
+ if (first==0 && CPU_loop)
+ {
+ int i;
+ CPU_t *cpu;
+ for (i = 0; i < Cpu_tot; i++) {
+ cpu = &smpcpu[i];
+ cpu->u_sav = cpu->u;
+ cpu->s_sav = cpu->s;
+ cpu->n_sav = cpu->n;
+ cpu->i_sav = cpu->i;
+ cpu->w_sav = cpu->w;
+ cpu->x_sav = cpu->x;
+ cpu->y_sav = cpu->y;
+ cpu->z_sav = cpu->z;
+ }
+ tv.tv_sec = Rc.delay_time;
+ tv.tv_usec = (Rc.delay_time - (int)Rc.delay_time) * 1000000;
+ select(0, NULL, NULL, NULL, &tv);
+
+ smpcpu = cpus_refresh(smpcpu);
+ }
+
if (CHKw(Curwin, View_CPUSUM)) {
// display just the 1st /proc/stat line
summaryhlp(&smpcpu[Cpu_tot], "Cpu(s):");
@@ -3050,6 +3076,8 @@ static proc_t **summary_show (void)
}
SETw(Curwin, NEWFRAM_cwo);
+
+ first = 1;
return p_table;
}
diff -up procps-3.2.7/top.1.p15 procps-3.2.7/top.1
--- procps-3.2.7/top.1.p15 2008-09-01 11:37:51.000000000 +0200
+++ procps-3.2.7/top.1 2008-09-01 11:37:51.000000000 +0200
@@ -1183,6 +1183,13 @@ Then ponder this:
Send bug reports to:
Albert D\. Cahalan, <albert@users.sf.net>
+The top command calculates Cpu(s) by looking at the change in CPU time values
+between samples. When you first run it, it has no previous sample to compare
+to, so these initial values are the percentages since boot. It means you need
+at least two loops or you have to ignore summary output from the first loop.
+This is problem for example for batch mode. There is a possible workaround if
+you define the CPULOOP=1 environment variable. The top command will be run one
+extra hidden loop for CPU data before standard output.
.\" ----------------------------------------------------------------------
.SH 8. HISTORY Former top