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