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