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