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