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