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