]> granicus.if.org Git - sysstat/blob - pr_stats.c
pr_stats.c: Cosmetic change in code
[sysstat] / pr_stats.c
1 /*
2  * pr_stats.c: Functions used by sar to display statistics
3  * (C) 1999-2017 by Sebastien GODARD (sysstat <at> orange.fr)
4  *
5  ***************************************************************************
6  * This program is free software; you can redistribute it and/or modify it *
7  * under the terms of the GNU General Public License as published  by  the *
8  * Free Software Foundation; either version 2 of the License, or (at  your *
9  * option) any later version.                                              *
10  *                                                                         *
11  * This program is distributed in the hope that it  will  be  useful,  but *
12  * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
14  * for more details.                                                       *
15  *                                                                         *
16  * You should have received a copy of the GNU General Public License along *
17  * with this program; if not, write to the Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA              *
19  ***************************************************************************
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26
27 #include "sa.h"
28 #include "ioconf.h"
29 #include "pr_stats.h"
30
31 #ifdef USE_NLS
32 #include <locale.h>
33 #include <libintl.h>
34 #define _(string) gettext(string)
35 #else
36 #define _(string) (string)
37 #endif
38
39 extern unsigned int flags;
40 extern unsigned int dm_major;
41 extern int  dis;
42 extern char timestamp[][TIMESTAMP_LEN];
43 extern unsigned long avg_count;
44
45
46 /*
47  ***************************************************************************
48  * Display current activity header line.
49  *
50  * IN:
51  * @timestamp   Timestamp for previous stat sample.
52  * @a           Activity structure.
53  * @pos         Index in @.hdr_line string, 0 being the first one (header
54  *              are delimited by the '|' character).
55  * @iwidth      First column width (generally this is the item name). A
56  *              negative value means that the corresponding field shall be
57  *              displayed at the end of the line, with no indication of width.
58  * @vwidth      Column width for stats values.
59  ***************************************************************************
60  */
61 void print_hdr_line(char *timestamp, struct activity *a, int pos, int iwidth, int vwidth)
62 {
63         char hline[HEADER_LINE_LEN] = "";
64         char *hl, *tk, *it = NULL;
65         int i = -1, j;
66         int p = pos;
67
68         strncpy(hline, a->hdr_line, HEADER_LINE_LEN - 1);
69         hline[HEADER_LINE_LEN - 1] = '\0';
70         for (hl = strtok(hline, "|"); hl && (pos > 0); hl = strtok(NULL, "|"), pos--);
71         if (!hl)
72                 /* Bad @pos arg given to function */
73                 return;
74
75         printf("\n%-11s", timestamp);
76
77         if (strchr(hl, '&')) {
78                 j = strcspn(hl, "&");
79                 if ((a->opt_flags & 0xff00) & (1 << (8 + p))) {
80                         /* Display whole header line */
81                         *(hl + j) = ';';
82                 }
83                 else {
84                         /* Display only the first part of the header line */
85                         *(hl + j) = '\0';
86                 }
87         }
88         /* Display each field */
89         for (tk = strtok(hl, ";"); tk; tk = strtok(NULL, ";"), i--) {
90                 if (iwidth > 0) {
91                         printf(" %*s", iwidth, tk);
92                         iwidth = 0;
93                         continue;
94                 }
95                 if ((iwidth < 0) && (iwidth == i)) {
96                         it = tk;
97                         iwidth = 0;
98                 }
99                 else {
100                         printf(" %*s", vwidth, tk);
101                 }
102         }
103         if (it) {
104                 printf(" %s", it);
105         }
106         printf("\n");
107 }
108
109 /*
110  ***************************************************************************
111  * Display CPU statistics.
112  * NB: The stats are only calculated over the part of the time interval when
113  * the CPU was online. As a consequence, the sum (%user + %nice + ... + %idle)
114  * will always be 100% on the time interval even if the CPU has been offline
115  * most of the time.
116  *
117  * IN:
118  * @a           Activity structure with statistics.
119  * @prev        Index in array where stats used as reference are.
120  * @curr        Index in array for current sample statistics.
121  * @itv         Interval of time in 1/100th of a second (independent of the
122  *              number of processors). Unused here.
123  ***************************************************************************
124  */
125 __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
126                                 unsigned long long itv)
127 {
128         int i;
129         unsigned long long tot_jiffies_c, tot_jiffies_p;
130         unsigned long long deltot_jiffies;
131         struct stats_cpu *scc, *scp;
132
133         if (dis) {
134                 print_hdr_line(timestamp[!curr], a, FIRST + DISPLAY_CPU_ALL(a->opt_flags), 7, 9);
135         }
136
137         /*
138          * @nr[curr] cannot normally be greater than @nr_ini
139          * (since @nr_ini counts up all CPU, even those offline).
140          * If this happens, it may be because the machine has been
141          * restarted with more CPU and no LINUX_RESTART has been
142          * inserted in file.
143          * No problem here with @nr_allocated. Having been able to
144          * read @nr[curr] structures shows that buffers are large enough.
145          */
146         if (a->nr[curr] > a->nr_ini) {
147                 a->nr_ini = a->nr[curr];
148         }
149
150         for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) {
151
152                 /*
153                  * The size of a->buf[...] CPU structure may be different from the default
154                  * sizeof(struct stats_cpu) value if data have been read from a file!
155                  * That's why we don't use a syntax like:
156                  * scc = (struct stats_cpu *) a->buf[...] + i;
157                  */
158                 scc = (struct stats_cpu *) ((char *) a->buf[curr] + i * a->msize);
159                 scp = (struct stats_cpu *) ((char *) a->buf[prev] + i * a->msize);
160
161                 /*
162                  * Note: @nr[curr] is in [1, NR_CPUS + 1].
163                  * Bitmap size is provided for (NR_CPUS + 1) CPUs.
164                  * Anyway, NR_CPUS may vary between the version of sysstat
165                  * used by sadc to create a file, and the version of sysstat
166                  * used by sar to read it...
167                  */
168
169                 /* Should current CPU (including CPU "all") be displayed? */
170                 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
171                         /* No */
172                         continue;
173
174                 /*
175                  * Yes: Compute the total number of jiffies spent by current processor.
176                  * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
177                  * already include them.
178                  */
179                 tot_jiffies_c = scc->cpu_user + scc->cpu_nice +
180                                 scc->cpu_sys + scc->cpu_idle +
181                                 scc->cpu_iowait + scc->cpu_hardirq +
182                                 scc->cpu_steal + scc->cpu_softirq;
183                 tot_jiffies_p = scp->cpu_user + scp->cpu_nice +
184                                 scp->cpu_sys + scp->cpu_idle +
185                                 scp->cpu_iowait + scp->cpu_hardirq +
186                                 scp->cpu_steal + scp->cpu_softirq;
187
188                 /* Total number of jiffies spent on the interval */
189                 deltot_jiffies = get_interval(tot_jiffies_p, tot_jiffies_c);
190
191                 /*
192                  * If the CPU is offline then it is omited from /proc/stat:
193                  * All the fields couldn't have been read and the sum of them is zero.
194                  */
195                 if (tot_jiffies_c == 0) {
196                         /*
197                          * CPU is currently offline.
198                          * Set current struct fields (which have been set to zero)
199                          * to values from previous iteration. Hence their values won't
200                          * jump from zero when the CPU comes back online.
201                          * Note that this workaround is no longer enough with recent kernels,
202                          * as I have noticed that when a CPU comes back online, some fields
203                          * restart from their previous value (e.g. user, nice, system)
204                          * whereas others restart from zero (idle, iowait)!
205                          */
206                         *scc = *scp;
207
208                         /* An offline CPU is not displayed */
209                         continue;
210                 }
211                 if (tot_jiffies_p == 0)
212                         /*
213                          * CPU has just come back online.
214                          * Unfortunately, no reference values are available
215                          * from a previous iteration, probably because it was
216                          * already offline when the first sample has been taken.
217                          * So don't display that CPU to prevent "jump-from-zero"
218                          * output syndrome.
219                          */
220                         continue;
221
222                 printf("%-11s", timestamp[curr]);
223
224                 if (!i) {
225                         /* This is CPU "all" */
226                         cprintf_in(IS_STR, " %s", "    all", 0);
227                 }
228                 else {
229                         cprintf_in(IS_INT, " %7d", "", i - 1);
230
231                         /* Recalculate interval for current proc */
232                         deltot_jiffies = get_per_cpu_interval(scc, scp);
233
234                         if (!deltot_jiffies) {
235                                 /*
236                                  * If the CPU is tickless then there is no change in CPU values
237                                  * but the sum of values is not zero.
238                                  * %user, %nice, %system, %iowait, %steal, ..., %idle
239                                  */
240                                 cprintf_pc(DISPLAY_UNIT(flags), 5, 9, 2,
241                                            0.0, 0.0, 0.0, 0.0, 0.0);
242
243                                 if (DISPLAY_CPU_DEF(a->opt_flags)) {
244                                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2, 100.0);
245                                         printf("\n");
246                                 }
247                                 /*
248                                  * Four additional fields to display:
249                                  * %irq, %soft, %guest, %gnice.
250                                  */
251                                 else if (DISPLAY_CPU_ALL(a->opt_flags)) {
252                                         cprintf_pc(DISPLAY_UNIT(flags), 4, 9, 2,
253                                                    0.0, 0.0, 0.0, 100.0);
254                                         printf("\n");
255                                 }
256                                 continue;
257                         }
258                 }
259
260                 if (DISPLAY_CPU_DEF(a->opt_flags)) {
261                         cprintf_pc(DISPLAY_UNIT(flags), 6, 9, 2,
262                                    ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
263                                    ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
264                                    ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
265                                                scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
266                                                deltot_jiffies),
267                                    ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
268                                    ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
269                                    scc->cpu_idle < scp->cpu_idle ?
270                                    0.0 :
271                                    ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
272                         printf("\n");
273                 }
274                 else if (DISPLAY_CPU_ALL(a->opt_flags)) {
275                         cprintf_pc(DISPLAY_UNIT(flags), 10, 9, 2,
276                                    (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
277                                    0.0 :
278                                    ll_sp_value(scp->cpu_user - scp->cpu_guest,
279                                                scc->cpu_user - scc->cpu_guest, deltot_jiffies),
280                                                (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
281                                    0.0 :
282                                    ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
283                                                scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
284                                    ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
285                                    ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
286                                    ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
287                                    ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
288                                    ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
289                                    ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
290                                    ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
291                                    scc->cpu_idle < scp->cpu_idle ?
292                                    0.0 :
293                                    ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
294                         printf("\n");
295                 }
296         }
297 }
298
299 /*
300  ***************************************************************************
301  * Display tasks creation and context switches statistics.
302  *
303  * IN:
304  * @a           Activity structure with statistics.
305  * @prev        Index in array where stats used as reference are.
306  * @curr        Index in array for current sample statistics.
307  * @itv         Interval of time in 1/100th of a second.
308  ***************************************************************************
309  */
310 __print_funct_t print_pcsw_stats(struct activity *a, int prev, int curr,
311                                  unsigned long long itv)
312 {
313         struct stats_pcsw
314                 *spc = (struct stats_pcsw *) a->buf[curr],
315                 *spp = (struct stats_pcsw *) a->buf[prev];
316
317         if (dis) {
318                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
319         }
320
321         printf("%-11s", timestamp[curr]);
322         cprintf_f(NO_UNIT, 2, 9, 2,
323                   S_VALUE(spp->processes,      spc->processes,      itv),
324                   S_VALUE(spp->context_switch, spc->context_switch, itv));
325         printf("\n");
326 }
327
328 /*
329  ***************************************************************************
330  * Display interrupts statistics.
331  *
332  * IN:
333  * @a           Activity structure with statistics.
334  * @prev        Index in array where stats used as reference are.
335  * @curr        Index in array for current sample statistics.
336  * @itv         Interval of time in 1/100th of a second.
337  ***************************************************************************
338  */
339 __print_funct_t print_irq_stats(struct activity *a, int prev, int curr,
340                                 unsigned long long itv)
341 {
342         int i;
343         struct stats_irq *sic, *sip;
344
345         if (dis) {
346                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
347         }
348
349         for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) {
350
351                 /*
352                  * If @nr[curr] > @nr[prev] then we consider that previous
353                  * interrupt value was 0.
354                  */
355                 sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
356                 sip = (struct stats_irq *) ((char *) a->buf[prev] + i * a->msize);
357
358                 /*
359                  * Note: @nr[curr] gives the number of interrupts read (1 .. NR_IRQS + 1).
360                  * Bitmap size is provided for (NR_IRQS + 1) interrupts.
361                  * Anyway, NR_IRQS may vary between the version of sysstat
362                  * used by sadc to create a file, and the version of sysstat
363                  * used by sar to read it...
364                  */
365
366                 /* Should current interrupt (including int "sum") be displayed? */
367                 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
368
369                         /* Yes: Display it */
370                         printf("%-11s", timestamp[curr]);
371                         if (!i) {
372                                 /* This is interrupt "sum" */
373                                 cprintf_in(IS_STR, " %s", "      sum", 0);
374                         }
375                         else {
376                                 cprintf_in(IS_INT, " %9d", "", i -1);
377                         }
378
379                         cprintf_f(NO_UNIT, 1, 9, 2, S_VALUE(sip->irq_nr, sic->irq_nr, itv));
380                         printf("\n");
381                 }
382         }
383 }
384
385 /*
386  ***************************************************************************
387  * Display swapping statistics.
388  *
389  * IN:
390  * @a           Activity structure with statistics.
391  * @prev        Index in array where stats used as reference are.
392  * @curr        Index in array for current sample statistics.
393  * @itv         Interval of time in 1/100th of a second.
394  ***************************************************************************
395  */
396 __print_funct_t print_swap_stats(struct activity *a, int prev, int curr,
397                                  unsigned long long itv)
398 {
399         struct stats_swap
400                 *ssc = (struct stats_swap *) a->buf[curr],
401                 *ssp = (struct stats_swap *) a->buf[prev];
402
403         if (dis) {
404                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
405         }
406
407         printf("%-11s", timestamp[curr]);
408         cprintf_f(NO_UNIT, 2, 9, 2,
409                   S_VALUE(ssp->pswpin,  ssc->pswpin,  itv),
410                   S_VALUE(ssp->pswpout, ssc->pswpout, itv));
411         printf("\n");
412 }
413
414 /*
415  ***************************************************************************
416  * Display paging statistics.
417  *
418  * IN:
419  * @a           Activity structure with statistics.
420  * @prev        Index in array where stats used as reference are.
421  * @curr        Index in array for current sample statistics.
422  * @itv         Interval of time in 1/100th of a second.
423  ***************************************************************************
424  */
425 __print_funct_t print_paging_stats(struct activity *a, int prev, int curr,
426                                    unsigned long long itv)
427 {
428         struct stats_paging
429                 *spc = (struct stats_paging *) a->buf[curr],
430                 *spp = (struct stats_paging *) a->buf[prev];
431
432         if (dis) {
433                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
434         }
435
436         printf("%-11s", timestamp[curr]);
437         cprintf_f(NO_UNIT, 8, 9, 2,
438                   S_VALUE(spp->pgpgin,        spc->pgpgin,        itv),
439                   S_VALUE(spp->pgpgout,       spc->pgpgout,       itv),
440                   S_VALUE(spp->pgfault,       spc->pgfault,       itv),
441                   S_VALUE(spp->pgmajfault,    spc->pgmajfault,    itv),
442                   S_VALUE(spp->pgfree,        spc->pgfree,        itv),
443                   S_VALUE(spp->pgscan_kswapd, spc->pgscan_kswapd, itv),
444                   S_VALUE(spp->pgscan_direct, spc->pgscan_direct, itv),
445                   S_VALUE(spp->pgsteal,       spc->pgsteal,       itv));
446         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
447                    (spc->pgscan_kswapd + spc->pgscan_direct -
448                    spp->pgscan_kswapd - spp->pgscan_direct) ?
449                    SP_VALUE(spp->pgsteal, spc->pgsteal,
450                             spc->pgscan_kswapd + spc->pgscan_direct -
451                             spp->pgscan_kswapd - spp->pgscan_direct)
452                    : 0.0);
453         printf("\n");
454 }
455
456 /*
457  ***************************************************************************
458  * Display I/O and transfer rate statistics.
459  *
460  * IN:
461  * @a           Activity structure with statistics.
462  * @prev        Index in array where stats used as reference are.
463  * @curr        Index in array for current sample statistics.
464  * @itv         Interval of time in 1/100th of a second.
465  ***************************************************************************
466  */
467 __print_funct_t print_io_stats(struct activity *a, int prev, int curr,
468                                unsigned long long itv)
469 {
470         struct stats_io
471                 *sic = (struct stats_io *) a->buf[curr],
472                 *sip = (struct stats_io *) a->buf[prev];
473
474         if (dis) {
475                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
476         }
477
478         printf("%-11s", timestamp[curr]);
479         /*
480          * If we get negative values, this is probably because
481          * one or more devices/filesystems have been unmounted.
482          * We display 0.0 in this case though we should rather tell
483          * the user that the value cannot be calculated here.
484          */
485         cprintf_f(NO_UNIT, 5, 9, 2,
486                   sic->dk_drive < sip->dk_drive ? 0.0 :
487                   S_VALUE(sip->dk_drive, sic->dk_drive, itv),
488                   sic->dk_drive_rio < sip->dk_drive_rio ? 0.0 :
489                   S_VALUE(sip->dk_drive_rio, sic->dk_drive_rio, itv),
490                   sic->dk_drive_wio < sip->dk_drive_wio ? 0.0 :
491                   S_VALUE(sip->dk_drive_wio, sic->dk_drive_wio, itv),
492                   sic->dk_drive_rblk < sip->dk_drive_rblk ? 0.0 :
493                   S_VALUE(sip->dk_drive_rblk, sic->dk_drive_rblk, itv),
494                   sic->dk_drive_wblk < sip->dk_drive_wblk ? 0.0 :
495                   S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv));
496         printf("\n");
497 }
498
499 /*
500  ***************************************************************************
501  * Display memory and swap statistics. This function is used to
502  * display instantaneous and average statistics.
503  *
504  * IN:
505  * @a           Activity structure with statistics.
506  * @prev        Index in array where stats used as reference are.
507  * @curr        Index in array for current sample statistics.
508  * @dispavg     TRUE if displaying average statistics.
509  ***************************************************************************
510  */
511 void stub_print_memory_stats(struct activity *a, int prev, int curr, int dispavg)
512 {
513         struct stats_memory
514                 *smc = (struct stats_memory *) a->buf[curr];
515         static unsigned long long
516                 avg_frmkb       = 0,
517                 avg_bufkb       = 0,
518                 avg_camkb       = 0,
519                 avg_comkb       = 0,
520                 avg_activekb    = 0,
521                 avg_inactkb     = 0,
522                 avg_dirtykb     = 0,
523                 avg_anonpgkb    = 0,
524                 avg_slabkb      = 0,
525                 avg_kstackkb    = 0,
526                 avg_pgtblkb     = 0,
527                 avg_vmusedkb    = 0,
528                 avg_availablekb = 0;
529         static unsigned long long
530                 avg_frskb = 0,
531                 avg_tlskb = 0,
532                 avg_caskb = 0;
533         int unit = NO_UNIT;
534
535         if (DISPLAY_UNIT(flags)) {
536                 /* Default values unit is kB */
537                 unit = UNIT_KILOBYTE;
538         }
539
540         if (DISPLAY_MEMORY(a->opt_flags)) {
541                 if (dis) {
542                         print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
543                 }
544
545                 if (!dispavg) {
546                         /* Display instantaneous values */
547                         printf("%-11s", timestamp[curr]);
548                         cprintf_u64(unit, 3, 9,
549                                     (unsigned long long) smc->frmkb,
550                                     (unsigned long long) smc->availablekb,
551                                     (unsigned long long) (smc->tlmkb - smc->frmkb));
552                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
553                                    smc->tlmkb ?
554                                    SP_VALUE(smc->frmkb, smc->tlmkb, smc->tlmkb)
555                                    : 0.0);
556                         cprintf_u64(unit, 3, 9,
557                                     (unsigned long long) smc->bufkb,
558                                     (unsigned long long) smc->camkb,
559                                     (unsigned long long) smc->comkb);
560                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
561                                    (smc->tlmkb + smc->tlskb) ?
562                                    SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb)
563                                    : 0.0);
564                         cprintf_u64(unit, 3, 9,
565                                     (unsigned long long) smc->activekb,
566                                     (unsigned long long) smc->inactkb,
567                                     (unsigned long long) smc->dirtykb);
568
569                         if (DISPLAY_MEM_ALL(a->opt_flags)) {
570                                 /* Display extended memory statistics */
571                                 cprintf_u64(unit, 5, 9,
572                                             (unsigned long long) smc->anonpgkb,
573                                             (unsigned long long) smc->slabkb,
574                                             (unsigned long long) smc->kstackkb,
575                                             (unsigned long long) smc->pgtblkb,
576                                             (unsigned long long) smc->vmusedkb);
577                         }
578
579                         printf("\n");
580
581                         /*
582                          * Will be used to compute the average.
583                          * We assume that the total amount of memory installed can not vary
584                          * during the interval given on the command line.
585                          */
586                         avg_frmkb       += smc->frmkb;
587                         avg_bufkb       += smc->bufkb;
588                         avg_camkb       += smc->camkb;
589                         avg_comkb       += smc->comkb;
590                         avg_activekb    += smc->activekb;
591                         avg_inactkb     += smc->inactkb;
592                         avg_dirtykb     += smc->dirtykb;
593                         avg_anonpgkb    += smc->anonpgkb;
594                         avg_slabkb      += smc->slabkb;
595                         avg_kstackkb    += smc->kstackkb;
596                         avg_pgtblkb     += smc->pgtblkb;
597                         avg_vmusedkb    += smc->vmusedkb;
598                         avg_availablekb += smc->availablekb;
599                 }
600                 else {
601                         /* Display average values */
602                         printf("%-11s", timestamp[curr]);
603                         cprintf_f(unit, 3, 9, 0,
604                                   (double) avg_frmkb / avg_count,
605                                   (double) avg_availablekb / avg_count,
606                                   (double) smc->tlmkb - ((double) avg_frmkb / avg_count));
607                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
608                                    smc->tlmkb ?
609                                    SP_VALUE((double) (avg_frmkb / avg_count), smc->tlmkb, smc->tlmkb)
610                                    : 0.0);
611                         cprintf_f(unit, 3, 9, 0,
612                                   (double) avg_bufkb / avg_count,
613                                   (double) avg_camkb / avg_count,
614                                   (double) avg_comkb / avg_count);
615                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
616                                    (smc->tlmkb + smc->tlskb) ?
617                                    SP_VALUE(0.0, (double) (avg_comkb / avg_count), smc->tlmkb + smc->tlskb)
618                                    : 0.0);
619                         cprintf_f(unit, 3, 9, 0,
620                                   (double) avg_activekb / avg_count,
621                                   (double) avg_inactkb / avg_count,
622                                   (double) avg_dirtykb / avg_count);
623
624                         if (DISPLAY_MEM_ALL(a->opt_flags)) {
625                                 cprintf_f(unit, 5, 9, 0,
626                                           (double) avg_anonpgkb / avg_count,
627                                           (double) avg_slabkb / avg_count,
628                                           (double) avg_kstackkb / avg_count,
629                                           (double) avg_pgtblkb / avg_count,
630                                           (double) avg_vmusedkb / avg_count);
631                         }
632
633                         printf("\n");
634
635                         /* Reset average counters */
636                         avg_frmkb = avg_bufkb = avg_camkb = avg_comkb = 0;
637                         avg_activekb = avg_inactkb = avg_dirtykb = 0;
638                         avg_anonpgkb = avg_slabkb = avg_kstackkb = 0;
639                         avg_pgtblkb = avg_vmusedkb = avg_availablekb = 0;
640                 }
641         }
642
643         if (DISPLAY_SWAP(a->opt_flags)) {
644                 if (dis) {
645                         print_hdr_line(timestamp[!curr], a, SECOND, 0, 9);
646                 }
647
648                 if (!dispavg) {
649                         /* Display instantaneous values */
650                         printf("%-11s", timestamp[curr]);
651                         cprintf_u64(unit, 2, 9,
652                                     (unsigned long long) smc->frskb,
653                                     (unsigned long long) (smc->tlskb - smc->frskb));
654                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
655                                    smc->tlskb ?
656                                    SP_VALUE(smc->frskb, smc->tlskb, smc->tlskb)
657                                    : 0.0);
658                         cprintf_u64(unit, 1, 9,
659                                     (unsigned long long) smc->caskb);
660                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
661                                    (smc->tlskb - smc->frskb) ?
662                                    SP_VALUE(0, smc->caskb, smc->tlskb - smc->frskb)
663                                    : 0.0);
664
665                         printf("\n");
666
667                         /*
668                          * Will be used to compute the average.
669                          * We assume that the total amount of swap space may vary.
670                          */
671                         avg_frskb += smc->frskb;
672                         avg_tlskb += smc->tlskb;
673                         avg_caskb += smc->caskb;
674                 }
675                 else {
676                         /* Display average values */
677                         printf("%-11s", timestamp[curr]);
678                         cprintf_f(unit, 2, 9, 0,
679                                   (double) avg_frskb / avg_count,
680                                   ((double) avg_tlskb / avg_count) -
681                                   ((double) avg_frskb / avg_count));
682                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
683                                    avg_tlskb ?
684                                    SP_VALUE((double) avg_frskb / avg_count,
685                                             (double) avg_tlskb / avg_count,
686                                             (double) avg_tlskb / avg_count)
687                                    : 0.0);
688                         cprintf_f(unit, 1, 9, 0,
689                                   (double) avg_caskb / avg_count);
690                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
691                                    (avg_tlskb != avg_frskb) ?
692                                    SP_VALUE(0.0, (double) avg_caskb / avg_count,
693                                             ((double) avg_tlskb / avg_count) -
694                                             ((double) avg_frskb / avg_count))
695                                    : 0.0);
696                         printf("\n");
697
698                         /* Reset average counters */
699                         avg_frskb = avg_tlskb = avg_caskb = 0;
700                 }
701         }
702 }
703
704 /*
705  ***************************************************************************
706  * Display memory and swap statistics.
707  *
708  * IN:
709  * @a           Activity structure with statistics.
710  * @prev        Index in array where stats used as reference are.
711  * @curr        Index in array for current sample statistics.
712  * @itv         Interval of time in 1/100th of a second.
713  ***************************************************************************
714  */
715 __print_funct_t print_memory_stats(struct activity *a, int prev, int curr,
716                                    unsigned long long itv)
717 {
718         stub_print_memory_stats(a, prev, curr, FALSE);
719 }
720
721 /*
722  ***************************************************************************
723  * Display average memory statistics.
724  *
725  * IN:
726  * @a           Activity structure with statistics.
727  * @prev        Index in array where stats used as reference are.
728  * @curr        Index in array for current sample statistics.
729  * @itv         Interval of time in 1/100th of a second.
730  ***************************************************************************
731  */
732 __print_funct_t print_avg_memory_stats(struct activity *a, int prev, int curr,
733                                        unsigned long long itv)
734 {
735         stub_print_memory_stats(a, prev, curr, TRUE);
736 }
737
738 /*
739  ***************************************************************************
740  * Display kernel tables statistics. This function is used to display
741  * instantaneous and average statistics.
742  *
743  * IN:
744  * @a           Activity structure with statistics.
745  * @curr        Index in array for current sample statistics.
746  * @dispavg     True if displaying average statistics.
747  ***************************************************************************
748  */
749 void stub_print_ktables_stats(struct activity *a, int curr, int dispavg)
750 {
751         struct stats_ktables
752                 *skc = (struct stats_ktables *) a->buf[curr];
753         static unsigned long long
754                 avg_dentry_stat = 0,
755                 avg_file_used   = 0,
756                 avg_inode_used  = 0,
757                 avg_pty_nr      = 0;
758
759
760         if (dis) {
761                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
762         }
763
764         if (!dispavg) {
765                 /* Display instantaneous values */
766                 printf("%-11s", timestamp[curr]);
767                 cprintf_u64(NO_UNIT, 4, 9,
768                             (unsigned long long) skc->dentry_stat,
769                             (unsigned long long) skc->file_used,
770                             (unsigned long long) skc->inode_used,
771                             (unsigned long long) skc->pty_nr);
772                 printf("\n");
773
774                 /*
775                  * Will be used to compute the average.
776                  * Note: Overflow unlikely to happen but not impossible...
777                  */
778                 avg_dentry_stat += skc->dentry_stat;
779                 avg_file_used   += skc->file_used;
780                 avg_inode_used  += skc->inode_used;
781                 avg_pty_nr      += skc->pty_nr;
782         }
783         else {
784                 /* Display average values */
785                 printf("%-11s", timestamp[curr]);
786                 cprintf_f(NO_UNIT, 4, 9, 0,
787                           (double) avg_dentry_stat / avg_count,
788                           (double) avg_file_used   / avg_count,
789                           (double) avg_inode_used  / avg_count,
790                           (double) avg_pty_nr      / avg_count);
791                 printf("\n");
792
793                 /* Reset average counters */
794                 avg_dentry_stat = avg_file_used = avg_inode_used = avg_pty_nr = 0;
795         }
796 }
797
798 /*
799  ***************************************************************************
800  * Display kernel tables statistics.
801  *
802  * IN:
803  * @a           Activity structure with statistics.
804  * @prev        Index in array where stats used as reference are.
805  * @curr        Index in array for current sample statistics.
806  * @itv         Interval of time in 1/100th of a second.
807  ***************************************************************************
808  */
809 __print_funct_t print_ktables_stats(struct activity *a, int prev, int curr,
810                                     unsigned long long itv)
811 {
812         stub_print_ktables_stats(a, curr, FALSE);
813 }
814
815 /*
816  ***************************************************************************
817  * Display average kernel tables statistics.
818  *
819  * IN:
820  * @a           Activity structure with statistics.
821  * @prev        Index in array where stats used as reference are.
822  * @curr        Index in array for current sample statistics.
823  * @itv         Interval of time in 1/100th of a second.
824  ***************************************************************************
825  */
826 __print_funct_t print_avg_ktables_stats(struct activity *a, int prev, int curr,
827                                         unsigned long long itv)
828 {
829         stub_print_ktables_stats(a, curr, TRUE);
830 }
831
832 /*
833  ***************************************************************************
834  * Display queue and load statistics. This function is used to display
835  * instantaneous and average statistics.
836  *
837  * IN:
838  * @a           Activity structure with statistics.
839  * @curr        Index in array for current sample statistics.
840  * @dispavg     TRUE if displaying average statistics.
841  ***************************************************************************
842  */
843 void stub_print_queue_stats(struct activity *a, int curr, int dispavg)
844 {
845         struct stats_queue
846                 *sqc = (struct stats_queue *) a->buf[curr];
847         static unsigned long long
848                 avg_nr_running    = 0,
849                 avg_nr_threads    = 0,
850                 avg_load_avg_1    = 0,
851                 avg_load_avg_5    = 0,
852                 avg_load_avg_15   = 0,
853                 avg_procs_blocked = 0;
854
855         if (dis) {
856                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
857         }
858
859         if (!dispavg) {
860                 /* Display instantaneous values */
861                 printf("%-11s", timestamp[curr]);
862                 cprintf_u64(NO_UNIT, 2, 9,
863                             (unsigned long long) sqc->nr_running,
864                             (unsigned long long) sqc->nr_threads);
865                 cprintf_f(NO_UNIT, 3, 9, 2,
866                           (double) sqc->load_avg_1  / 100,
867                           (double) sqc->load_avg_5  / 100,
868                           (double) sqc->load_avg_15 / 100);
869                 cprintf_u64(NO_UNIT, 1, 9,
870                             (unsigned long long) sqc->procs_blocked);
871                 printf("\n");
872
873                 /* Will be used to compute the average */
874                 avg_nr_running    += sqc->nr_running;
875                 avg_nr_threads    += sqc->nr_threads;
876                 avg_load_avg_1    += sqc->load_avg_1;
877                 avg_load_avg_5    += sqc->load_avg_5;
878                 avg_load_avg_15   += sqc->load_avg_15;
879                 avg_procs_blocked += sqc->procs_blocked;
880         }
881         else {
882                 /* Display average values */
883                 printf("%-11s", timestamp[curr]);
884                 cprintf_f(NO_UNIT, 2, 9, 0,
885                           (double) avg_nr_running / avg_count,
886                           (double) avg_nr_threads / avg_count);
887                 cprintf_f(NO_UNIT, 3, 9, 2,
888                           (double) avg_load_avg_1  / (avg_count * 100),
889                           (double) avg_load_avg_5  / (avg_count * 100),
890                           (double) avg_load_avg_15 / (avg_count * 100));
891                 cprintf_f(NO_UNIT, 1, 9, 0,
892                           (double) avg_procs_blocked / avg_count);
893                 printf("\n");
894
895                 /* Reset average counters */
896                 avg_nr_running = avg_nr_threads = 0;
897                 avg_load_avg_1 = avg_load_avg_5 = avg_load_avg_15 = 0;
898                 avg_procs_blocked = 0;
899         }
900 }
901
902 /*
903  ***************************************************************************
904  * Display queue and load statistics.
905  *
906  * IN:
907  * @a           Activity structure with statistics.
908  * @prev        Index in array where stats used as reference are.
909  * @curr        Index in array for current sample statistics.
910  * @itv         Interval of time in 1/100th of a second.
911  ***************************************************************************
912  */
913 __print_funct_t print_queue_stats(struct activity *a, int prev, int curr,
914                                   unsigned long long itv)
915 {
916         stub_print_queue_stats(a, curr, FALSE);
917 }
918
919 /*
920  ***************************************************************************
921  * Display average queue and load statistics.
922  *
923  * IN:
924  * @a           Activity structure with statistics.
925  * @prev        Index in array where stats used as reference are.
926  * @curr        Index in array for current sample statistics.
927  * @itv         Interval of time in 1/100th of a second.
928  ***************************************************************************
929  */
930 __print_funct_t print_avg_queue_stats(struct activity *a, int prev, int curr,
931                                       unsigned long long itv)
932 {
933         stub_print_queue_stats(a, curr, TRUE);
934 }
935
936 /*
937  ***************************************************************************
938  * Display serial lines statistics.
939  *
940  * IN:
941  * @a           Activity structure with statistics.
942  * @prev        Index in array where stats used as reference are.
943  * @curr        Index in array for current sample statistics.
944  * @itv         Interval of time in 1/100th of a second.
945  ***************************************************************************
946  */
947 __print_funct_t print_serial_stats(struct activity *a, int prev, int curr,
948                                    unsigned long long itv)
949 {
950         int i, j, j0, found;
951         struct stats_serial *ssc, *ssp;
952
953         if (dis) {
954                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
955         }
956
957         for (i = 0; i < a->nr[curr]; i++) {
958
959                 ssc = (struct stats_serial *) ((char *) a->buf[curr] + i * a->msize);
960
961                 /* Look for corresponding serial line in previous iteration */
962                 j = i;
963                 if (j > a->nr[prev]) {
964                         j = a->nr[prev];
965                 }
966
967                 j0 = j;
968                 found = FALSE;
969
970                 do {
971                         if (j > a->nr[prev]) {
972                                 j = 0;
973                         }
974                         ssp = (struct stats_serial *) ((char *) a->buf[prev] + j * a->msize);
975                         if ((ssc->line == ssp->line) || WANT_SINCE_BOOT(flags)) {
976                                 found = TRUE;
977                                 break;
978                         }
979                         j++;
980                 }
981                 while (j != j0);
982
983                 if (!found)
984                         continue;
985
986                 printf("%-11s", timestamp[curr]);
987                 cprintf_in(IS_INT, "       %3d", "", ssc->line - 1);
988
989                 cprintf_f(NO_UNIT, 6, 9, 2,
990                           S_VALUE(ssp->rx,      ssc->rx,      itv),
991                           S_VALUE(ssp->tx,      ssc->tx,      itv),
992                           S_VALUE(ssp->frame,   ssc->frame,   itv),
993                           S_VALUE(ssp->parity,  ssc->parity,  itv),
994                           S_VALUE(ssp->brk,     ssc->brk,     itv),
995                           S_VALUE(ssp->overrun, ssc->overrun, itv));
996                 printf("\n");
997         }
998 }
999
1000 /*
1001  ***************************************************************************
1002  * Display disks statistics.
1003  *
1004  * IN:
1005  * @a           Activity structure with statistics.
1006  * @prev        Index in array where stats used as reference are.
1007  * @curr        Index in array for current sample statistics.
1008  * @itv         Interval of time in 1/100th of a second.
1009  ***************************************************************************
1010  */
1011 __print_funct_t print_disk_stats(struct activity *a, int prev, int curr,
1012                                  unsigned long long itv)
1013 {
1014         int i, j;
1015         struct stats_disk *sdc, *sdp, sdpzero;
1016         struct ext_disk_stats xds;
1017         char *dev_name, *persist_dev_name;
1018         int unit = NO_UNIT;
1019
1020         memset(&sdpzero, 0, STATS_DISK_SIZE);
1021
1022         if (DISPLAY_UNIT(flags)) {
1023                 /* Default values unit is kB */
1024                 unit = UNIT_KILOBYTE;
1025         }
1026
1027         if (dis) {
1028                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1029         }
1030
1031         for (i = 0; i < a->nr[curr]; i++) {
1032
1033                 sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
1034
1035                 j = check_disk_reg(a, curr, prev, i);
1036                 if (j < 0) {
1037                         /* This is a newly registered interface. Previous stats are zero */
1038                         sdp = &sdpzero;
1039                 }
1040                 else {
1041                         sdp = (struct stats_disk *) ((char *) a->buf[prev] + j * a->msize);
1042                 }
1043
1044                 /* Compute service time, etc. */
1045                 compute_ext_disk_stats(sdc, sdp, itv, &xds);
1046
1047                 dev_name = NULL;
1048                 persist_dev_name = NULL;
1049
1050                 if (DISPLAY_PERSIST_NAME_S(flags)) {
1051                         persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
1052                 }
1053
1054                 if (persist_dev_name) {
1055                         dev_name = persist_dev_name;
1056                 }
1057                 else {
1058                         if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
1059                                 dev_name = transform_devmapname(sdc->major, sdc->minor);
1060                         }
1061
1062                         if (!dev_name) {
1063                                 dev_name = get_devname(sdc->major, sdc->minor,
1064                                                        USE_PRETTY_OPTION(flags));
1065                         }
1066                 }
1067
1068                 printf("%-11s", timestamp[curr]);
1069
1070                 cprintf_in(IS_STR, " %9s", dev_name, 0);
1071                 cprintf_f(NO_UNIT, 1, 9, 2,
1072                           S_VALUE(sdp->nr_ios, sdc->nr_ios,  itv));
1073                 cprintf_f(unit, 2, 9, 2,
1074                           S_VALUE(sdp->rd_sect, sdc->rd_sect, itv) / 2,
1075                           S_VALUE(sdp->wr_sect, sdc->wr_sect, itv) / 2);
1076                 /* See iostat for explanations */
1077                 cprintf_f(unit, 1, 9, 2,
1078                           xds.arqsz / 2);
1079                 cprintf_f(NO_UNIT, 3, 9, 2,
1080                           S_VALUE(sdp->rq_ticks, sdc->rq_ticks, itv) / 1000.0,
1081                           xds.await,
1082                           xds.svctm);
1083                 cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
1084                            xds.util / 10.0);
1085                 printf("\n");
1086         }
1087 }
1088
1089 /*
1090  ***************************************************************************
1091  * Display network interfaces statistics.
1092  *
1093  * IN:
1094  * @a           Activity structure with statistics.
1095  * @prev        Index in array where stats used as reference are.
1096  * @curr        Index in array for current sample statistics.
1097  * @itv         Interval of time in 1/100th of a second.
1098  ***************************************************************************
1099  */
1100 __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr,
1101                                     unsigned long long itv)
1102 {
1103         int i, j;
1104         struct stats_net_dev *sndc, *sndp, sndzero;
1105         double rxkb, txkb, ifutil;
1106         int unit = NO_UNIT;
1107
1108         memset(&sndzero, 0, STATS_NET_DEV_SIZE);
1109
1110         if (DISPLAY_UNIT(flags)) {
1111                 /* Default values unit is bytes */
1112                 unit = UNIT_BYTE;
1113         }
1114
1115         if (dis) {
1116                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1117         }
1118
1119         for (i = 0; i < a->nr[curr]; i++) {
1120
1121                 sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
1122
1123                 j = check_net_dev_reg(a, curr, prev, i);
1124                 if (j < 0) {
1125                         /* This is a newly registered interface. Previous stats are zero */
1126                         sndp = &sndzero;
1127                 }
1128                 else {
1129                         sndp = (struct stats_net_dev *) ((char *) a->buf[prev] + j * a->msize);
1130                 }
1131
1132                 printf("%-11s", timestamp[curr]);
1133                 cprintf_in(IS_STR, " %9s", sndc->interface, 0);
1134
1135                 rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
1136                 txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
1137
1138                 cprintf_f(NO_UNIT, 2, 9, 2,
1139                           S_VALUE(sndp->rx_packets, sndc->rx_packets, itv),
1140                           S_VALUE(sndp->tx_packets, sndc->tx_packets, itv));
1141                 cprintf_f(unit, 2, 9, 2,
1142                           unit < 0 ? rxkb / 1024 : rxkb,
1143                           unit < 0 ? txkb / 1024 : txkb);
1144                 cprintf_f(NO_UNIT, 3, 9, 2,
1145                           S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv),
1146                           S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv),
1147                           S_VALUE(sndp->multicast,     sndc->multicast,     itv));
1148                 ifutil = compute_ifutil(sndc, rxkb, txkb);
1149                 cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2, ifutil);
1150                 printf("\n");
1151         }
1152 }
1153
1154 /*
1155  ***************************************************************************
1156  * Display network interface errors statistics.
1157  *
1158  * IN:
1159  * @a           Activity structure with statistics.
1160  * @prev        Index in array where stats used as reference are.
1161  * @curr        Index in array for current sample statistics.
1162  * @itv         Interval of time in 1/100th of a second.
1163  ***************************************************************************
1164  */
1165 __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr,
1166                                      unsigned long long itv)
1167 {
1168         int i, j;
1169         struct stats_net_edev *snedc, *snedp, snedzero;
1170
1171         memset(&snedzero, 0, STATS_NET_EDEV_SIZE);
1172
1173         if (dis) {
1174                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1175         }
1176
1177         for (i = 0; i < a->nr[curr]; i++) {
1178
1179                 snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize);
1180
1181                 j = check_net_edev_reg(a, curr, prev, i);
1182                 if (j < 0) {
1183                         /* This is a newly registered interface. Previous stats are zero */
1184                         snedp = &snedzero;
1185                 }
1186                 else {
1187                         snedp = (struct stats_net_edev *) ((char *) a->buf[prev] + j * a->msize);
1188                 }
1189
1190                 printf("%-11s", timestamp[curr]);
1191                 cprintf_in(IS_STR, " %9s", snedc->interface, 0);
1192
1193                 cprintf_f(NO_UNIT, 9, 9, 2,
1194                           S_VALUE(snedp->rx_errors,         snedc->rx_errors,         itv),
1195                           S_VALUE(snedp->tx_errors,         snedc->tx_errors,         itv),
1196                           S_VALUE(snedp->collisions,        snedc->collisions,        itv),
1197                           S_VALUE(snedp->rx_dropped,        snedc->rx_dropped,        itv),
1198                           S_VALUE(snedp->tx_dropped,        snedc->tx_dropped,        itv),
1199                           S_VALUE(snedp->tx_carrier_errors, snedc->tx_carrier_errors, itv),
1200                           S_VALUE(snedp->rx_frame_errors,   snedc->rx_frame_errors,   itv),
1201                           S_VALUE(snedp->rx_fifo_errors,    snedc->rx_fifo_errors,    itv),
1202                           S_VALUE(snedp->tx_fifo_errors,    snedc->tx_fifo_errors,    itv));
1203                 printf("\n");
1204         }
1205 }
1206
1207 /*
1208  ***************************************************************************
1209  * Display NFS client statistics.
1210  *
1211  * IN:
1212  * @a           Activity structure with statistics.
1213  * @prev        Index in array where stats used as reference are.
1214  * @curr        Index in array for current sample statistics.
1215  * @itv         Interval of time in 1/100th of a second.
1216  ***************************************************************************
1217  */
1218 __print_funct_t print_net_nfs_stats(struct activity *a, int prev, int curr,
1219                                     unsigned long long itv)
1220 {
1221         struct stats_net_nfs
1222                 *snnc = (struct stats_net_nfs *) a->buf[curr],
1223                 *snnp = (struct stats_net_nfs *) a->buf[prev];
1224
1225         if (dis) {
1226                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1227         }
1228
1229         printf("%-11s", timestamp[curr]);
1230         cprintf_f(NO_UNIT, 6, 9, 2,
1231                   S_VALUE(snnp->nfs_rpccnt,     snnc->nfs_rpccnt,     itv),
1232                   S_VALUE(snnp->nfs_rpcretrans, snnc->nfs_rpcretrans, itv),
1233                   S_VALUE(snnp->nfs_readcnt,    snnc->nfs_readcnt,    itv),
1234                   S_VALUE(snnp->nfs_writecnt,   snnc->nfs_writecnt,   itv),
1235                   S_VALUE(snnp->nfs_accesscnt,  snnc->nfs_accesscnt,  itv),
1236                   S_VALUE(snnp->nfs_getattcnt,  snnc->nfs_getattcnt,  itv));
1237         printf("\n");
1238 }
1239
1240 /*
1241  ***************************************************************************
1242  * Display NFS server statistics.
1243  *
1244  * IN:
1245  * @a           Activity structure with statistics.
1246  * @prev        Index in array where stats used as reference are.
1247  * @curr        Index in array for current sample statistics.
1248  * @itv         Interval of time in 1/100th of a second.
1249  ***************************************************************************
1250  */
1251 __print_funct_t print_net_nfsd_stats(struct activity *a, int prev, int curr,
1252                                      unsigned long long itv)
1253 {
1254         struct stats_net_nfsd
1255                 *snndc = (struct stats_net_nfsd *) a->buf[curr],
1256                 *snndp = (struct stats_net_nfsd *) a->buf[prev];
1257
1258         if (dis) {
1259                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1260         }
1261
1262         printf("%-11s", timestamp[curr]);
1263         cprintf_f(NO_UNIT, 11, 9, 2,
1264                   S_VALUE(snndp->nfsd_rpccnt,    snndc->nfsd_rpccnt,    itv),
1265                   S_VALUE(snndp->nfsd_rpcbad,    snndc->nfsd_rpcbad,    itv),
1266                   S_VALUE(snndp->nfsd_netcnt,    snndc->nfsd_netcnt,    itv),
1267                   S_VALUE(snndp->nfsd_netudpcnt, snndc->nfsd_netudpcnt, itv),
1268                   S_VALUE(snndp->nfsd_nettcpcnt, snndc->nfsd_nettcpcnt, itv),
1269                   S_VALUE(snndp->nfsd_rchits,    snndc->nfsd_rchits,    itv),
1270                   S_VALUE(snndp->nfsd_rcmisses,  snndc->nfsd_rcmisses,  itv),
1271                   S_VALUE(snndp->nfsd_readcnt,   snndc->nfsd_readcnt,   itv),
1272                   S_VALUE(snndp->nfsd_writecnt,  snndc->nfsd_writecnt,  itv),
1273                   S_VALUE(snndp->nfsd_accesscnt, snndc->nfsd_accesscnt, itv),
1274                   S_VALUE(snndp->nfsd_getattcnt, snndc->nfsd_getattcnt, itv));
1275         printf("\n");
1276 }
1277
1278 /*
1279  ***************************************************************************
1280  * Display network sockets statistics. This function is used to display
1281  * instantaneous and average statistics.
1282  *
1283  * IN:
1284  * @a           Activity structure with statistics.
1285  * @curr        Index in array for current sample statistics.
1286  * @dispavg     TRUE if displaying average statistics.
1287  ***************************************************************************
1288  */
1289 void stub_print_net_sock_stats(struct activity *a, int curr, int dispavg)
1290 {
1291         struct stats_net_sock
1292                 *snsc = (struct stats_net_sock *) a->buf[curr];
1293         static unsigned long long
1294                 avg_sock_inuse = 0,
1295                 avg_tcp_inuse  = 0,
1296                 avg_udp_inuse  = 0,
1297                 avg_raw_inuse  = 0,
1298                 avg_frag_inuse = 0,
1299                 avg_tcp_tw     = 0;
1300
1301         if (dis) {
1302                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1303         }
1304
1305         if (!dispavg) {
1306                 /* Display instantaneous values */
1307                 printf("%-11s", timestamp[curr]);
1308                 cprintf_u64(NO_UNIT, 6, 9,
1309                             (unsigned long long) snsc->sock_inuse,
1310                             (unsigned long long) snsc->tcp_inuse,
1311                             (unsigned long long) snsc->udp_inuse,
1312                             (unsigned long long) snsc->raw_inuse,
1313                             (unsigned long long) snsc->frag_inuse,
1314                             (unsigned long long) snsc->tcp_tw);
1315                 printf("\n");
1316
1317                 /* Will be used to compute the average */
1318                 avg_sock_inuse += snsc->sock_inuse;
1319                 avg_tcp_inuse  += snsc->tcp_inuse;
1320                 avg_udp_inuse  += snsc->udp_inuse;
1321                 avg_raw_inuse  += snsc->raw_inuse;
1322                 avg_frag_inuse += snsc->frag_inuse;
1323                 avg_tcp_tw     += snsc->tcp_tw;
1324         }
1325         else {
1326                 /* Display average values */
1327                 printf("%-11s", timestamp[curr]);
1328                 cprintf_f(NO_UNIT, 6, 9, 0,
1329                           (double) avg_sock_inuse / avg_count,
1330                           (double) avg_tcp_inuse  / avg_count,
1331                           (double) avg_udp_inuse  / avg_count,
1332                           (double) avg_raw_inuse  / avg_count,
1333                           (double) avg_frag_inuse / avg_count,
1334                           (double) avg_tcp_tw     / avg_count);
1335                 printf("\n");
1336
1337                 /* Reset average counters */
1338                 avg_sock_inuse = avg_tcp_inuse = avg_udp_inuse = 0;
1339                 avg_raw_inuse = avg_frag_inuse = avg_tcp_tw = 0;
1340         }
1341 }
1342
1343 /*
1344  ***************************************************************************
1345  * Display network sockets statistics.
1346  *
1347  * IN:
1348  * @a           Activity structure with statistics.
1349  * @prev        Index in array where stats used as reference are.
1350  * @curr        Index in array for current sample statistics.
1351  * @itv         Interval of time in 1/100th of a second.
1352  ***************************************************************************
1353  */
1354 __print_funct_t print_net_sock_stats(struct activity *a, int prev, int curr,
1355                                      unsigned long long itv)
1356 {
1357         stub_print_net_sock_stats(a, curr, FALSE);
1358 }
1359
1360 /*
1361  ***************************************************************************
1362  * Display average network sockets statistics.
1363  *
1364  * IN:
1365  * @a           Activity structure with statistics.
1366  * @prev        Index in array where stats used as reference are.
1367  * @curr        Index in array for current sample statistics.
1368  * @itv         Interval of time in 1/100th of a second.
1369  ***************************************************************************
1370  */
1371 __print_funct_t print_avg_net_sock_stats(struct activity *a, int prev, int curr,
1372                                          unsigned long long itv)
1373 {
1374         stub_print_net_sock_stats(a, curr, TRUE);
1375 }
1376
1377 /*
1378  ***************************************************************************
1379  * Display IP network traffic statistics.
1380  *
1381  * IN:
1382  * @a           Activity structure with statistics.
1383  * @prev        Index in array where stats used as reference are.
1384  * @curr        Index in array for current sample statistics.
1385  * @itv         Interval of time in 1/100th of a second.
1386  ***************************************************************************
1387  */
1388 __print_funct_t print_net_ip_stats(struct activity *a, int prev, int curr,
1389                                    unsigned long long itv)
1390 {
1391         struct stats_net_ip
1392                 *snic = (struct stats_net_ip *) a->buf[curr],
1393                 *snip = (struct stats_net_ip *) a->buf[prev];
1394
1395         if (dis) {
1396                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1397         }
1398
1399         printf("%-11s", timestamp[curr]);
1400         cprintf_f(NO_UNIT, 8, 9, 2,
1401                   S_VALUE(snip->InReceives,    snic->InReceives,    itv),
1402                   S_VALUE(snip->ForwDatagrams, snic->ForwDatagrams, itv),
1403                   S_VALUE(snip->InDelivers,    snic->InDelivers,    itv),
1404                   S_VALUE(snip->OutRequests,   snic->OutRequests,   itv),
1405                   S_VALUE(snip->ReasmReqds,    snic->ReasmReqds,    itv),
1406                   S_VALUE(snip->ReasmOKs,      snic->ReasmOKs,      itv),
1407                   S_VALUE(snip->FragOKs,       snic->FragOKs,       itv),
1408                   S_VALUE(snip->FragCreates,   snic->FragCreates,   itv));
1409         printf("\n");
1410 }
1411
1412 /*
1413  ***************************************************************************
1414  * Display IP network errors statistics.
1415  *
1416  * IN:
1417  * @a           Activity structure with statistics.
1418  * @prev        Index in array where stats used as reference are.
1419  * @curr        Index in array for current sample statistics.
1420  * @itv         Interval of time in 1/100th of a second.
1421  ***************************************************************************
1422  */
1423 __print_funct_t print_net_eip_stats(struct activity *a, int prev, int curr,
1424                                     unsigned long long itv)
1425 {
1426         struct stats_net_eip
1427                 *sneic = (struct stats_net_eip *) a->buf[curr],
1428                 *sneip = (struct stats_net_eip *) a->buf[prev];
1429
1430         if (dis) {
1431                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1432         }
1433
1434         printf("%-11s", timestamp[curr]);
1435         cprintf_f(NO_UNIT, 8, 9, 2,
1436                   S_VALUE(sneip->InHdrErrors,     sneic->InHdrErrors,     itv),
1437                   S_VALUE(sneip->InAddrErrors,    sneic->InAddrErrors,    itv),
1438                   S_VALUE(sneip->InUnknownProtos, sneic->InUnknownProtos, itv),
1439                   S_VALUE(sneip->InDiscards,      sneic->InDiscards,      itv),
1440                   S_VALUE(sneip->OutDiscards,     sneic->OutDiscards,     itv),
1441                   S_VALUE(sneip->OutNoRoutes,     sneic->OutNoRoutes,     itv),
1442                   S_VALUE(sneip->ReasmFails,      sneic->ReasmFails,      itv),
1443                   S_VALUE(sneip->FragFails,       sneic->FragFails,       itv));
1444         printf("\n");
1445 }
1446
1447 /*
1448  ***************************************************************************
1449  * Display ICMP network traffic statistics.
1450  *
1451  * IN:
1452  * @a           Activity structure with statistics.
1453  * @prev        Index in array where stats used as reference are.
1454  * @curr        Index in array for current sample statistics.
1455  * @itv         Interval of time in 1/100th of a second.
1456  ***************************************************************************
1457  */
1458 __print_funct_t print_net_icmp_stats(struct activity *a, int prev, int curr,
1459                                      unsigned long long itv)
1460 {
1461         struct stats_net_icmp
1462                 *snic = (struct stats_net_icmp *) a->buf[curr],
1463                 *snip = (struct stats_net_icmp *) a->buf[prev];
1464
1465         if (dis) {
1466                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1467         }
1468
1469         printf("%-11s", timestamp[curr]);
1470         cprintf_f(NO_UNIT, 14, 9, 2,
1471                   S_VALUE(snip->InMsgs,           snic->InMsgs,           itv),
1472                   S_VALUE(snip->OutMsgs,          snic->OutMsgs,          itv),
1473                   S_VALUE(snip->InEchos,          snic->InEchos,          itv),
1474                   S_VALUE(snip->InEchoReps,       snic->InEchoReps,       itv),
1475                   S_VALUE(snip->OutEchos,         snic->OutEchos,         itv),
1476                   S_VALUE(snip->OutEchoReps,      snic->OutEchoReps,      itv),
1477                   S_VALUE(snip->InTimestamps,     snic->InTimestamps,     itv),
1478                   S_VALUE(snip->InTimestampReps,  snic->InTimestampReps,  itv),
1479                   S_VALUE(snip->OutTimestamps,    snic->OutTimestamps,    itv),
1480                   S_VALUE(snip->OutTimestampReps, snic->OutTimestampReps, itv),
1481                   S_VALUE(snip->InAddrMasks,      snic->InAddrMasks,      itv),
1482                   S_VALUE(snip->InAddrMaskReps,   snic->InAddrMaskReps,   itv),
1483                   S_VALUE(snip->OutAddrMasks,     snic->OutAddrMasks,     itv),
1484                   S_VALUE(snip->OutAddrMaskReps,  snic->OutAddrMaskReps,  itv));
1485         printf("\n");
1486 }
1487
1488 /*
1489  ***************************************************************************
1490  * Display ICMP network errors statistics.
1491  *
1492  * IN:
1493  * @a           Activity structure with statistics.
1494  * @prev        Index in array where stats used as reference are.
1495  * @curr        Index in array for current sample statistics.
1496  * @itv         Interval of time in 1/100th of a second.
1497  ***************************************************************************
1498  */
1499 __print_funct_t print_net_eicmp_stats(struct activity *a, int prev, int curr,
1500                                       unsigned long long itv)
1501 {
1502         struct stats_net_eicmp
1503                 *sneic = (struct stats_net_eicmp *) a->buf[curr],
1504                 *sneip = (struct stats_net_eicmp *) a->buf[prev];
1505
1506         if (dis) {
1507                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1508         }
1509
1510         printf("%-11s", timestamp[curr]);
1511         cprintf_f(NO_UNIT, 12, 9, 2,
1512                   S_VALUE(sneip->InErrors,        sneic->InErrors,        itv),
1513                   S_VALUE(sneip->OutErrors,       sneic->OutErrors,       itv),
1514                   S_VALUE(sneip->InDestUnreachs,  sneic->InDestUnreachs,  itv),
1515                   S_VALUE(sneip->OutDestUnreachs, sneic->OutDestUnreachs, itv),
1516                   S_VALUE(sneip->InTimeExcds,     sneic->InTimeExcds,     itv),
1517                   S_VALUE(sneip->OutTimeExcds,    sneic->OutTimeExcds,    itv),
1518                   S_VALUE(sneip->InParmProbs,     sneic->InParmProbs,     itv),
1519                   S_VALUE(sneip->OutParmProbs,    sneic->OutParmProbs,    itv),
1520                   S_VALUE(sneip->InSrcQuenchs,    sneic->InSrcQuenchs,    itv),
1521                   S_VALUE(sneip->OutSrcQuenchs,   sneic->OutSrcQuenchs,   itv),
1522                   S_VALUE(sneip->InRedirects,     sneic->InRedirects,     itv),
1523                   S_VALUE(sneip->OutRedirects,    sneic->OutRedirects,    itv));
1524         printf("\n");
1525 }
1526
1527 /*
1528  ***************************************************************************
1529  * Display TCP network traffic statistics.
1530  *
1531  * IN:
1532  * @a           Activity structure with statistics.
1533  * @prev        Index in array where stats used as reference are.
1534  * @curr        Index in array for current sample statistics.
1535  * @itv         Interval of time in 1/100th of a second.
1536  ***************************************************************************
1537  */
1538 __print_funct_t print_net_tcp_stats(struct activity *a, int prev, int curr,
1539                                     unsigned long long itv)
1540 {
1541         struct stats_net_tcp
1542                 *sntc = (struct stats_net_tcp *) a->buf[curr],
1543                 *sntp = (struct stats_net_tcp *) a->buf[prev];
1544
1545         if (dis) {
1546                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1547         }
1548
1549         printf("%-11s", timestamp[curr]);
1550         cprintf_f(NO_UNIT, 4, 9, 2,
1551                   S_VALUE(sntp->ActiveOpens,  sntc->ActiveOpens,  itv),
1552                   S_VALUE(sntp->PassiveOpens, sntc->PassiveOpens, itv),
1553                   S_VALUE(sntp->InSegs,       sntc->InSegs,       itv),
1554                   S_VALUE(sntp->OutSegs,      sntc->OutSegs,      itv));
1555         printf("\n");
1556 }
1557
1558 /*
1559  ***************************************************************************
1560  * Display TCP network errors statistics.
1561  *
1562  * IN:
1563  * @a           Activity structure with statistics.
1564  * @prev        Index in array where stats used as reference are.
1565  * @curr        Index in array for current sample statistics.
1566  * @itv         Interval of time in 1/100th of a second.
1567  ***************************************************************************
1568  */
1569 __print_funct_t print_net_etcp_stats(struct activity *a, int prev, int curr,
1570                                      unsigned long long itv)
1571 {
1572         struct stats_net_etcp
1573                 *snetc = (struct stats_net_etcp *) a->buf[curr],
1574                 *snetp = (struct stats_net_etcp *) a->buf[prev];
1575
1576         if (dis) {
1577                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1578         }
1579
1580         printf("%-11s", timestamp[curr]);
1581         cprintf_f(NO_UNIT, 5, 9, 2,
1582                   S_VALUE(snetp->AttemptFails, snetc->AttemptFails, itv),
1583                   S_VALUE(snetp->EstabResets,  snetc->EstabResets,  itv),
1584                   S_VALUE(snetp->RetransSegs,  snetc->RetransSegs,  itv),
1585                   S_VALUE(snetp->InErrs,       snetc->InErrs,       itv),
1586                   S_VALUE(snetp->OutRsts,      snetc->OutRsts,      itv));
1587         printf("\n");
1588 }
1589
1590 /*
1591  ***************************************************************************
1592  * Display UDP network traffic statistics.
1593  *
1594  * IN:
1595  * @a           Activity structure with statistics.
1596  * @prev        Index in array where stats used as reference are.
1597  * @curr        Index in array for current sample statistics.
1598  * @itv         Interval of time in 1/100th of a second.
1599  ***************************************************************************
1600  */
1601 __print_funct_t print_net_udp_stats(struct activity *a, int prev, int curr,
1602                                     unsigned long long itv)
1603 {
1604         struct stats_net_udp
1605                 *snuc = (struct stats_net_udp *) a->buf[curr],
1606                 *snup = (struct stats_net_udp *) a->buf[prev];
1607
1608         if (dis) {
1609                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1610         }
1611
1612         printf("%-11s", timestamp[curr]);
1613         cprintf_f(NO_UNIT, 4, 9, 2,
1614                   S_VALUE(snup->InDatagrams,  snuc->InDatagrams,  itv),
1615                   S_VALUE(snup->OutDatagrams, snuc->OutDatagrams, itv),
1616                   S_VALUE(snup->NoPorts,      snuc->NoPorts,      itv),
1617                   S_VALUE(snup->InErrors,     snuc->InErrors,     itv));
1618         printf("\n");
1619 }
1620
1621 /*
1622  ***************************************************************************
1623  * Display IPv6 sockets statistics. This function is used to display
1624  * instantaneous and average statistics.
1625  *
1626  * IN:
1627  * @a           Activity structure with statistics.
1628  * @curr        Index in array for current sample statistics.
1629  * @dispavg     TRUE if displaying average statistics.
1630  ***************************************************************************
1631  */
1632 void stub_print_net_sock6_stats(struct activity *a, int curr, int dispavg)
1633 {
1634         struct stats_net_sock6
1635                 *snsc = (struct stats_net_sock6 *) a->buf[curr];
1636         static unsigned long long
1637                 avg_tcp6_inuse  = 0,
1638                 avg_udp6_inuse  = 0,
1639                 avg_raw6_inuse  = 0,
1640                 avg_frag6_inuse = 0;
1641
1642         if (dis) {
1643                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1644         }
1645
1646         if (!dispavg) {
1647                 /* Display instantaneous values */
1648                 printf("%-11s", timestamp[curr]);
1649                 cprintf_u64(NO_UNIT, 4, 9,
1650                             (unsigned long long) snsc->tcp6_inuse,
1651                             (unsigned long long) snsc->udp6_inuse,
1652                             (unsigned long long) snsc->raw6_inuse,
1653                             (unsigned long long) snsc->frag6_inuse);
1654                 printf("\n");
1655
1656                 /* Will be used to compute the average */
1657                 avg_tcp6_inuse  += snsc->tcp6_inuse;
1658                 avg_udp6_inuse  += snsc->udp6_inuse;
1659                 avg_raw6_inuse  += snsc->raw6_inuse;
1660                 avg_frag6_inuse += snsc->frag6_inuse;
1661         }
1662         else {
1663                 /* Display average values */
1664                 printf("%-11s", timestamp[curr]);
1665                 cprintf_f(NO_UNIT, 4, 9, 0,
1666                           (double) avg_tcp6_inuse  / avg_count,
1667                           (double) avg_udp6_inuse  / avg_count,
1668                           (double) avg_raw6_inuse  / avg_count,
1669                           (double) avg_frag6_inuse / avg_count);
1670                 printf("\n");
1671
1672                 /* Reset average counters */
1673                 avg_tcp6_inuse = avg_udp6_inuse = avg_raw6_inuse = avg_frag6_inuse = 0;
1674         }
1675 }
1676
1677 /*
1678  ***************************************************************************
1679  * Display IPv6 sockets statistics.
1680  *
1681  * IN:
1682  * @a           Activity structure with statistics.
1683  * @prev        Index in array where stats used as reference are.
1684  * @curr        Index in array for current sample statistics.
1685  * @itv         Interval of time in 1/100th of a second.
1686  ***************************************************************************
1687  */
1688 __print_funct_t print_net_sock6_stats(struct activity *a, int prev, int curr,
1689                                       unsigned long long itv)
1690 {
1691         stub_print_net_sock6_stats(a, curr, FALSE);
1692 }
1693
1694 /*
1695  ***************************************************************************
1696  * Display average IPv6 sockets statistics.
1697  *
1698  * IN:
1699  * @a           Activity structure with statistics.
1700  * @prev        Index in array where stats used as reference are.
1701  * @curr        Index in array for current sample statistics.
1702  * @itv         Interval of time in 1/100th of a second.
1703  ***************************************************************************
1704  */
1705 __print_funct_t print_avg_net_sock6_stats(struct activity *a, int prev, int curr,
1706                                           unsigned long long itv)
1707 {
1708         stub_print_net_sock6_stats(a, curr, TRUE);
1709 }
1710
1711 /*
1712  ***************************************************************************
1713  * Display IPv6 network traffic statistics.
1714  *
1715  * IN:
1716  * @a           Activity structure with statistics.
1717  * @prev        Index in array where stats used as reference are.
1718  * @curr        Index in array for current sample statistics.
1719  * @itv         Interval of time in 1/100th of a second.
1720  ***************************************************************************
1721  */
1722 __print_funct_t print_net_ip6_stats(struct activity *a, int prev, int curr,
1723                                     unsigned long long itv)
1724 {
1725         struct stats_net_ip6
1726                 *snic = (struct stats_net_ip6 *) a->buf[curr],
1727                 *snip = (struct stats_net_ip6 *) a->buf[prev];
1728
1729         if (dis) {
1730                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1731         }
1732
1733         printf("%-11s", timestamp[curr]);
1734         cprintf_f(NO_UNIT, 10, 9, 2,
1735                   S_VALUE(snip->InReceives6,       snic->InReceives6,       itv),
1736                   S_VALUE(snip->OutForwDatagrams6, snic->OutForwDatagrams6, itv),
1737                   S_VALUE(snip->InDelivers6,       snic->InDelivers6,       itv),
1738                   S_VALUE(snip->OutRequests6,      snic->OutRequests6,      itv),
1739                   S_VALUE(snip->ReasmReqds6,       snic->ReasmReqds6,       itv),
1740                   S_VALUE(snip->ReasmOKs6,         snic->ReasmOKs6,         itv),
1741                   S_VALUE(snip->InMcastPkts6,      snic->InMcastPkts6,      itv),
1742                   S_VALUE(snip->OutMcastPkts6,     snic->OutMcastPkts6,     itv),
1743                   S_VALUE(snip->FragOKs6,          snic->FragOKs6,          itv),
1744                   S_VALUE(snip->FragCreates6,      snic->FragCreates6,      itv));
1745         printf("\n");
1746 }
1747
1748 /*
1749  ***************************************************************************
1750  * Display IPv6 network errors statistics.
1751  *
1752  * IN:
1753  * @a           Activity structure with statistics.
1754  * @prev        Index in array where stats used as reference are.
1755  * @curr        Index in array for current sample statistics.
1756  * @itv         Interval of time in 1/100th of a second.
1757  ***************************************************************************
1758  */
1759 __print_funct_t print_net_eip6_stats(struct activity *a, int prev, int curr,
1760                                      unsigned long long itv)
1761 {
1762         struct stats_net_eip6
1763                 *sneic = (struct stats_net_eip6 *) a->buf[curr],
1764                 *sneip = (struct stats_net_eip6 *) a->buf[prev];
1765
1766         if (dis) {
1767                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1768         }
1769
1770         printf("%-11s", timestamp[curr]);
1771         cprintf_f(NO_UNIT, 11, 9, 2,
1772                   S_VALUE(sneip->InHdrErrors6,     sneic->InHdrErrors6,     itv),
1773                   S_VALUE(sneip->InAddrErrors6,    sneic->InAddrErrors6,    itv),
1774                   S_VALUE(sneip->InUnknownProtos6, sneic->InUnknownProtos6, itv),
1775                   S_VALUE(sneip->InTooBigErrors6,  sneic->InTooBigErrors6,  itv),
1776                   S_VALUE(sneip->InDiscards6,      sneic->InDiscards6,      itv),
1777                   S_VALUE(sneip->OutDiscards6,     sneic->OutDiscards6,     itv),
1778                   S_VALUE(sneip->InNoRoutes6,      sneic->InNoRoutes6,      itv),
1779                   S_VALUE(sneip->OutNoRoutes6,     sneic->OutNoRoutes6,     itv),
1780                   S_VALUE(sneip->ReasmFails6,      sneic->ReasmFails6,      itv),
1781                   S_VALUE(sneip->FragFails6,       sneic->FragFails6,       itv),
1782                   S_VALUE(sneip->InTruncatedPkts6, sneic->InTruncatedPkts6, itv));
1783         printf("\n");
1784 }
1785
1786 /*
1787  ***************************************************************************
1788  * Display ICMPv6 network traffic statistics.
1789  *
1790  * IN:
1791  * @a           Activity structure with statistics.
1792  * @prev        Index in array where stats used as reference are.
1793  * @curr        Index in array for current sample statistics.
1794  * @itv         Interval of time in 1/100th of a second.
1795  ***************************************************************************
1796  */
1797 __print_funct_t print_net_icmp6_stats(struct activity *a, int prev, int curr,
1798                                       unsigned long long itv)
1799 {
1800         struct stats_net_icmp6
1801                 *snic = (struct stats_net_icmp6 *) a->buf[curr],
1802                 *snip = (struct stats_net_icmp6 *) a->buf[prev];
1803
1804         if (dis) {
1805                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1806         }
1807
1808         printf("%-11s", timestamp[curr]);
1809         cprintf_f(NO_UNIT, 17, 9, 2,
1810                   S_VALUE(snip->InMsgs6,                    snic->InMsgs6,                    itv),
1811                   S_VALUE(snip->OutMsgs6,                   snic->OutMsgs6,                   itv),
1812                   S_VALUE(snip->InEchos6,                   snic->InEchos6,                   itv),
1813                   S_VALUE(snip->InEchoReplies6,             snic->InEchoReplies6,             itv),
1814                   S_VALUE(snip->OutEchoReplies6,            snic->OutEchoReplies6,            itv),
1815                   S_VALUE(snip->InGroupMembQueries6,        snic->InGroupMembQueries6,        itv),
1816                   S_VALUE(snip->InGroupMembResponses6,      snic->InGroupMembResponses6,      itv),
1817                   S_VALUE(snip->OutGroupMembResponses6,     snic->OutGroupMembResponses6,     itv),
1818                   S_VALUE(snip->InGroupMembReductions6,     snic->InGroupMembReductions6,     itv),
1819                   S_VALUE(snip->OutGroupMembReductions6,    snic->OutGroupMembReductions6,    itv),
1820                   S_VALUE(snip->InRouterSolicits6,          snic->InRouterSolicits6,          itv),
1821                   S_VALUE(snip->OutRouterSolicits6,         snic->OutRouterSolicits6,         itv),
1822                   S_VALUE(snip->InRouterAdvertisements6,    snic->InRouterAdvertisements6,    itv),
1823                   S_VALUE(snip->InNeighborSolicits6,        snic->InNeighborSolicits6,        itv),
1824                   S_VALUE(snip->OutNeighborSolicits6,       snic->OutNeighborSolicits6,       itv),
1825                   S_VALUE(snip->InNeighborAdvertisements6,  snic->InNeighborAdvertisements6,  itv),
1826                   S_VALUE(snip->OutNeighborAdvertisements6, snic->OutNeighborAdvertisements6, itv));
1827         printf("\n");
1828 }
1829
1830 /*
1831  ***************************************************************************
1832  * Display ICMPv6 network errors statistics.
1833  *
1834  * IN:
1835  * @a           Activity structure with statistics.
1836  * @prev        Index in array where stats used as reference are.
1837  * @curr        Index in array for current sample statistics.
1838  * @itv         Interval of time in 1/100th of a second.
1839  ***************************************************************************
1840  */
1841 __print_funct_t print_net_eicmp6_stats(struct activity *a, int prev, int curr,
1842                                        unsigned long long itv)
1843 {
1844         struct stats_net_eicmp6
1845                 *sneic = (struct stats_net_eicmp6 *) a->buf[curr],
1846                 *sneip = (struct stats_net_eicmp6 *) a->buf[prev];
1847
1848         if (dis) {
1849                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1850         }
1851
1852         printf("%-11s", timestamp[curr]);
1853         cprintf_f(NO_UNIT, 11, 9, 2,
1854                   S_VALUE(sneip->InErrors6,        sneic->InErrors6,        itv),
1855                   S_VALUE(sneip->InDestUnreachs6,  sneic->InDestUnreachs6,  itv),
1856                   S_VALUE(sneip->OutDestUnreachs6, sneic->OutDestUnreachs6, itv),
1857                   S_VALUE(sneip->InTimeExcds6,     sneic->InTimeExcds6,     itv),
1858                   S_VALUE(sneip->OutTimeExcds6,    sneic->OutTimeExcds6,    itv),
1859                   S_VALUE(sneip->InParmProblems6,  sneic->InParmProblems6,  itv),
1860                   S_VALUE(sneip->OutParmProblems6, sneic->OutParmProblems6, itv),
1861                   S_VALUE(sneip->InRedirects6,     sneic->InRedirects6,     itv),
1862                   S_VALUE(sneip->OutRedirects6,    sneic->OutRedirects6,    itv),
1863                   S_VALUE(sneip->InPktTooBigs6,    sneic->InPktTooBigs6,    itv),
1864                   S_VALUE(sneip->OutPktTooBigs6,   sneic->OutPktTooBigs6,   itv));
1865         printf("\n");
1866 }
1867
1868 /*
1869  ***************************************************************************
1870  * Display UDPv6 network traffic statistics.
1871  *
1872  * IN:
1873  * @a           Activity structure with statistics.
1874  * @prev        Index in array where stats used as reference are.
1875  * @curr        Index in array for current sample statistics.
1876  * @itv         Interval of time in 1/100th of a second.
1877  ***************************************************************************
1878  */
1879 __print_funct_t print_net_udp6_stats(struct activity *a, int prev, int curr,
1880                                      unsigned long long itv)
1881 {
1882         struct stats_net_udp6
1883                 *snuc = (struct stats_net_udp6 *) a->buf[curr],
1884                 *snup = (struct stats_net_udp6 *) a->buf[prev];
1885
1886         if (dis) {
1887                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
1888         }
1889
1890         printf("%-11s", timestamp[curr]);
1891         cprintf_f(NO_UNIT, 4, 9, 2,
1892                   S_VALUE(snup->InDatagrams6,  snuc->InDatagrams6,  itv),
1893                   S_VALUE(snup->OutDatagrams6, snuc->OutDatagrams6, itv),
1894                   S_VALUE(snup->NoPorts6,      snuc->NoPorts6,      itv),
1895                   S_VALUE(snup->InErrors6,     snuc->InErrors6,     itv));
1896         printf("\n");
1897 }
1898
1899 /*
1900  ***************************************************************************
1901  * Display CPU frequency statistics. This function is used to display
1902  * instantaneous and average statistics.
1903  *
1904  * IN:
1905  * @a           Activity structure with statistics.
1906  * @curr        Index in array for current sample statistics.
1907  * @dispavg     True if displaying average statistics.
1908  ***************************************************************************
1909  */
1910 void stub_print_pwr_cpufreq_stats(struct activity *a, int curr, int dispavg)
1911 {
1912         int i;
1913         struct stats_pwr_cpufreq *spc;
1914         static __nr_t nr_alloc = 0;
1915         static unsigned long long
1916                 *avg_cpufreq = NULL;
1917
1918         if (!avg_cpufreq || (a->nr[curr] > nr_alloc)) {
1919                 /* Allocate array of CPU frequency */
1920                 SREALLOC(avg_cpufreq, unsigned long long, sizeof(unsigned long long) * a->nr[curr]);
1921                 if (a->nr[curr] > nr_alloc) {
1922                         /* Init additional space allocated */
1923                         memset(avg_cpufreq + nr_alloc, 0,
1924                                sizeof(unsigned long long) * (a->nr[curr] - nr_alloc));
1925                 }
1926                 nr_alloc = a->nr[curr];
1927         }
1928
1929         if (dis) {
1930                 print_hdr_line(timestamp[!curr], a, FIRST, 7, 9);
1931         }
1932
1933         for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) {
1934
1935                 /*
1936                  * The size of a->buf[...] CPU structure may be different from the default
1937                  * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file!
1938                  * That's why we don't use a syntax like:
1939                  * spc = (struct stats_pwr_cpufreq *) a->buf[...] + i;
1940                  */
1941                 spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);
1942
1943                 if (!spc->cpufreq)
1944                         /* This CPU is offline: Don't display it */
1945                         continue;
1946
1947                 /*
1948                  * Note: @nr[curr] is in [1, NR_CPUS + 1].
1949                  * Bitmap size is provided for (NR_CPUS + 1) CPUs.
1950                  * Anyway, NR_CPUS may vary between the version of sysstat
1951                  * used by sadc to create a file, and the version of sysstat
1952                  * used by sar to read it...
1953                  */
1954
1955                 /* Should current CPU (including CPU "all") be displayed? */
1956                 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
1957                         /* No */
1958                         continue;
1959
1960                 printf("%-11s", timestamp[curr]);
1961
1962                 if (!i) {
1963                         /* This is CPU "all" */
1964                         cprintf_in(IS_STR, "%s", "     all", 0);
1965                 }
1966                 else {
1967                         cprintf_in(IS_INT, "     %3d", "", i - 1);
1968                 }
1969
1970                 if (!dispavg) {
1971                         /* Display instantaneous values */
1972                         cprintf_f(NO_UNIT, 1, 9, 2,
1973                                   ((double) spc->cpufreq) / 100);
1974                         printf("\n");
1975                         /*
1976                          * Will be used to compute the average.
1977                          * Note: Overflow unlikely to happen but not impossible...
1978                          */
1979                         avg_cpufreq[i] += spc->cpufreq;
1980                 }
1981                 else {
1982                         /* Display average values */
1983                         cprintf_f(NO_UNIT, 1, 9, 2,
1984                                   (double) avg_cpufreq[i] / (100 * avg_count));
1985                         printf("\n");
1986                 }
1987         }
1988
1989         if (dispavg && avg_cpufreq) {
1990                 /* Array of CPU frequency no longer needed: Free it! */
1991                 free(avg_cpufreq);
1992                 avg_cpufreq = NULL;
1993                 nr_alloc = 0;
1994         }
1995 }
1996
1997 /*
1998  ***************************************************************************
1999  * Display CPU frequency statistics.
2000  *
2001  * IN:
2002  * @a           Activity structure with statistics.
2003  * @prev        Index in array where stats used as reference are.
2004  * @curr        Index in array for current sample statistics.
2005  * @itv         Interval of time in 1/100th of a second.
2006  ***************************************************************************
2007  */
2008 __print_funct_t print_pwr_cpufreq_stats(struct activity *a, int prev, int curr,
2009                                         unsigned long long itv)
2010 {
2011         stub_print_pwr_cpufreq_stats(a, curr, FALSE);
2012 }
2013
2014 /*
2015  ***************************************************************************
2016  * Display average CPU frequency statistics.
2017  *
2018  * IN:
2019  * @a           Activity structure with statistics.
2020  * @prev        Index in array where stats used as reference are.
2021  * @curr        Index in array for current sample statistics.
2022  * @itv         Interval of time in 1/100th of a second.
2023  ***************************************************************************
2024  */
2025 __print_funct_t print_avg_pwr_cpufreq_stats(struct activity *a, int prev, int curr,
2026                                             unsigned long long itv)
2027 {
2028         stub_print_pwr_cpufreq_stats(a, curr, TRUE);
2029 }
2030
2031 /*
2032  ***************************************************************************
2033  * Display fan statistics. This function is used to display
2034  * instantaneous and average statistics.
2035  *
2036  * IN:
2037  * @a           Activity structure with statistics.
2038  * @curr        Index in array for current sample statistics.
2039  * @dispavg     True if displaying average statistics.
2040  ***************************************************************************
2041  */
2042 void stub_print_pwr_fan_stats(struct activity *a, int curr, int dispavg)
2043 {
2044         int i;
2045         struct stats_pwr_fan *spc;
2046         static __nr_t nr_alloc = 0;
2047         static double *avg_fan = NULL;
2048         static double *avg_fan_min = NULL;
2049
2050         /* Allocate arrays of fan RPMs */
2051         if (!avg_fan || (a->nr[curr] > nr_alloc)) {
2052                 SREALLOC(avg_fan, double, sizeof(double) * a->nr[curr]);
2053                 SREALLOC(avg_fan_min, double, sizeof(double) * a->nr[curr]);
2054
2055                 if (a->nr[curr] > nr_alloc) {
2056                         /* Init additional space allocated */
2057                         memset(avg_fan + nr_alloc, 0,
2058                                sizeof(double) * (a->nr[curr] - nr_alloc));
2059                         memset(avg_fan_min + nr_alloc, 0,
2060                                sizeof(double) * (a->nr[curr] - nr_alloc));
2061                 }
2062                 nr_alloc = a->nr[curr];
2063         }
2064
2065         if (dis) {
2066                 print_hdr_line(timestamp[!curr], a, FIRST, -2, 9);
2067         }
2068
2069         for (i = 0; i < a->nr[curr]; i++) {
2070                 spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize);
2071
2072                 printf("%-11s", timestamp[curr]);
2073                 cprintf_in(IS_INT, "     %5d", "", i + 1);
2074
2075                 if (dispavg) {
2076                         /* Display average values */
2077                         cprintf_f(NO_UNIT, 2, 9, 2,
2078                                   (double) avg_fan[i] / avg_count,
2079                                   (double) (avg_fan[i] - avg_fan_min[i]) / avg_count);
2080                 }
2081                 else {
2082                         /* Display instantaneous values */
2083                         cprintf_f(NO_UNIT, 2, 9, 2,
2084                                   spc->rpm,
2085                                   spc->rpm - spc->rpm_min);
2086                         avg_fan[i]     += spc->rpm;
2087                         avg_fan_min[i] += spc->rpm_min;
2088                 }
2089
2090                 cprintf_in(IS_STR, " %s\n", spc->device, 0);
2091         }
2092
2093         if (dispavg && avg_fan) {
2094                 free(avg_fan);
2095                 free(avg_fan_min);
2096                 avg_fan = NULL;
2097                 avg_fan_min = NULL;
2098                 nr_alloc = 0;
2099         }
2100 }
2101
2102 /*
2103  ***************************************************************************
2104  * Display fan statistics.
2105  *
2106  * IN:
2107  * @a           Activity structure with statistics.
2108  * @prev        Index in array where stats used as reference are.
2109  * @curr        Index in array for current sample statistics.
2110  * @itv         Interval of time in 1/100th of a second.
2111  ***************************************************************************
2112  */
2113 __print_funct_t print_pwr_fan_stats(struct activity *a, int prev, int curr,
2114                                     unsigned long long itv)
2115 {
2116         stub_print_pwr_fan_stats(a, curr, FALSE);
2117 }
2118
2119 /*
2120  ***************************************************************************
2121  * Display average fan statistics.
2122  *
2123  * IN:
2124  * @a           Activity structure with statistics.
2125  * @prev        Index in array where stats used as reference are.
2126  * @curr        Index in array for current sample statistics.
2127  * @itv         Interval of time in 1/100th of a second.
2128  ***************************************************************************
2129  */
2130 __print_funct_t print_avg_pwr_fan_stats(struct activity *a, int prev, int curr,
2131                                         unsigned long long itv)
2132 {
2133         stub_print_pwr_fan_stats(a, curr, TRUE);
2134 }
2135
2136 /*
2137  ***************************************************************************
2138  * Display device temperature statistics. This function is used to display
2139  * instantaneous and average statistics.
2140  *
2141  * IN:
2142  * @a           Activity structure with statistics.
2143  * @curr        Index in array for current sample statistics.
2144  * @dispavg     True if displaying average statistics.
2145  ***************************************************************************
2146  */
2147 void stub_print_pwr_temp_stats(struct activity *a, int curr, int dispavg)
2148 {
2149         int i;
2150         struct stats_pwr_temp *spc;
2151         static __nr_t nr_alloc = 0;
2152         static double *avg_temp = NULL;
2153         static double *avg_temp_min = NULL, *avg_temp_max = NULL;
2154
2155         /* Allocate arrays of temperatures */
2156         if (!avg_temp || (a->nr[curr] > nr_alloc)) {
2157                 SREALLOC(avg_temp, double, sizeof(double) * a->nr[curr]);
2158                 SREALLOC(avg_temp_min, double, sizeof(double) * a->nr[curr]);
2159                 SREALLOC(avg_temp_max, double, sizeof(double) * a->nr[curr]);
2160
2161                 if (a->nr[curr] > nr_alloc) {
2162                         /* Init additional space allocated */
2163                         memset(avg_temp + nr_alloc, 0,
2164                                sizeof(double) * (a->nr[curr] - nr_alloc));
2165                         memset(avg_temp_min + nr_alloc, 0,
2166                                sizeof(double) * (a->nr[curr] - nr_alloc));
2167                         memset(avg_temp_max + nr_alloc, 0,
2168                                sizeof(double) * (a->nr[curr] - nr_alloc));
2169                 }
2170                 nr_alloc = a->nr[curr];
2171         }
2172
2173         if (dis) {
2174                 print_hdr_line(timestamp[!curr], a, FIRST, -2, 9);
2175         }
2176
2177         for (i = 0; i < a->nr[curr]; i++) {
2178                 spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize);
2179
2180                 printf("%-11s", timestamp[curr]);
2181                 cprintf_in(IS_INT, "     %5d", "", i + 1);
2182
2183                 if (dispavg) {
2184                         /* Display average values */
2185                         cprintf_f(NO_UNIT, 1, 9, 2, (double) avg_temp[i] / avg_count);
2186                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2187                                    (avg_temp_max[i] - avg_temp_min[i]) ?
2188                                    ((double) (avg_temp[i] / avg_count) - avg_temp_min[i]) / (avg_temp_max[i] - avg_temp_min[i]) * 100
2189                                    : 0.0);
2190                 }
2191                 else {
2192                         /* Display instantaneous values */
2193                         cprintf_f(NO_UNIT, 1, 9, 2, spc->temp);
2194                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2195                                    (spc->temp_max - spc->temp_min) ?
2196                                    (spc->temp - spc->temp_min) / (spc->temp_max - spc->temp_min) * 100
2197                                    : 0.0);
2198                         avg_temp[i] += spc->temp;
2199                         /* Assume that min and max temperatures cannot vary */
2200                         avg_temp_min[i] = spc->temp_min;
2201                         avg_temp_max[i] = spc->temp_max;
2202                 }
2203
2204                 cprintf_in(IS_STR, " %s\n", spc->device, 0);
2205         }
2206
2207         if (dispavg && avg_temp) {
2208                 free(avg_temp);
2209                 free(avg_temp_min);
2210                 free(avg_temp_max);
2211                 avg_temp = NULL;
2212                 avg_temp_min = NULL;
2213                 avg_temp_max = NULL;
2214                 nr_alloc = 0;
2215         }
2216 }
2217
2218 /*
2219  ***************************************************************************
2220  * Display temperature statistics.
2221  *
2222  * IN:
2223  * @a           Activity structure with statistics.
2224  * @prev        Index in array where stats used as reference are.
2225  * @curr        Index in array for current sample statistics.
2226  * @itv         Interval of time in 1/100th of a second.
2227  ***************************************************************************
2228  */
2229 __print_funct_t print_pwr_temp_stats(struct activity *a, int prev, int curr,
2230                                      unsigned long long itv)
2231 {
2232         stub_print_pwr_temp_stats(a, curr, FALSE);
2233 }
2234
2235 /*
2236  ***************************************************************************
2237  * Display average temperature statistics.
2238  *
2239  * IN:
2240  * @a           Activity structure with statistics.
2241  * @prev        Index in array where stats used as reference are.
2242  * @curr        Index in array for current sample statistics.
2243  * @itv         Interval of time in 1/100th of a second.
2244  ***************************************************************************
2245  */
2246 __print_funct_t print_avg_pwr_temp_stats(struct activity *a, int prev, int curr,
2247                                          unsigned long long itv)
2248 {
2249         stub_print_pwr_temp_stats(a, curr, TRUE);
2250 }
2251
2252 /*
2253  ***************************************************************************
2254  * Display voltage inputs statistics. This function is used to display
2255  * instantaneous and average statistics.
2256  *
2257  * IN:
2258  * @a           Activity structure with statistics.
2259  * @curr        Index in array for current sample statistics.
2260  * @dispavg     True if displaying average statistics.
2261  ***************************************************************************
2262  */
2263 void stub_print_pwr_in_stats(struct activity *a, int curr, int dispavg)
2264 {
2265         int i;
2266         struct stats_pwr_in *spc;
2267         static __nr_t nr_alloc = 0;
2268         static double *avg_in = NULL;
2269         static double *avg_in_min = NULL, *avg_in_max = NULL;
2270
2271         /* Allocate arrays of voltage inputs */
2272         if (!avg_in || (a->nr[curr] > nr_alloc)) {
2273                 SREALLOC(avg_in, double, sizeof(double) * a->nr[curr]);
2274                 SREALLOC(avg_in_min, double, sizeof(double) * a->nr[curr]);
2275                 SREALLOC(avg_in_max, double, sizeof(double) * a->nr[curr]);
2276
2277                 if (a->nr[curr] > nr_alloc) {
2278                         /* Init additional space allocated */
2279                         memset(avg_in + nr_alloc, 0,
2280                                sizeof(double) * (a->nr[curr] - nr_alloc));
2281                         memset(avg_in_min + nr_alloc, 0,
2282                                sizeof(double) * (a->nr[curr] - nr_alloc));
2283                         memset(avg_in_max + nr_alloc, 0,
2284                                sizeof(double) * (a->nr[curr] - nr_alloc));
2285                 }
2286                 nr_alloc = a->nr[curr];
2287         }
2288
2289         if (dis) {
2290                 print_hdr_line(timestamp[!curr], a, FIRST, -2, 9);
2291         }
2292
2293         for (i = 0; i < a->nr[curr]; i++) {
2294                 spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize);
2295
2296                 printf("%-11s", timestamp[curr]);
2297                 cprintf_in(IS_INT, "     %5d", "", i);
2298
2299                 if (dispavg) {
2300                         /* Display average values */
2301                         cprintf_f(NO_UNIT, 1, 9, 2, (double) avg_in[i] / avg_count);
2302                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2303                                    (avg_in_max[i] - avg_in_min[i]) ?
2304                                    ((double) (avg_in[i] / avg_count) - avg_in_min[i]) / (avg_in_max[i] - avg_in_min[i]) * 100
2305                                    : 0.0);
2306                 }
2307                 else {
2308                         /* Display instantaneous values */
2309                         cprintf_f(NO_UNIT, 1, 9, 2, spc->in);
2310                         cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2311                                    (spc->in_max - spc->in_min) ?
2312                                    (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100
2313                                    : 0.0);
2314                         avg_in[i] += spc->in;
2315                         /* Assume that min and max voltage inputs cannot vary */
2316                         avg_in_min[i] = spc->in_min;
2317                         avg_in_max[i] = spc->in_max;
2318                 }
2319
2320                 cprintf_in(IS_STR, " %s\n", spc->device, 0);
2321         }
2322
2323         if (dispavg && avg_in) {
2324                 free(avg_in);
2325                 free(avg_in_min);
2326                 free(avg_in_max);
2327                 avg_in = NULL;
2328                 avg_in_min = NULL;
2329                 avg_in_max = NULL;
2330                 nr_alloc = 0;
2331         }
2332 }
2333
2334 /*
2335  ***************************************************************************
2336  * Display voltage inputs statistics.
2337  *
2338  * IN:
2339  * @a           Activity structure with statistics.
2340  * @prev        Index in array where stats used as reference are.
2341  * @curr        Index in array for current sample statistics.
2342  * @itv         Interval of time in 1/100th of a second.
2343  ***************************************************************************
2344  */
2345 __print_funct_t print_pwr_in_stats(struct activity *a, int prev, int curr,
2346                                    unsigned long long itv)
2347 {
2348         stub_print_pwr_in_stats(a, curr, FALSE);
2349 }
2350
2351 /*
2352  ***************************************************************************
2353  * Display average voltage inputs statistics.
2354  *
2355  * IN:
2356  * @a           Activity structure with statistics.
2357  * @prev        Index in array where stats used as reference are.
2358  * @curr        Index in array for current sample statistics.
2359  * @itv         Interval of time in 1/100th of a second.
2360  ***************************************************************************
2361  */
2362 __print_funct_t print_avg_pwr_in_stats(struct activity *a, int prev, int curr,
2363                                        unsigned long long itv)
2364 {
2365         stub_print_pwr_in_stats(a, curr, TRUE);
2366 }
2367
2368 /*
2369  ***************************************************************************
2370  * Display huge pages statistics. This function is used to
2371  * display instantaneous and average statistics.
2372  *
2373  * IN:
2374  * @a           Activity structure with statistics.
2375  * @curr        Index in array for current sample statistics.
2376  * @dispavg     TRUE if displaying average statistics.
2377  ***************************************************************************
2378  */
2379 void stub_print_huge_stats(struct activity *a, int curr, int dispavg)
2380 {
2381         struct stats_huge
2382                 *smc = (struct stats_huge *) a->buf[curr];
2383         static unsigned long long
2384                 avg_frhkb = 0,
2385                 avg_tlhkb = 0;
2386         int unit = NO_UNIT;
2387
2388         if (DISPLAY_UNIT(flags)) {
2389                 /* Default values unit is kB */
2390                 unit = UNIT_KILOBYTE;
2391         }
2392
2393         if (dis) {
2394                 print_hdr_line(timestamp[!curr], a, FIRST, 0, 9);
2395         }
2396
2397         if (!dispavg) {
2398                 /* Display instantaneous values */
2399                 printf("%-11s", timestamp[curr]);
2400                 cprintf_u64(unit, 2, 9,
2401                             (unsigned long long) smc->frhkb,
2402                             (unsigned long long) (smc->tlhkb - smc->frhkb));
2403                 cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2404                            smc->tlhkb ?
2405                            SP_VALUE(smc->frhkb, smc->tlhkb, smc->tlhkb) : 0.0);
2406                 printf("\n");
2407
2408                 /* Will be used to compute the average */
2409                 avg_frhkb += smc->frhkb;
2410                 avg_tlhkb += smc->tlhkb;
2411         }
2412         else {
2413                 /* Display average values */
2414                 printf("%-11s", timestamp[curr]);
2415                 cprintf_f(unit, 2, 9, 0,
2416                           (double) avg_frhkb / avg_count,
2417                           ((double) avg_tlhkb / avg_count) -
2418                           ((double) avg_frhkb / avg_count));
2419                 cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2420                            avg_tlhkb ?
2421                            SP_VALUE((double) avg_frhkb / avg_count,
2422                                     (double) avg_tlhkb / avg_count,
2423                                     (double) avg_tlhkb / avg_count) : 0.0);
2424                 printf("\n");
2425
2426                 /* Reset average counters */
2427                 avg_frhkb = avg_tlhkb = 0;
2428         }
2429 }
2430
2431 /*
2432  ***************************************************************************
2433  * Display huge pages statistics.
2434  *
2435  * IN:
2436  * @a           Activity structure with statistics.
2437  * @prev        Index in array where stats used as reference are.
2438  * @curr        Index in array for current sample statistics.
2439  * @itv         Interval of time in 1/100th of a second.
2440  ***************************************************************************
2441  */
2442 __print_funct_t print_huge_stats(struct activity *a, int prev, int curr,
2443                                  unsigned long long itv)
2444 {
2445         stub_print_huge_stats(a, curr, FALSE);
2446 }
2447
2448 /*
2449  ***************************************************************************
2450  * Display huge pages statistics.
2451  *
2452  * IN:
2453  * @a           Activity structure with statistics.
2454  * @prev        Index in array where stats used as reference are.
2455  * @curr        Index in array for current sample statistics.
2456  * @itv         Interval of time in 1/100th of a second.
2457  ***************************************************************************
2458  */
2459 __print_funct_t print_avg_huge_stats(struct activity *a, int prev, int curr,
2460                                      unsigned long long itv)
2461 {
2462         stub_print_huge_stats(a, curr, TRUE);
2463 }
2464
2465 /*
2466  ***************************************************************************
2467  * Display CPU weighted frequency statistics. This function is used to
2468  * display instantaneous and average statistics.
2469  *
2470  * IN:
2471  * @a           Activity structure with statistics.
2472  * @prev        Index in array where stats used as reference are.
2473  * @curr        Index in array for current sample statistics.
2474  * @itv         Interval of time in 1/100th of a second.
2475  ***************************************************************************
2476  */
2477 void print_pwr_wghfreq_stats(struct activity *a, int prev, int curr,
2478                              unsigned long long itv)
2479 {
2480         int i, k;
2481         struct stats_pwr_wghfreq *spc, *spp, *spc_k, *spp_k;
2482         unsigned long long tis, tisfreq;
2483
2484         if (dis) {
2485                 print_hdr_line(timestamp[!curr], a, FIRST, 7, 9);
2486         }
2487
2488         for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) {
2489
2490                 /*
2491                  * The size of a->buf[...] CPU structure may be different from the default
2492                  * sizeof(struct stats_pwr_wghfreq) value if data have been read from a file!
2493                  * That's why we don't use a syntax like:
2494                  * spc = (struct stats_pwr_wghfreq *) a->buf[...] + i;
2495                  */
2496                 spc = (struct stats_pwr_wghfreq *) ((char *) a->buf[curr] + i * a->msize * a->nr2);
2497                 spp = (struct stats_pwr_wghfreq *) ((char *) a->buf[prev] + i * a->msize * a->nr2);
2498
2499                 /*
2500                  * Note: a->nr is in [1, NR_CPUS + 1].
2501                  * Bitmap size is provided for (NR_CPUS + 1) CPUs.
2502                  * Anyway, NR_CPUS may vary between the version of sysstat
2503                  * used by sadc to create a file, and the version of sysstat
2504                  * used by sar to read it...
2505                  */
2506
2507                 /* Should current CPU (including CPU "all") be displayed? */
2508                 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
2509                         /* No */
2510                         continue;
2511
2512                 /* Yes: Display it */
2513                 printf("%-11s", timestamp[curr]);
2514
2515                 if (!i) {
2516                         /* This is CPU "all" */
2517                         cprintf_in(IS_STR, "%s", "     all", 0);
2518                 }
2519                 else {
2520                         cprintf_in(IS_INT, "     %3d", "", i - 1);
2521                 }
2522
2523                 tisfreq = 0;
2524                 tis = 0;
2525
2526                 for (k = 0; k < a->nr2; k++) {
2527
2528                         spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * a->msize);
2529                         if (!spc_k->freq)
2530                                 break;
2531                         spp_k = (struct stats_pwr_wghfreq *) ((char *) spp + k * a->msize);
2532
2533                         tisfreq += (spc_k->freq / 1000) *
2534                                    (spc_k->time_in_state - spp_k->time_in_state);
2535                         tis     += (spc_k->time_in_state - spp_k->time_in_state);
2536                 }
2537
2538                 /* Display weighted frequency for current CPU */
2539                 cprintf_f(NO_UNIT, 1, 9, 2,
2540                           tis ? ((double) tisfreq) / tis : 0.0);
2541                 printf("\n");
2542         }
2543 }
2544
2545 /*
2546  ***************************************************************************
2547  * Display USB devices statistics. This function is used to
2548  * display instantaneous and summary statistics.
2549  *
2550  * IN:
2551  * @a           Activity structure with statistics.
2552  * @curr        Index in array for current sample statistics.
2553  * @dispavg     TRUE if displaying average statistics.
2554  ***************************************************************************
2555  */
2556 void stub_print_pwr_usb_stats(struct activity *a, int curr, int dispavg)
2557 {
2558         int i, j;
2559         char fmt[16];
2560         struct stats_pwr_usb *suc, *sum;
2561
2562         if (dis) {
2563                 printf("\n%-11s     BUS  idvendor    idprod  maxpower",
2564                        (dispavg ? _("Summary:") : timestamp[!curr]));
2565                 printf(" %-*s product\n", MAX_MANUF_LEN - 1, "manufact");
2566         }
2567
2568         for (i = 0; i < a->nr[curr]; i++) {
2569                 suc = (struct stats_pwr_usb *) ((char *) a->buf[curr] + i * a->msize);
2570
2571                 printf("%-11s", (dispavg ? _("Summary:") : timestamp[curr]));
2572                 cprintf_in(IS_INT, "  %6d", "", suc->bus_nr);
2573                 cprintf_x(2, 9,
2574                           suc->vendor_id,
2575                           suc->product_id);
2576                 cprintf_u64(NO_UNIT, 1, 9,
2577                             /* bMaxPower is expressed in 2 mA units */
2578                             (unsigned long long) (suc->bmaxpower << 1));
2579
2580                 snprintf(fmt, 16, " %%-%ds", MAX_MANUF_LEN - 1);
2581                 cprintf_s(IS_STR, fmt, suc->manufacturer);
2582                 cprintf_s(IS_STR, " %s\n", suc->product);
2583
2584                 if (!dispavg) {
2585                         /* Save current USB device in summary list */
2586                         for (j = 0; j < a->nr_allocated; j++) {
2587                                 sum = (struct stats_pwr_usb *) ((char *) a->buf[2] + j * a->msize);
2588
2589                                 if ((sum->bus_nr     == suc->bus_nr) &&
2590                                     (sum->vendor_id  == suc->vendor_id) &&
2591                                     (sum->product_id == suc->product_id))
2592                                         /* USB device found in summary list */
2593                                         break;
2594                                 if (!sum->bus_nr) {
2595                                         /*
2596                                          * Current slot is free:
2597                                          * Save USB device in summary list.
2598                                          */
2599                                         *sum = *suc;
2600                                         break;
2601                                 }
2602                         }
2603                         if (j == a->nr_allocated) {
2604                                 /*
2605                                  * No free slot has been found for current device.
2606                                  * So enlarge buffers then save device in list.
2607                                  */
2608                                 reallocate_all_buffers(a);
2609                                 sum = (struct stats_pwr_usb *) ((char *) a->buf[2] + j * a->msize);
2610                                 *sum = *suc;
2611                         }
2612                 }
2613         }
2614 }
2615
2616 /*
2617  ***************************************************************************
2618  * Display USB devices statistics.
2619  *
2620  * IN:
2621  * @a           Activity structure with statistics.
2622  * @prev        Index in array where stats used as reference are.
2623  * @curr        Index in array for current sample statistics.
2624  * @itv         Interval of time in 1/100th of a second.
2625  ***************************************************************************
2626  */
2627 __print_funct_t print_pwr_usb_stats(struct activity *a, int prev, int curr,
2628                                    unsigned long long itv)
2629 {
2630         stub_print_pwr_usb_stats(a, curr, FALSE);
2631 }
2632
2633 /*
2634  ***************************************************************************
2635  * Display average USB devices statistics.
2636  *
2637  * IN:
2638  * @a           Activity structure with statistics.
2639  * @prev        Index in array where stats used as reference are.
2640  * @curr        Index in array for current sample statistics.
2641  * @itv         Interval of time in 1/100th of a second.
2642  ***************************************************************************
2643  */
2644 __print_funct_t print_avg_pwr_usb_stats(struct activity *a, int prev, int curr,
2645                                         unsigned long long itv)
2646 {
2647         stub_print_pwr_usb_stats(a, 2, TRUE);
2648 }
2649
2650 /*
2651  ***************************************************************************
2652  * Display filesystems statistics. This function is used to
2653  * display instantaneous and average statistics.
2654  *
2655  * IN:
2656  * @a           Activity structure with statistics.
2657  * @curr        Index in array for current sample statistics.
2658  * @dispavg     TRUE if displaying average statistics.
2659  ***************************************************************************
2660  */
2661 __print_funct_t stub_print_filesystem_stats(struct activity *a, int curr, int dispavg)
2662 {
2663         int i, j;
2664         struct stats_filesystem *sfc, *sfm;
2665         int unit = NO_UNIT;
2666
2667         if (DISPLAY_UNIT(flags)) {
2668                 /* Default values unit is B */
2669                 unit = UNIT_BYTE;
2670         }
2671
2672         if (dis) {
2673                 print_hdr_line((dispavg ? _("Summary:") : timestamp[!curr]),
2674                                a, FIRST + DISPLAY_MOUNT(a->opt_flags), -1, 9);
2675         }
2676
2677         for (i = 0; i < a->nr[curr]; i++) {
2678                 sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize);
2679
2680                 printf("%-11s", (dispavg ? _("Summary:") : timestamp[curr]));
2681                 cprintf_f(unit, 2, 9, 0,
2682                           unit < 0 ? (double) sfc->f_bfree / 1024 / 1024 : (double) sfc->f_bfree,
2683                           unit < 0 ? (double) (sfc->f_blocks - sfc->f_bfree) / 1024 / 1024 :
2684                                      (double) (sfc->f_blocks - sfc->f_bfree));
2685                 cprintf_pc(DISPLAY_UNIT(flags), 2, 9, 2,
2686                            /* f_blocks is not zero. But test it anyway ;-) */
2687                            sfc->f_blocks ? SP_VALUE(sfc->f_bfree, sfc->f_blocks, sfc->f_blocks)
2688                            : 0.0,
2689                            sfc->f_blocks ? SP_VALUE(sfc->f_bavail, sfc->f_blocks, sfc->f_blocks)
2690                            : 0.0);
2691                 cprintf_u64(NO_UNIT, 2, 9,
2692                             (unsigned long long) sfc->f_ffree,
2693                             (unsigned long long) (sfc->f_files - sfc->f_ffree));
2694                 cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
2695                            sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files)
2696                            : 0.0);
2697                 cprintf_in(IS_STR, " %s\n",
2698                            DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name, 0);
2699
2700                 if (!dispavg) {
2701                         /* Save current filesystem in summary list */
2702                         for (j = 0; j < a->nr_allocated; j++) {
2703                                 sfm = (struct stats_filesystem *) ((char *) a->buf[2] + j * a->msize);
2704
2705                                 if (!strcmp(sfm->fs_name, sfc->fs_name) ||
2706                                     !sfm->f_blocks) {
2707                                         /*
2708                                          * Filesystem found in list (then save again its stats)
2709                                          * or free slot (end of list).
2710                                          */
2711                                         *sfm = *sfc;
2712                                         break;
2713                                 }
2714                         }
2715                         if (j == a->nr_allocated) {
2716                                 /*
2717                                  * No free slot has been found for current filesystem.
2718                                  * So enlarge buffers then save filesystem in list.
2719                                  */
2720                                 reallocate_all_buffers(a);
2721                                 sfm = (struct stats_filesystem *) ((char *) a->buf[2] + j * a->msize);
2722                                 *sfm = *sfc;
2723                         }
2724                 }
2725         }
2726 }
2727
2728 /*
2729  ***************************************************************************
2730  * Display filesystems statistics.
2731  *
2732  * IN:
2733  * @a           Activity structure with statistics.
2734  * @prev        Index in array where stats used as reference are.
2735  * @curr        Index in array for current sample statistics.
2736  * @itv         Interval of time in 1/100th of a second.
2737  ***************************************************************************
2738  */
2739 __print_funct_t print_filesystem_stats(struct activity *a, int prev, int curr,
2740                                        unsigned long long itv)
2741 {
2742         stub_print_filesystem_stats(a, curr, FALSE);
2743 }
2744
2745 /*
2746  ***************************************************************************
2747  * Display average filesystems statistics.
2748  *
2749  * IN:
2750  * @a           Activity structure with statistics.
2751  * @prev        Index in array where stats used as reference are.
2752  * @curr        Index in array for current sample statistics.
2753  * @itv         Interval of time in 1/100th of a second.
2754  ***************************************************************************
2755  */
2756 __print_funct_t print_avg_filesystem_stats(struct activity *a, int prev, int curr,
2757                                            unsigned long long itv)
2758 {
2759         stub_print_filesystem_stats(a, 2, TRUE);
2760 }
2761
2762 /*
2763  ***************************************************************************
2764  * Display Fibre Channel HBA statistics.
2765  *
2766  * IN:
2767  * @a           Activity structure with statistics.
2768  * @prev        Index in array where stats used as reference are.
2769  * @curr        Index in array for current sample statistics.
2770  * @itv         Interval of time in 1/100th of a second.
2771  ***************************************************************************
2772  */
2773 __print_funct_t print_fchost_stats(struct activity *a, int prev, int curr,
2774                                    unsigned long long itv)
2775 {
2776         int i, j, j0, found;
2777         struct stats_fchost *sfcc,*sfcp;
2778
2779         if (dis) {
2780                 print_hdr_line(timestamp[!curr], a, FIRST, -1, 9);
2781         }
2782
2783         for (i = 0; i < a->nr[curr]; i++) {
2784
2785                 sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
2786
2787                 /* Look for corresponding structure in previous iteration */
2788                 j = i;
2789                 if (j > a->nr[prev]) {
2790                         j = a->nr[prev];
2791                 }
2792
2793                 j0 = j;
2794                 found = FALSE;
2795
2796                 do {
2797                         if (j > a->nr[prev]) {
2798                                 j = 0;
2799                         }
2800                         sfcp = (struct stats_fchost *) ((char *) a->buf[prev] + j * a->msize);
2801                         if (!strcmp(sfcc->fchost_name, sfcp->fchost_name)) {
2802                                 found = TRUE;
2803                                 break;
2804                         }
2805                         j++;
2806                 }
2807                 while (j != j0);
2808
2809                 if (!found)
2810                         continue;
2811
2812                 printf("%-11s", timestamp[curr]);
2813                 cprintf_f(NO_UNIT, 4, 9, 2,
2814                           S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv),
2815                           S_VALUE(sfcp->f_txframes, sfcc->f_txframes, itv),
2816                           S_VALUE(sfcp->f_rxwords,  sfcc->f_rxwords,  itv),
2817                           S_VALUE(sfcp->f_txwords,  sfcc->f_txwords,  itv));
2818                 cprintf_in(IS_STR, " %s\n", sfcc->fchost_name, 0);
2819         }
2820 }
2821
2822 /*
2823  ***************************************************************************
2824  * Display softnet statistics.
2825  *
2826  * IN:
2827  * @a           Activity structure with statistics.
2828  * @prev        Index in array where stats used as reference are.
2829  * @curr        Index in array for current sample statistics.
2830  * @itv         Interval of time in 1/100th of a second.
2831  ***************************************************************************
2832  */
2833 __print_funct_t print_softnet_stats(struct activity *a, int prev, int curr,
2834                                     unsigned long long itv)
2835 {
2836         struct stats_softnet
2837                 *ssnc = (struct stats_softnet *) a->buf[curr],
2838                 *ssnp = (struct stats_softnet *) a->buf[prev];
2839         int i;
2840
2841         if (dis) {
2842                 print_hdr_line(timestamp[!curr], a, FIRST, 7, 9);
2843         }
2844
2845         for (i = 0; (i < a->nr[curr]) && (i < a->bitmap->b_size + 1); i++) {
2846
2847                 /*
2848                  * The size of a->buf[...] CPU structure may be different from the default
2849                  * sizeof(struct stats_pwr_cpufreq) value if data have been read from a file!
2850                  * That's why we don't use a syntax like:
2851                  * ssnc = (struct stats_softnet *) a->buf[...] + i;
2852                  */
2853                 ssnc = (struct stats_softnet *) ((char *) a->buf[curr] + i * a->msize);
2854                 ssnp = (struct stats_softnet *) ((char *) a->buf[prev] + i * a->msize);
2855
2856                 /*
2857                  * Note: a->nr is in [1, NR_CPUS + 1].
2858                  * Bitmap size is provided for (NR_CPUS + 1) CPUs.
2859                  * Anyway, NR_CPUS may vary between the version of sysstat
2860                  * used by sadc to create a file, and the version of sysstat
2861                  * used by sar to read it...
2862                  */
2863
2864                 /* Should current CPU (including CPU "all") be displayed? */
2865                 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
2866                         /* No */
2867                         continue;
2868
2869                 printf("%-11s", timestamp[curr]);
2870
2871                 if (!i) {
2872                         /* This is CPU "all" */
2873                         cprintf_in(IS_STR, " %s", "    all", 0);
2874                 }
2875                 else {
2876                         cprintf_in(IS_INT, " %7d", "", i - 1);
2877                 }
2878
2879                 cprintf_f(NO_UNIT, 5, 9, 2,
2880                           S_VALUE(ssnp->processed,    ssnc->processed,    itv),
2881                           S_VALUE(ssnp->dropped,      ssnc->dropped,      itv),
2882                           S_VALUE(ssnp->time_squeeze, ssnc->time_squeeze, itv),
2883                           S_VALUE(ssnp->received_rps, ssnc->received_rps, itv),
2884                           S_VALUE(ssnp->flow_limit,   ssnc->flow_limit,   itv));
2885                 printf("\n");
2886         }
2887 }