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