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