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