]> granicus.if.org Git - sysstat/blob - json_stats.c
sar: Add softnet statistics (part 1): Basic definitions and structures
[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                  /*
439                   * If we get negative values, this is probably because
440                   * one or more devices/filesystems have been unmounted.
441                   * We display 0.0 in this case though we should rather tell
442                   * the user that the value cannot be calculated here.
443                   */
444                  sic->dk_drive < sip->dk_drive ? 0.0 :
445                  S_VALUE(sip->dk_drive, sic->dk_drive, itv),
446                  sic->dk_drive_rio < sip->dk_drive_rio ? 0.0 :
447                  S_VALUE(sip->dk_drive_rio, sic->dk_drive_rio, itv),
448                  sic->dk_drive_rblk < sip->dk_drive_rblk ? 0.0 :
449                  S_VALUE(sip->dk_drive_rblk, sic->dk_drive_rblk, itv),
450                  sic->dk_drive_wio < sip->dk_drive_wio ? 0.0 :
451                  S_VALUE(sip->dk_drive_wio, sic->dk_drive_wio, itv),
452                  sic->dk_drive_wblk < sip->dk_drive_wblk ? 0.0 :
453                  S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv));
454 }
455
456 /*
457  ***************************************************************************
458  * Display memory statistics in JSON.
459  *
460  * IN:
461  * @a           Activity structure with statistics.
462  * @curr        Index in array for current sample statistics.
463  * @tab         Indentation in output.
464  * @itv         Interval of time in jiffies.
465  ***************************************************************************
466  */
467 __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab,
468                                         unsigned long long itv)
469 {
470         struct stats_memory
471                 *smc = (struct stats_memory *) a->buf[curr],
472                 *smp = (struct stats_memory *) a->buf[!curr];
473         int sep = FALSE;
474
475         xprintf0(tab, "\"memory\": {");
476
477         if (DISPLAY_MEM_AMT(a->opt_flags)) {
478
479                 sep = TRUE;
480
481                 printf("\"memfree\": %lu, "
482                        "\"memused\": %lu, "
483                        "\"memused-percent\": %.2f, "
484                        "\"buffers\": %lu, "
485                        "\"cached\": %lu, "
486                        "\"commit\": %lu, "
487                        "\"commit-percent\": %.2f, "
488                        "\"active\": %lu, "
489                        "\"inactive\": %lu, "
490                        "\"dirty\": %lu",
491                        smc->frmkb,
492                        smc->tlmkb - smc->frmkb,
493                        smc->tlmkb ?
494                        SP_VALUE(smc->frmkb, smc->tlmkb, smc->tlmkb) :
495                        0.0,
496                        smc->bufkb,
497                        smc->camkb,
498                        smc->comkb,
499                        (smc->tlmkb + smc->tlskb) ?
500                        SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) :
501                        0.0,
502                        smc->activekb,
503                        smc->inactkb,
504                        smc->dirtykb);
505
506                 if (DISPLAY_MEM_ALL(a->opt_flags)) {
507                         /* Display extended memory stats */
508                         printf(", \"anonpg\": %lu, "
509                                "\"slab\": %lu, "
510                                "\"kstack\": %lu, "
511                                "\"pgtbl\": %lu, "
512                                "\"vmused\": %lu",
513                                smc->anonpgkb,
514                                smc->slabkb,
515                                smc->kstackkb,
516                                smc->pgtblkb,
517                                smc->vmusedkb);
518                 }
519         }
520
521         if (DISPLAY_SWAP(a->opt_flags)) {
522
523                 if (sep) {
524                         printf(", ");
525                 }
526                 sep = TRUE;
527
528                 printf("\"swpfree\": %lu, "
529                        "\"swpused\": %lu, "
530                        "\"swpused-percent\": %.2f, "
531                        "\"swpcad\": %lu, "
532                        "\"swpcad-percent\": %.2f",
533                        smc->frskb,
534                        smc->tlskb - smc->frskb,
535                        smc->tlskb ?
536                        SP_VALUE(smc->frskb, smc->tlskb, smc->tlskb) :
537                        0.0,
538                        smc->caskb,
539                        (smc->tlskb - smc->frskb) ?
540                        SP_VALUE(0, smc->caskb, smc->tlskb - smc->frskb) :
541                        0.0);
542         }
543
544         if (DISPLAY_MEMORY(a->opt_flags)) {
545
546                 if (sep) {
547                         printf(", ");
548                 }
549
550                 printf("\"frmpg\": %.2f, "
551                        "\"bufpg\": %.2f, "
552                        "\"campg\": %.2f",
553                        S_VALUE((double) KB_TO_PG(smp->frmkb),
554                                (double) KB_TO_PG(smc->frmkb), itv),
555                        S_VALUE((double) KB_TO_PG(smp->bufkb),
556                                (double) KB_TO_PG(smc->bufkb), itv),
557                        S_VALUE((double) KB_TO_PG(smp->camkb),
558                                (double) KB_TO_PG(smc->camkb), itv));
559         }
560
561         printf("}");
562 }
563
564 /*
565  ***************************************************************************
566  * Display kernel tables statistics in JSON.
567  *
568  * IN:
569  * @a           Activity structure with statistics.
570  * @curr        Index in array for current sample statistics.
571  * @tab         Indentation in output.
572  * @itv         Interval of time in jiffies.
573  ***************************************************************************
574  */
575 __print_funct_t json_print_ktables_stats(struct activity *a, int curr, int tab,
576                                          unsigned long long itv)
577 {
578         struct stats_ktables
579                 *skc = (struct stats_ktables *) a->buf[curr];
580
581         xprintf0(tab, "\"kernel\": {"
582                  "\"dentunusd\": %u, "
583                  "\"file-nr\": %u, "
584                  "\"inode-nr\": %u, "
585                  "\"pty-nr\": %u}",
586                  skc->dentry_stat,
587                  skc->file_used,
588                  skc->inode_used,
589                  skc->pty_nr);
590 }
591
592 /*
593  ***************************************************************************
594  * Display queue and load statistics in JSON.
595  *
596  * IN:
597  * @a           Activity structure with statistics.
598  * @curr        Index in array for current sample statistics.
599  * @tab         Indentation in output.
600  * @itv         Interval of time in jiffies.
601  ***************************************************************************
602  */
603 __print_funct_t json_print_queue_stats(struct activity *a, int curr, int tab,
604                                        unsigned long long itv)
605 {
606         struct stats_queue
607                 *sqc = (struct stats_queue *) a->buf[curr];
608
609         xprintf0(tab, "\"queue\": {"
610                  "\"runq-sz\": %lu, "
611                  "\"plist-sz\": %u, "
612                  "\"ldavg-1\": %.2f, "
613                  "\"ldavg-5\": %.2f, "
614                  "\"ldavg-15\": %.2f, "
615                  "\"blocked\": %lu}",
616                  sqc->nr_running,
617                  sqc->nr_threads,
618                  (double) sqc->load_avg_1 / 100,
619                  (double) sqc->load_avg_5 / 100,
620                  (double) sqc->load_avg_15 / 100,
621                  sqc->procs_blocked);
622 }
623
624 /*
625  ***************************************************************************
626  * Display serial lines statistics in JSON.
627  *
628  * IN:
629  * @a           Activity structure with statistics.
630  * @curr        Index in array for current sample statistics.
631  * @tab         Indentation in output.
632  * @itv         Interval of time in jiffies.
633  ***************************************************************************
634  */
635 __print_funct_t json_print_serial_stats(struct activity *a, int curr, int tab,
636                                         unsigned long long itv)
637 {
638         int i;
639         struct stats_serial *ssc, *ssp;
640         int sep = FALSE;
641
642         xprintf(tab++, "\"serial\": [");
643
644         for (i = 0; i < a->nr; i++) {
645
646                 ssc = (struct stats_serial *) ((char *) a->buf[curr]  + i * a->msize);
647                 ssp = (struct stats_serial *) ((char *) a->buf[!curr] + i * a->msize);
648
649                 if (ssc->line == 0)
650                         continue;
651
652                 if (ssc->line == ssp->line) {
653
654                         if (sep) {
655                                 printf(",\n");
656                         }
657                         sep = TRUE;
658
659                         xprintf0(tab, "{\"line\": %d, "
660                                  "\"rcvin\": %.2f, "
661                                  "\"xmtin\": %.2f, "
662                                  "\"framerr\": %.2f, "
663                                  "\"prtyerr\": %.2f, "
664                                  "\"brk\": %.2f, "
665                                  "\"ovrun\": %.2f}",
666                                  ssc->line - 1,
667                                  S_VALUE(ssp->rx,      ssc->rx,      itv),
668                                  S_VALUE(ssp->tx,      ssc->tx,      itv),
669                                  S_VALUE(ssp->frame,   ssc->frame,   itv),
670                                  S_VALUE(ssp->parity,  ssc->parity,  itv),
671                                  S_VALUE(ssp->brk,     ssc->brk,     itv),
672                                  S_VALUE(ssp->overrun, ssc->overrun, itv));
673                 }
674         }
675
676         printf("\n");
677         xprintf0(--tab, "]");
678 }
679
680 /*
681  ***************************************************************************
682  * Display disks statistics in JSON.
683  *
684  * IN:
685  * @a           Activity structure with statistics.
686  * @curr        Index in array for current sample statistics.
687  * @tab         Indentation in output.
688  * @itv         Interval of time in jiffies.
689  ***************************************************************************
690  */
691 __print_funct_t json_print_disk_stats(struct activity *a, int curr, int tab,
692                                       unsigned long long itv)
693 {
694         int i, j;
695         struct stats_disk *sdc, *sdp;
696         struct ext_disk_stats xds;
697         int sep = FALSE;
698         char *dev_name, *persist_dev_name;
699
700         xprintf(tab++, "\"disk\": [");
701
702         for (i = 0; i < a->nr; i++) {
703
704                 sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
705
706                 if (!(sdc->major + sdc->minor))
707                         continue;
708
709                 j = check_disk_reg(a, curr, !curr, i);
710                 sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize);
711
712                 /* Compute extended statistics values */
713                 compute_ext_disk_stats(sdc, sdp, itv, &xds);
714
715                 dev_name = NULL;
716                 persist_dev_name = NULL;
717
718                 if (DISPLAY_PERSIST_NAME_S(flags)) {
719                         persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
720                 }
721
722                 if (persist_dev_name) {
723                         dev_name = persist_dev_name;
724                 }
725                 else {
726                         if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
727                                 dev_name = transform_devmapname(sdc->major, sdc->minor);
728                         }
729
730                         if (!dev_name) {
731                                 dev_name = get_devname(sdc->major, sdc->minor,
732                                                        USE_PRETTY_OPTION(flags));
733                         }
734                 }
735
736                 if (sep) {
737                         printf(",\n");
738                 }
739                 sep = TRUE;
740
741                 xprintf0(tab, "{\"disk-device\": \"%s\", "
742                          "\"tps\": %.2f, "
743                          "\"rd_sec\": %.2f, "
744                          "\"wr_sec\": %.2f, "
745                          "\"avgrq-sz\": %.2f, "
746                          "\"avgqu-sz\": %.2f, "
747                          "\"await\": %.2f, "
748                          "\"svctm\": %.2f, "
749                          "\"util-percent\": %.2f}",
750                          /* Confusion possible here between index and minor numbers */
751                          dev_name,
752                          S_VALUE(sdp->nr_ios, sdc->nr_ios, itv),
753                          S_VALUE(sdp->rd_sect, sdc->rd_sect, itv),
754                          S_VALUE(sdp->wr_sect, sdc->wr_sect, itv),
755                          /* See iostat for explanations */
756                          xds.arqsz,
757                          S_VALUE(sdp->rq_ticks, sdc->rq_ticks, itv) / 1000.0,
758                          xds.await,
759                          xds.svctm,
760                          xds.util / 10.0);
761         }
762
763         printf("\n");
764         xprintf0(--tab, "]");
765 }
766
767 /*
768  ***************************************************************************
769  * Display network interfaces statistics in JSON.
770  *
771  * IN:
772  * @a           Activity structure with statistics.
773  * @curr        Index in array for current sample statistics.
774  * @tab         Indentation in output.
775  * @itv         Interval of time in jiffies.
776  ***************************************************************************
777  */
778 __print_funct_t json_print_net_dev_stats(struct activity *a, int curr, int tab,
779                                          unsigned long long itv)
780 {
781         int i, j;
782         struct stats_net_dev *sndc, *sndp;
783         int sep = FALSE;
784         double rxkb, txkb, ifutil;
785
786         if (!IS_SELECTED(a->options) || (a->nr <= 0))
787                 goto close_json_markup;
788
789         json_markup_network(tab, OPEN_JSON_MARKUP);
790         tab++;
791
792         xprintf(tab++, "\"net-dev\": [");
793
794         for (i = 0; i < a->nr; i++) {
795
796                 sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
797
798                 if (!strcmp(sndc->interface, ""))
799                         continue;
800
801                 j = check_net_dev_reg(a, curr, !curr, i);
802                 sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
803
804                 if (sep) {
805                         printf(",\n");
806                 }
807                 sep = TRUE;
808
809                 rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
810                 txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
811                 ifutil = compute_ifutil(sndc, rxkb, txkb);
812
813                 xprintf0(tab, "{\"iface\": \"%s\", "
814                          "\"rxpck\": %.2f, "
815                          "\"txpck\": %.2f, "
816                          "\"rxkB\": %.2f, "
817                          "\"txkB\": %.2f, "
818                          "\"rxcmp\": %.2f, "
819                          "\"txcmp\": %.2f, "
820                          "\"rxmcst\": %.2f, "
821                          "\"ifutil-percent\": %.2f}",
822                          sndc->interface,
823                          S_VALUE(sndp->rx_packets,    sndc->rx_packets,    itv),
824                          S_VALUE(sndp->tx_packets,    sndc->tx_packets,    itv),
825                          rxkb / 1024,
826                          txkb / 1024,
827                          S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv),
828                          S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv),
829                          S_VALUE(sndp->multicast,     sndc->multicast,     itv),
830                          ifutil);
831         }
832
833         printf("\n");
834         xprintf0(--tab, "]");
835
836         tab--;
837
838 close_json_markup:
839         if (CLOSE_MARKUP(a->options)) {
840                 json_markup_network(tab, CLOSE_JSON_MARKUP);
841         }
842 }
843
844 /*
845  ***************************************************************************
846  * Display network interfaces errors statistics in JSON.
847  *
848  * IN:
849  * @a           Activity structure with statistics.
850  * @curr        Index in array for current sample statistics.
851  * @tab         Indentation in output.
852  * @itv         Interval of time in jiffies.
853  ***************************************************************************
854  */
855 __print_funct_t json_print_net_edev_stats(struct activity *a, int curr, int tab,
856                                           unsigned long long itv)
857 {
858         int i, j;
859         struct stats_net_edev *snedc, *snedp;
860         int sep = FALSE;
861
862         if (!IS_SELECTED(a->options) || (a->nr <= 0))
863                 goto close_json_markup;
864
865         json_markup_network(tab, OPEN_JSON_MARKUP);
866         tab++;
867
868         xprintf(tab++, "\"net-edev\": [");
869
870         for (i = 0; i < a->nr; i++) {
871
872                 snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize);
873
874                 if (!strcmp(snedc->interface, ""))
875                         continue;
876
877                 j = check_net_edev_reg(a, curr, !curr, i);
878                 snedp = (struct stats_net_edev *) ((char *) a->buf[!curr] + j * a->msize);
879
880                 if (sep) {
881                         printf(",\n");
882                 }
883                 sep = TRUE;
884
885                 xprintf0(tab, "{\"iface\": \"%s\", "
886                          "\"rxerr\": %.2f, "
887                          "\"txerr\": %.2f, "
888                          "\"coll\": %.2f, "
889                          "\"rxdrop\": %.2f, "
890                          "\"txdrop\": %.2f, "
891                          "\"txcarr\": %.2f, "
892                          "\"rxfram\": %.2f, "
893                          "\"rxfifo\": %.2f, "
894                          "\"txfifo\": %.2f}",
895                          snedc->interface,
896                          S_VALUE(snedp->rx_errors,         snedc->rx_errors,         itv),
897                          S_VALUE(snedp->tx_errors,         snedc->tx_errors,         itv),
898                          S_VALUE(snedp->collisions,        snedc->collisions,        itv),
899                          S_VALUE(snedp->rx_dropped,        snedc->rx_dropped,        itv),
900                          S_VALUE(snedp->tx_dropped,        snedc->tx_dropped,        itv),
901                          S_VALUE(snedp->tx_carrier_errors, snedc->tx_carrier_errors, itv),
902                          S_VALUE(snedp->rx_frame_errors,   snedc->rx_frame_errors,   itv),
903                          S_VALUE(snedp->rx_fifo_errors,    snedc->rx_fifo_errors,    itv),
904                          S_VALUE(snedp->tx_fifo_errors,    snedc->tx_fifo_errors,    itv));
905         }
906
907         printf("\n");
908         xprintf0(--tab, "]");
909
910         tab--;
911
912 close_json_markup:
913         if (CLOSE_MARKUP(a->options)) {
914                 json_markup_network(tab, CLOSE_JSON_MARKUP);
915         }
916 }
917
918 /*
919  ***************************************************************************
920  * Display NFS client statistics in JSON.
921  *
922  * IN:
923  * @a           Activity structure with statistics.
924  * @curr        Index in array for current sample statistics.
925  * @tab         Indentation in output.
926  * @itv         Interval of time in jiffies.
927  ***************************************************************************
928  */
929 __print_funct_t json_print_net_nfs_stats(struct activity *a, int curr, int tab,
930                                          unsigned long long itv)
931 {
932         struct stats_net_nfs
933                 *snnc = (struct stats_net_nfs *) a->buf[curr],
934                 *snnp = (struct stats_net_nfs *) a->buf[!curr];
935
936         if (!IS_SELECTED(a->options) || (a->nr <= 0))
937                 goto close_json_markup;
938
939         json_markup_network(tab, OPEN_JSON_MARKUP);
940         tab++;
941
942         xprintf0(tab, "\"net-nfs\": {"
943                  "\"call\": %.2f, "
944                  "\"retrans\": %.2f, "
945                  "\"read\": %.2f, "
946                  "\"write\": %.2f, "
947                  "\"access\": %.2f, "
948                  "\"getatt\": %.2f}",
949                  S_VALUE(snnp->nfs_rpccnt,     snnc->nfs_rpccnt,     itv),
950                  S_VALUE(snnp->nfs_rpcretrans, snnc->nfs_rpcretrans, itv),
951                  S_VALUE(snnp->nfs_readcnt,    snnc->nfs_readcnt,    itv),
952                  S_VALUE(snnp->nfs_writecnt,   snnc->nfs_writecnt,   itv),
953                  S_VALUE(snnp->nfs_accesscnt,  snnc->nfs_accesscnt,  itv),
954                  S_VALUE(snnp->nfs_getattcnt,  snnc->nfs_getattcnt,  itv));
955         tab--;
956
957 close_json_markup:
958         if (CLOSE_MARKUP(a->options)) {
959                 json_markup_network(tab, CLOSE_JSON_MARKUP);
960         }
961 }
962
963 /*
964  ***************************************************************************
965  * Display NFS server statistics in JSON.
966  *
967  * IN:
968  * @a           Activity structure with statistics.
969  * @curr        Index in array for current sample statistics.
970  * @tab         Indentation in output.
971  * @itv         Interval of time in jiffies.
972  ***************************************************************************
973  */
974 __print_funct_t json_print_net_nfsd_stats(struct activity *a, int curr, int tab,
975                                           unsigned long long itv)
976 {
977         struct stats_net_nfsd
978                 *snndc = (struct stats_net_nfsd *) a->buf[curr],
979                 *snndp = (struct stats_net_nfsd *) a->buf[!curr];
980
981         if (!IS_SELECTED(a->options) || (a->nr <= 0))
982                 goto close_json_markup;
983
984         json_markup_network(tab, OPEN_JSON_MARKUP);
985         tab++;
986
987         xprintf0(tab, "\"net-nfsd\": {"
988                  "\"scall\": %.2f, "
989                  "\"badcall\": %.2f, "
990                  "\"packet\": %.2f, "
991                  "\"udp\": %.2f, "
992                  "\"tcp\": %.2f, "
993                  "\"hit\": %.2f, "
994                  "\"miss\": %.2f, "
995                  "\"sread\": %.2f, "
996                  "\"swrite\": %.2f, "
997                  "\"saccess\": %.2f, "
998                  "\"sgetatt\": %.2f}",
999                  S_VALUE(snndp->nfsd_rpccnt,    snndc->nfsd_rpccnt,    itv),
1000                  S_VALUE(snndp->nfsd_rpcbad,    snndc->nfsd_rpcbad,    itv),
1001                  S_VALUE(snndp->nfsd_netcnt,    snndc->nfsd_netcnt,    itv),
1002                  S_VALUE(snndp->nfsd_netudpcnt, snndc->nfsd_netudpcnt, itv),
1003                  S_VALUE(snndp->nfsd_nettcpcnt, snndc->nfsd_nettcpcnt, itv),
1004                  S_VALUE(snndp->nfsd_rchits,    snndc->nfsd_rchits,    itv),
1005                  S_VALUE(snndp->nfsd_rcmisses,  snndc->nfsd_rcmisses,  itv),
1006                  S_VALUE(snndp->nfsd_readcnt,   snndc->nfsd_readcnt,   itv),
1007                  S_VALUE(snndp->nfsd_writecnt,  snndc->nfsd_writecnt,  itv),
1008                  S_VALUE(snndp->nfsd_accesscnt, snndc->nfsd_accesscnt, itv),
1009                  S_VALUE(snndp->nfsd_getattcnt, snndc->nfsd_getattcnt, itv));
1010         tab--;
1011
1012 close_json_markup:
1013         if (CLOSE_MARKUP(a->options)) {
1014                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1015         }
1016 }
1017
1018 /*
1019  ***************************************************************************
1020  * Display network socket statistics in JSON.
1021  *
1022  * IN:
1023  * @a           Activity structure with statistics.
1024  * @curr        Index in array for current sample statistics.
1025  * @tab         Indentation in output.
1026  * @itv         Interval of time in jiffies.
1027  ***************************************************************************
1028  */
1029 __print_funct_t json_print_net_sock_stats(struct activity *a, int curr, int tab,
1030                                           unsigned long long itv)
1031 {
1032         struct stats_net_sock
1033                 *snsc = (struct stats_net_sock *) a->buf[curr];
1034
1035         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1036                 goto close_json_markup;
1037
1038         json_markup_network(tab, OPEN_JSON_MARKUP);
1039         tab++;
1040
1041         xprintf0(tab, "\"net-sock\": {"
1042                  "\"totsck\": %u, "
1043                  "\"tcpsck\": %u, "
1044                  "\"udpsck\": %u, "
1045                  "\"rawsck\": %u, "
1046                  "\"ip-frag\": %u, "
1047                  "\"tcp-tw\": %u}",
1048                  snsc->sock_inuse,
1049                  snsc->tcp_inuse,
1050                  snsc->udp_inuse,
1051                  snsc->raw_inuse,
1052                  snsc->frag_inuse,
1053                  snsc->tcp_tw);
1054         tab--;
1055
1056 close_json_markup:
1057         if (CLOSE_MARKUP(a->options)) {
1058                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1059         }
1060 }
1061
1062 /*
1063  ***************************************************************************
1064  * Display IP network statistics in JSON.
1065  *
1066  * IN:
1067  * @a           Activity structure with statistics.
1068  * @curr        Index in array for current sample statistics.
1069  * @tab         Indentation in output.
1070  * @itv         Interval of time in jiffies.
1071  ***************************************************************************
1072  */
1073 __print_funct_t json_print_net_ip_stats(struct activity *a, int curr, int tab,
1074                                         unsigned long long itv)
1075 {
1076         struct stats_net_ip
1077                 *snic = (struct stats_net_ip *) a->buf[curr],
1078                 *snip = (struct stats_net_ip *) a->buf[!curr];
1079
1080         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1081                 goto close_json_markup;
1082
1083         json_markup_network(tab, OPEN_JSON_MARKUP);
1084         tab++;
1085
1086         xprintf0(tab, "\"net-ip\": {"
1087                  "\"irec\": %.2f, "
1088                  "\"fwddgm\": %.2f, "
1089                  "\"idel\": %.2f, "
1090                  "\"orq\": %.2f, "
1091                  "\"asmrq\": %.2f, "
1092                  "\"asmok\": %.2f, "
1093                  "\"fragok\": %.2f, "
1094                  "\"fragcrt\": %.2f}",
1095                  S_VALUE(snip->InReceives,    snic->InReceives,    itv),
1096                  S_VALUE(snip->ForwDatagrams, snic->ForwDatagrams, itv),
1097                  S_VALUE(snip->InDelivers,    snic->InDelivers,    itv),
1098                  S_VALUE(snip->OutRequests,   snic->OutRequests,   itv),
1099                  S_VALUE(snip->ReasmReqds,    snic->ReasmReqds,    itv),
1100                  S_VALUE(snip->ReasmOKs,      snic->ReasmOKs,      itv),
1101                  S_VALUE(snip->FragOKs,       snic->FragOKs,       itv),
1102                  S_VALUE(snip->FragCreates,   snic->FragCreates,   itv));
1103         tab--;
1104
1105 close_json_markup:
1106         if (CLOSE_MARKUP(a->options)) {
1107                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1108         }
1109 }
1110
1111 /*
1112  ***************************************************************************
1113  * Display IP network errors statistics in JSON.
1114  *
1115  * IN:
1116  * @a           Activity structure with statistics.
1117  * @curr        Index in array for current sample statistics.
1118  * @tab         Indentation in output.
1119  * @itv         Interval of time in jiffies.
1120  ***************************************************************************
1121  */
1122 __print_funct_t json_print_net_eip_stats(struct activity *a, int curr, int tab,
1123                                          unsigned long long itv)
1124 {
1125         struct stats_net_eip
1126                 *sneic = (struct stats_net_eip *) a->buf[curr],
1127                 *sneip = (struct stats_net_eip *) a->buf[!curr];
1128
1129         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1130                 goto close_json_markup;
1131
1132         json_markup_network(tab, OPEN_JSON_MARKUP);
1133         tab++;
1134
1135         xprintf0(tab, "\"net-eip\": {"
1136                  "\"ihdrerr\": %.2f, "
1137                  "\"iadrerr\": %.2f, "
1138                  "\"iukwnpr\": %.2f, "
1139                  "\"idisc\": %.2f, "
1140                  "\"odisc\": %.2f, "
1141                  "\"onort\": %.2f, "
1142                  "\"asmf\": %.2f, "
1143                  "\"fragf\": %.2f}",
1144                  S_VALUE(sneip->InHdrErrors,     sneic->InHdrErrors,     itv),
1145                  S_VALUE(sneip->InAddrErrors,    sneic->InAddrErrors,    itv),
1146                  S_VALUE(sneip->InUnknownProtos, sneic->InUnknownProtos, itv),
1147                  S_VALUE(sneip->InDiscards,      sneic->InDiscards,      itv),
1148                  S_VALUE(sneip->OutDiscards,     sneic->OutDiscards,     itv),
1149                  S_VALUE(sneip->OutNoRoutes,     sneic->OutNoRoutes,     itv),
1150                  S_VALUE(sneip->ReasmFails,      sneic->ReasmFails,      itv),
1151                  S_VALUE(sneip->FragFails,       sneic->FragFails,       itv));
1152         tab--;
1153
1154 close_json_markup:
1155         if (CLOSE_MARKUP(a->options)) {
1156                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1157         }
1158 }
1159
1160 /*
1161  ***************************************************************************
1162  * Display ICMP network statistics in JSON.
1163  *
1164  * IN:
1165  * @a           Activity structure with statistics.
1166  * @curr        Index in array for current sample statistics.
1167  * @tab         Indentation in output.
1168  * @itv         Interval of time in jiffies.
1169  ***************************************************************************
1170  */
1171 __print_funct_t json_print_net_icmp_stats(struct activity *a, int curr, int tab,
1172                                           unsigned long long itv)
1173 {
1174         struct stats_net_icmp
1175                 *snic = (struct stats_net_icmp *) a->buf[curr],
1176                 *snip = (struct stats_net_icmp *) a->buf[!curr];
1177
1178         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1179                 goto close_json_markup;
1180
1181         json_markup_network(tab, OPEN_JSON_MARKUP);
1182         tab++;
1183
1184         xprintf0(tab, "\"net-icmp\": {"
1185                  "\"imsg\": %.2f, "
1186                  "\"omsg\": %.2f, "
1187                  "\"iech\": %.2f, "
1188                  "\"iechr\": %.2f, "
1189                  "\"oech\": %.2f, "
1190                  "\"oechr\": %.2f, "
1191                  "\"itm\": %.2f, "
1192                  "\"itmr\": %.2f, "
1193                  "\"otm\": %.2f, "
1194                  "\"otmr\": %.2f, "
1195                  "\"iadrmk\": %.2f, "
1196                  "\"iadrmkr\": %.2f, "
1197                  "\"oadrmk\": %.2f, "
1198                  "\"oadrmkr\": %.2f}",
1199                  S_VALUE(snip->InMsgs,           snic->InMsgs,           itv),
1200                  S_VALUE(snip->OutMsgs,          snic->OutMsgs,          itv),
1201                  S_VALUE(snip->InEchos,          snic->InEchos,          itv),
1202                  S_VALUE(snip->InEchoReps,       snic->InEchoReps,       itv),
1203                  S_VALUE(snip->OutEchos,         snic->OutEchos,         itv),
1204                  S_VALUE(snip->OutEchoReps,      snic->OutEchoReps,      itv),
1205                  S_VALUE(snip->InTimestamps,     snic->InTimestamps,     itv),
1206                  S_VALUE(snip->InTimestampReps,  snic->InTimestampReps,  itv),
1207                  S_VALUE(snip->OutTimestamps,    snic->OutTimestamps,    itv),
1208                  S_VALUE(snip->OutTimestampReps, snic->OutTimestampReps, itv),
1209                  S_VALUE(snip->InAddrMasks,      snic->InAddrMasks,      itv),
1210                  S_VALUE(snip->InAddrMaskReps,   snic->InAddrMaskReps,   itv),
1211                  S_VALUE(snip->OutAddrMasks,     snic->OutAddrMasks,     itv),
1212                  S_VALUE(snip->OutAddrMaskReps,  snic->OutAddrMaskReps,  itv));
1213         tab--;
1214
1215 close_json_markup:
1216         if (CLOSE_MARKUP(a->options)) {
1217                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1218         }
1219 }
1220
1221 /*
1222  ***************************************************************************
1223  * Display ICMP errors message statistics in JSON.
1224  *
1225  * IN:
1226  * @a           Activity structure with statistics.
1227  * @curr        Index in array for current sample statistics.
1228  * @tab         Indentation in output.
1229  * @itv         Interval of time in jiffies.
1230  ***************************************************************************
1231  */
1232 __print_funct_t json_print_net_eicmp_stats(struct activity *a, int curr, int tab,
1233                                            unsigned long long itv)
1234 {
1235         struct stats_net_eicmp
1236                 *sneic = (struct stats_net_eicmp *) a->buf[curr],
1237                 *sneip = (struct stats_net_eicmp *) a->buf[!curr];
1238
1239         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1240                 goto close_json_markup;
1241
1242         json_markup_network(tab, OPEN_JSON_MARKUP);
1243         tab++;
1244
1245         xprintf0(tab, "\"net-eicmp\": {"
1246                  "\"ierr\": %.2f, "
1247                  "\"oerr\": %.2f, "
1248                  "\"idstunr\": %.2f, "
1249                  "\"odstunr\": %.2f, "
1250                  "\"itmex\": %.2f, "
1251                  "\"otmex\": %.2f, "
1252                  "\"iparmpb\": %.2f, "
1253                  "\"oparmpb\": %.2f, "
1254                  "\"isrcq\": %.2f, "
1255                  "\"osrcq\": %.2f, "
1256                  "\"iredir\": %.2f, "
1257                  "\"oredir\": %.2f}",
1258                  S_VALUE(sneip->InErrors,        sneic->InErrors,        itv),
1259                  S_VALUE(sneip->OutErrors,       sneic->OutErrors,       itv),
1260                  S_VALUE(sneip->InDestUnreachs,  sneic->InDestUnreachs,  itv),
1261                  S_VALUE(sneip->OutDestUnreachs, sneic->OutDestUnreachs, itv),
1262                  S_VALUE(sneip->InTimeExcds,     sneic->InTimeExcds,     itv),
1263                  S_VALUE(sneip->OutTimeExcds,    sneic->OutTimeExcds,    itv),
1264                  S_VALUE(sneip->InParmProbs,     sneic->InParmProbs,     itv),
1265                  S_VALUE(sneip->OutParmProbs,    sneic->OutParmProbs,    itv),
1266                  S_VALUE(sneip->InSrcQuenchs,    sneic->InSrcQuenchs,    itv),
1267                  S_VALUE(sneip->OutSrcQuenchs,   sneic->OutSrcQuenchs,   itv),
1268                  S_VALUE(sneip->InRedirects,     sneic->InRedirects,     itv),
1269                  S_VALUE(sneip->OutRedirects,    sneic->OutRedirects,    itv));
1270         tab--;
1271
1272 close_json_markup:
1273         if (CLOSE_MARKUP(a->options)) {
1274                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1275         }
1276 }
1277
1278 /*
1279  ***************************************************************************
1280  * Display TCP network statistics in JSON.
1281  *
1282  * IN:
1283  * @a           Activity structure with statistics.
1284  * @curr        Index in array for current sample statistics.
1285  * @tab         Indentation in output.
1286  * @itv         Interval of time in jiffies.
1287  ***************************************************************************
1288  */
1289 __print_funct_t json_print_net_tcp_stats(struct activity *a, int curr, int tab,
1290                                          unsigned long long itv)
1291 {
1292         struct stats_net_tcp
1293                 *sntc = (struct stats_net_tcp *) a->buf[curr],
1294                 *sntp = (struct stats_net_tcp *) a->buf[!curr];
1295
1296         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1297                 goto close_json_markup;
1298
1299         json_markup_network(tab, OPEN_JSON_MARKUP);
1300         tab++;
1301
1302         xprintf0(tab, "\"net-tcp\": {"
1303                  "\"active\": %.2f, "
1304                  "\"passive\": %.2f, "
1305                  "\"iseg\": %.2f, "
1306                  "\"oseg\": %.2f}",
1307                  S_VALUE(sntp->ActiveOpens,  sntc->ActiveOpens,  itv),
1308                  S_VALUE(sntp->PassiveOpens, sntc->PassiveOpens, itv),
1309                  S_VALUE(sntp->InSegs,       sntc->InSegs,       itv),
1310                  S_VALUE(sntp->OutSegs,      sntc->OutSegs,      itv));
1311         tab--;
1312
1313 close_json_markup:
1314         if (CLOSE_MARKUP(a->options)) {
1315                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1316         }
1317 }
1318
1319 /*
1320  ***************************************************************************
1321  * Display TCP network errors statistics in JSON.
1322  *
1323  * IN:
1324  * @a           Activity structure with statistics.
1325  * @curr        Index in array for current sample statistics.
1326  * @tab         Indentation in XML output.
1327  * @itv         Interval of time in jiffies.
1328  ***************************************************************************
1329  */
1330 __print_funct_t json_print_net_etcp_stats(struct activity *a, int curr, int tab,
1331                                           unsigned long long itv)
1332 {
1333         struct stats_net_etcp
1334                 *snetc = (struct stats_net_etcp *) a->buf[curr],
1335                 *snetp = (struct stats_net_etcp *) a->buf[!curr];
1336
1337         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1338                 goto close_json_markup;
1339
1340         json_markup_network(tab, OPEN_JSON_MARKUP);
1341         tab++;
1342
1343         xprintf0(tab, "\"net-etcp\": {"
1344                  "\"atmptf\": %.2f, "
1345                  "\"estres\": %.2f, "
1346                  "\"retrans\": %.2f, "
1347                  "\"isegerr\": %.2f, "
1348                  "\"orsts\": %.2f}",
1349                  S_VALUE(snetp->AttemptFails, snetc->AttemptFails,  itv),
1350                  S_VALUE(snetp->EstabResets,  snetc->EstabResets,  itv),
1351                  S_VALUE(snetp->RetransSegs,  snetc->RetransSegs,  itv),
1352                  S_VALUE(snetp->InErrs,       snetc->InErrs,  itv),
1353                  S_VALUE(snetp->OutRsts,      snetc->OutRsts,  itv));
1354         tab--;
1355
1356 close_json_markup:
1357         if (CLOSE_MARKUP(a->options)) {
1358                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1359         }
1360 }
1361
1362 /*
1363  ***************************************************************************
1364  * Display UDP network statistics in JSON.
1365  *
1366  * IN:
1367  * @a           Activity structure with statistics.
1368  * @curr        Index in array for current sample statistics.
1369  * @tab         Indentation in output.
1370  * @itv         Interval of time in jiffies.
1371  ***************************************************************************
1372  */
1373 __print_funct_t json_print_net_udp_stats(struct activity *a, int curr, int tab,
1374                                          unsigned long long itv)
1375 {
1376         struct stats_net_udp
1377                 *snuc = (struct stats_net_udp *) a->buf[curr],
1378                 *snup = (struct stats_net_udp *) a->buf[!curr];
1379
1380         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1381                 goto close_json_markup;
1382
1383         json_markup_network(tab, OPEN_JSON_MARKUP);
1384         tab++;
1385
1386         xprintf0(tab, "\"net-udp\": {"
1387                  "\"idgm\": %.2f, "
1388                  "\"odgm\": %.2f, "
1389                  "\"noport\": %.2f, "
1390                  "\"idgmerr\": %.2f}",
1391                  S_VALUE(snup->InDatagrams,  snuc->InDatagrams,  itv),
1392                  S_VALUE(snup->OutDatagrams, snuc->OutDatagrams, itv),
1393                  S_VALUE(snup->NoPorts,      snuc->NoPorts,      itv),
1394                  S_VALUE(snup->InErrors,     snuc->InErrors,     itv));
1395         tab--;
1396
1397 close_json_markup:
1398         if (CLOSE_MARKUP(a->options)) {
1399                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1400         }
1401 }
1402
1403 /*
1404  ***************************************************************************
1405  * Display IPv6 network socket statistics in JSON.
1406  *
1407  * IN:
1408  * @a           Activity structure with statistics.
1409  * @curr        Index in array for current sample statistics.
1410  * @tab         Indentation in output.
1411  * @itv         Interval of time in jiffies.
1412  ***************************************************************************
1413  */
1414 __print_funct_t json_print_net_sock6_stats(struct activity *a, int curr, int tab,
1415                                            unsigned long long itv)
1416 {
1417         struct stats_net_sock6
1418                 *snsc = (struct stats_net_sock6 *) a->buf[curr];
1419
1420         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1421                 goto close_json_markup;
1422
1423         json_markup_network(tab, OPEN_JSON_MARKUP);
1424         tab++;
1425
1426         xprintf0(tab, "\"net-sock6\": {"
1427                  "\"tcp6sck\": %u, "
1428                  "\"udp6sck\": %u, "
1429                  "\"raw6sck\": %u, "
1430                  "\"ip6-frag\": %u}",
1431                  snsc->tcp6_inuse,
1432                  snsc->udp6_inuse,
1433                  snsc->raw6_inuse,
1434                  snsc->frag6_inuse);
1435         tab--;
1436
1437 close_json_markup:
1438         if (CLOSE_MARKUP(a->options)) {
1439                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1440         }
1441 }
1442
1443 /*
1444  ***************************************************************************
1445  * Display IPv6 network statistics in JSON.
1446  *
1447  * IN:
1448  * @a           Activity structure with statistics.
1449  * @curr        Index in array for current sample statistics.
1450  * @tab         Indentation in output.
1451  * @itv         Interval of time in jiffies.
1452  ***************************************************************************
1453  */
1454 __print_funct_t json_print_net_ip6_stats(struct activity *a, int curr, int tab,
1455                                          unsigned long long itv)
1456 {
1457         struct stats_net_ip6
1458                 *snic = (struct stats_net_ip6 *) a->buf[curr],
1459                 *snip = (struct stats_net_ip6 *) a->buf[!curr];
1460
1461         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1462                 goto close_json_markup;
1463
1464         json_markup_network(tab, OPEN_JSON_MARKUP);
1465         tab++;
1466
1467         xprintf0(tab, "\"net-ip6\": {"
1468                  "\"irec6\": %.2f, "
1469                  "\"fwddgm6\": %.2f, "
1470                  "\"idel6\": %.2f, "
1471                  "\"orq6\": %.2f, "
1472                  "\"asmrq6\": %.2f, "
1473                  "\"asmok6\": %.2f, "
1474                  "\"imcpck6\": %.2f, "
1475                  "\"omcpck6\": %.2f, "
1476                  "\"fragok6\": %.2f, "
1477                  "\"fragcr6\": %.2f}",
1478                  S_VALUE(snip->InReceives6,       snic->InReceives6,       itv),
1479                  S_VALUE(snip->OutForwDatagrams6, snic->OutForwDatagrams6, itv),
1480                  S_VALUE(snip->InDelivers6,       snic->InDelivers6,       itv),
1481                  S_VALUE(snip->OutRequests6,      snic->OutRequests6,      itv),
1482                  S_VALUE(snip->ReasmReqds6,       snic->ReasmReqds6,       itv),
1483                  S_VALUE(snip->ReasmOKs6,         snic->ReasmOKs6,         itv),
1484                  S_VALUE(snip->InMcastPkts6,      snic->InMcastPkts6,      itv),
1485                  S_VALUE(snip->OutMcastPkts6,     snic->OutMcastPkts6,     itv),
1486                  S_VALUE(snip->FragOKs6,          snic->FragOKs6,          itv),
1487                  S_VALUE(snip->FragCreates6,      snic->FragCreates6,      itv));
1488         tab--;
1489
1490 close_json_markup:
1491         if (CLOSE_MARKUP(a->options)) {
1492                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1493         }
1494 }
1495
1496 /*
1497  ***************************************************************************
1498  * Display IPv6 network errors statistics in JSON.
1499  *
1500  * IN:
1501  * @a           Activity structure with statistics.
1502  * @curr        Index in array for current sample statistics.
1503  * @tab         Indentation in output.
1504  * @itv         Interval of time in jiffies.
1505  ***************************************************************************
1506  */
1507 __print_funct_t json_print_net_eip6_stats(struct activity *a, int curr, int tab,
1508                                           unsigned long long itv)
1509 {
1510         struct stats_net_eip6
1511                 *sneic = (struct stats_net_eip6 *) a->buf[curr],
1512                 *sneip = (struct stats_net_eip6 *) a->buf[!curr];
1513
1514         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1515                 goto close_json_markup;
1516
1517         json_markup_network(tab, OPEN_JSON_MARKUP);
1518         tab++;
1519
1520         xprintf0(tab, "\"net-eip6\": {"
1521                  "\"ihdrer6\": %.2f, "
1522                  "\"iadrer6\": %.2f, "
1523                  "\"iukwnp6\": %.2f, "
1524                  "\"i2big6\": %.2f, "
1525                  "\"idisc6\": %.2f, "
1526                  "\"odisc6\": %.2f, "
1527                  "\"inort6\": %.2f, "
1528                  "\"onort6\": %.2f, "
1529                  "\"asmf6\": %.2f, "
1530                  "\"fragf6\": %.2f, "
1531                  "\"itrpck6\": %.2f}",
1532                  S_VALUE(sneip->InHdrErrors6,     sneic->InHdrErrors6,     itv),
1533                  S_VALUE(sneip->InAddrErrors6,    sneic->InAddrErrors6,    itv),
1534                  S_VALUE(sneip->InUnknownProtos6, sneic->InUnknownProtos6, itv),
1535                  S_VALUE(sneip->InTooBigErrors6,  sneic->InTooBigErrors6,  itv),
1536                  S_VALUE(sneip->InDiscards6,      sneic->InDiscards6,      itv),
1537                  S_VALUE(sneip->OutDiscards6,     sneic->OutDiscards6,     itv),
1538                  S_VALUE(sneip->InNoRoutes6,      sneic->InNoRoutes6,      itv),
1539                  S_VALUE(sneip->OutNoRoutes6,     sneic->OutNoRoutes6,     itv),
1540                  S_VALUE(sneip->ReasmFails6,      sneic->ReasmFails6,      itv),
1541                  S_VALUE(sneip->FragFails6,       sneic->FragFails6,       itv),
1542                  S_VALUE(sneip->InTruncatedPkts6, sneic->InTruncatedPkts6, itv));
1543         tab--;
1544
1545 close_json_markup:
1546         if (CLOSE_MARKUP(a->options)) {
1547                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1548         }
1549 }
1550
1551 /*
1552  ***************************************************************************
1553  * Display ICMPv6 network statistics in JSON.
1554  *
1555  * IN:
1556  * @a           Activity structure with statistics.
1557  * @curr        Index in array for current sample statistics.
1558  * @tab         Indentation in output.
1559  * @itv         Interval of time in jiffies.
1560  ***************************************************************************
1561  */
1562 __print_funct_t json_print_net_icmp6_stats(struct activity *a, int curr, int tab,
1563                                            unsigned long long itv)
1564 {
1565         struct stats_net_icmp6
1566                 *snic = (struct stats_net_icmp6 *) a->buf[curr],
1567                 *snip = (struct stats_net_icmp6 *) a->buf[!curr];
1568
1569         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1570                 goto close_json_markup;
1571
1572         json_markup_network(tab, OPEN_JSON_MARKUP);
1573         tab++;
1574
1575         xprintf0(tab, "\"net-icmp6\": {"
1576                  "\"imsg6\": %.2f, "
1577                  "\"omsg6\": %.2f, "
1578                  "\"iech6\": %.2f, "
1579                  "\"iechr6\": %.2f, "
1580                  "\"oechr6\": %.2f, "
1581                  "\"igmbq6\": %.2f, "
1582                  "\"igmbr6\": %.2f, "
1583                  "\"ogmbr6\": %.2f, "
1584                  "\"igmbrd6\": %.2f, "
1585                  "\"ogmbrd6\": %.2f, "
1586                  "\"irtsol6\": %.2f, "
1587                  "\"ortsol6\": %.2f, "
1588                  "\"irtad6\": %.2f, "
1589                  "\"inbsol6\": %.2f, "
1590                  "\"onbsol6\": %.2f, "
1591                  "\"inbad6\": %.2f, "
1592                  "\"onbad6\": %.2f}",
1593                  S_VALUE(snip->InMsgs6,                    snic->InMsgs6,                    itv),
1594                  S_VALUE(snip->OutMsgs6,                   snic->OutMsgs6,                   itv),
1595                  S_VALUE(snip->InEchos6,                   snic->InEchos6,                   itv),
1596                  S_VALUE(snip->InEchoReplies6,             snic->InEchoReplies6,             itv),
1597                  S_VALUE(snip->OutEchoReplies6,            snic->OutEchoReplies6,            itv),
1598                  S_VALUE(snip->InGroupMembQueries6,        snic->InGroupMembQueries6,        itv),
1599                  S_VALUE(snip->InGroupMembResponses6,      snic->InGroupMembResponses6,      itv),
1600                  S_VALUE(snip->OutGroupMembResponses6,     snic->OutGroupMembResponses6,     itv),
1601                  S_VALUE(snip->InGroupMembReductions6,     snic->InGroupMembReductions6,     itv),
1602                  S_VALUE(snip->OutGroupMembReductions6,    snic->OutGroupMembReductions6,    itv),
1603                  S_VALUE(snip->InRouterSolicits6,          snic->InRouterSolicits6,          itv),
1604                  S_VALUE(snip->OutRouterSolicits6,         snic->OutRouterSolicits6,         itv),
1605                  S_VALUE(snip->InRouterAdvertisements6,    snic->InRouterAdvertisements6,    itv),
1606                  S_VALUE(snip->InNeighborSolicits6,        snic->InNeighborSolicits6,        itv),
1607                  S_VALUE(snip->OutNeighborSolicits6,       snic->OutNeighborSolicits6,       itv),
1608                  S_VALUE(snip->InNeighborAdvertisements6,  snic->InNeighborAdvertisements6,  itv),
1609                  S_VALUE(snip->OutNeighborAdvertisements6, snic->OutNeighborAdvertisements6, itv));
1610         tab--;
1611
1612 close_json_markup:
1613         if (CLOSE_MARKUP(a->options)) {
1614                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1615         }
1616 }
1617
1618 /*
1619  ***************************************************************************
1620  * Display ICMPv6 error messages statistics in JSON.
1621  *
1622  * IN:
1623  * @a           Activity structure with statistics.
1624  * @curr        Index in array for current sample statistics.
1625  * @tab         Indentation in output.
1626  * @itv         Interval of time in jiffies.
1627  ***************************************************************************
1628  */
1629 __print_funct_t json_print_net_eicmp6_stats(struct activity *a, int curr, int tab,
1630                                             unsigned long long itv)
1631 {
1632         struct stats_net_eicmp6
1633                 *sneic = (struct stats_net_eicmp6 *) a->buf[curr],
1634                 *sneip = (struct stats_net_eicmp6 *) a->buf[!curr];
1635
1636         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1637                 goto close_json_markup;
1638
1639         json_markup_network(tab, OPEN_JSON_MARKUP);
1640         tab++;
1641
1642         xprintf0(tab, "\"net-eicmp6\": {"
1643                  "\"ierr6\": %.2f, "
1644                  "\"idtunr6\": %.2f, "
1645                  "\"odtunr6\": %.2f, "
1646                  "\"itmex6\": %.2f, "
1647                  "\"otmex6\": %.2f, "
1648                  "\"iprmpb6\": %.2f, "
1649                  "\"oprmpb6\": %.2f, "
1650                  "\"iredir6\": %.2f, "
1651                  "\"oredir6\": %.2f, "
1652                  "\"ipck2b6\": %.2f, "
1653                  "\"opck2b6\": %.2f}",
1654                  S_VALUE(sneip->InErrors6,        sneic->InErrors6,        itv),
1655                  S_VALUE(sneip->InDestUnreachs6,  sneic->InDestUnreachs6,  itv),
1656                  S_VALUE(sneip->OutDestUnreachs6, sneic->OutDestUnreachs6, itv),
1657                  S_VALUE(sneip->InTimeExcds6,     sneic->InTimeExcds6,     itv),
1658                  S_VALUE(sneip->OutTimeExcds6,    sneic->OutTimeExcds6,    itv),
1659                  S_VALUE(sneip->InParmProblems6,  sneic->InParmProblems6,  itv),
1660                  S_VALUE(sneip->OutParmProblems6, sneic->OutParmProblems6, itv),
1661                  S_VALUE(sneip->InRedirects6,     sneic->InRedirects6,     itv),
1662                  S_VALUE(sneip->OutRedirects6,    sneic->OutRedirects6,    itv),
1663                  S_VALUE(sneip->InPktTooBigs6,    sneic->InPktTooBigs6,    itv),
1664                  S_VALUE(sneip->OutPktTooBigs6,   sneic->OutPktTooBigs6,   itv));
1665         tab--;
1666
1667 close_json_markup:
1668         if (CLOSE_MARKUP(a->options)) {
1669                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1670         }
1671 }
1672
1673 /*
1674  ***************************************************************************
1675  * Display UDPv6 network statistics in JSON.
1676  *
1677  * IN:
1678  * @a           Activity structure with statistics.
1679  * @curr        Index in array for current sample statistics.
1680  * @tab         Indentation in output.
1681  * @itv         Interval of time in jiffies.
1682  ***************************************************************************
1683  */
1684 __print_funct_t json_print_net_udp6_stats(struct activity *a, int curr, int tab,
1685                                           unsigned long long itv)
1686 {
1687         struct stats_net_udp6
1688                 *snuc = (struct stats_net_udp6 *) a->buf[curr],
1689                 *snup = (struct stats_net_udp6 *) a->buf[!curr];
1690
1691         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1692                 goto close_json_markup;
1693
1694         json_markup_network(tab, OPEN_JSON_MARKUP);
1695         tab++;
1696
1697         xprintf0(tab, "\"net-udp6\": {"
1698                  "\"idgm6\": %.2f, "
1699                  "\"odgm6\": %.2f, "
1700                  "\"noport6\": %.2f, "
1701                  "\"idgmer6\": %.2f}",
1702                  S_VALUE(snup->InDatagrams6,  snuc->InDatagrams6,  itv),
1703                  S_VALUE(snup->OutDatagrams6, snuc->OutDatagrams6, itv),
1704                  S_VALUE(snup->NoPorts6,      snuc->NoPorts6,      itv),
1705                  S_VALUE(snup->InErrors6,     snuc->InErrors6,     itv));
1706         tab--;
1707
1708 close_json_markup:
1709         if (CLOSE_MARKUP(a->options)) {
1710                 json_markup_network(tab, CLOSE_JSON_MARKUP);
1711         }
1712 }
1713
1714 /*
1715  ***************************************************************************
1716  * Display CPU frequency statistics in JSON.
1717  *
1718  * IN:
1719  * @a           Activity structure with statistics.
1720  * @curr        Index in array for current sample statistics.
1721  * @tab         Indentation in output.
1722  * @itv         Interval of time in jiffies.
1723  ***************************************************************************
1724  */
1725 __print_funct_t json_print_pwr_cpufreq_stats(struct activity *a, int curr, int tab,
1726                                              unsigned long long itv)
1727 {
1728         int i;
1729         struct stats_pwr_cpufreq *spc;
1730         int sep = FALSE;
1731         char cpuno[8];
1732
1733         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1734                 goto close_json_markup;
1735
1736         json_markup_power_management(tab, OPEN_JSON_MARKUP);
1737         tab++;
1738
1739         xprintf(tab++, "\"cpu-frequency\": [");
1740
1741         for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
1742
1743                 spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr]  + i * a->msize);
1744
1745                 /* Should current CPU (including CPU "all") be displayed? */
1746                 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
1747
1748                         /* Yes: Display it */
1749                         if (!i) {
1750                                 /* This is CPU "all" */
1751                                 strcpy(cpuno, "all");
1752                         }
1753                         else {
1754                                 sprintf(cpuno, "%d", i - 1);
1755                         }
1756
1757                         if (sep) {
1758                                 printf(",\n");
1759                         }
1760                         sep = TRUE;
1761
1762                         xprintf0(tab, "{\"number\": \"%s\", "
1763                                  "\"frequency\": %.2f}",
1764                                  cpuno,
1765                                  ((double) spc->cpufreq) / 100);
1766                 }
1767         }
1768
1769         printf("\n");
1770         xprintf0(--tab, "]");
1771         tab--;
1772
1773 close_json_markup:
1774         if (CLOSE_MARKUP(a->options)) {
1775                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1776         }
1777 }
1778
1779 /*
1780  ***************************************************************************
1781  * Display fan statistics in JSON.
1782  *
1783  * IN:
1784  * @a           Activity structure with statistics.
1785  * @curr        Index in array for current sample statistics.
1786  * @tab         Indentation in output.
1787  * @itv         Interval of time in jiffies.
1788  ***************************************************************************
1789  */
1790 __print_funct_t json_print_pwr_fan_stats(struct activity *a, int curr, int tab,
1791                                          unsigned long long itv)
1792 {
1793         int i;
1794         struct stats_pwr_fan *spc;
1795         int sep = FALSE;
1796
1797         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1798                 goto close_json_markup;
1799
1800         json_markup_power_management(tab, OPEN_JSON_MARKUP);
1801         tab++;
1802
1803         xprintf(tab++, "\"fan-speed\": [");
1804
1805         for (i = 0; i < a->nr; i++) {
1806                 spc = (struct stats_pwr_fan *) ((char *) a->buf[curr]  + i * a->msize);
1807
1808                 if (sep) {
1809                         printf(",\n");
1810                 }
1811                 sep = TRUE;
1812
1813                 xprintf0(tab, "{\"number\": %d, "
1814                          "\"rpm\": %llu, "
1815                          "\"drpm\": %llu, "
1816                          "\"device\": \"%s\"}",
1817                          i + 1,
1818                          (unsigned long long) spc->rpm,
1819                          (unsigned long long) (spc->rpm - spc->rpm_min),
1820                          spc->device);
1821         }
1822
1823         printf("\n");
1824         xprintf0(--tab, "]");
1825         tab--;
1826
1827 close_json_markup:
1828         if (CLOSE_MARKUP(a->options)) {
1829                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1830         }
1831 }
1832
1833 /*
1834  ***************************************************************************
1835  * Display temperature statistics in JSON.
1836  *
1837  * IN:
1838  * @a           Activity structure with statistics.
1839  * @curr        Index in array for current sample statistics.
1840  * @tab         Indentation in output.
1841  * @itv         Interval of time in jiffies.
1842  ***************************************************************************
1843  */
1844 __print_funct_t json_print_pwr_temp_stats(struct activity *a, int curr, int tab,
1845                                           unsigned long long itv)
1846 {
1847         int i;
1848         struct stats_pwr_temp *spc;
1849         int sep = FALSE;
1850
1851         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1852                 goto close_json_markup;
1853
1854         json_markup_power_management(tab, OPEN_JSON_MARKUP);
1855         tab++;
1856
1857         xprintf(tab++, "\"temperature\": [");
1858
1859         for (i = 0; i < a->nr; i++) {
1860                 spc = (struct stats_pwr_temp *) ((char *) a->buf[curr]  + i * a->msize);
1861
1862                 if (sep) {
1863                         printf(",\n");
1864                 }
1865                 sep = TRUE;
1866
1867                 xprintf0(tab, "{\"number\": %d, "
1868                          "\"degC\": %.2f, "
1869                          "\"percent-temp\": %.2f, "
1870                          "\"device\": \"%s\"}",
1871                          i + 1,
1872                          spc->temp,
1873                          (spc->temp_max - spc->temp_min) ?
1874                          (spc->temp - spc->temp_min) / (spc->temp_max - spc->temp_min) * 100 :
1875                          0.0,
1876                          spc->device);
1877         }
1878
1879         printf("\n");
1880         xprintf0(--tab, "]");
1881         tab--;
1882
1883 close_json_markup:
1884         if (CLOSE_MARKUP(a->options)) {
1885                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1886         }
1887 }
1888
1889 /*
1890  ***************************************************************************
1891  * Display voltage inputs statistics in JSON.
1892  *
1893  * IN:
1894  * @a           Activity structure with statistics.
1895  * @curr        Index in array for current sample statistics.
1896  * @tab         Indentation in output.
1897  * @itv         Interval of time in jiffies.
1898  ***************************************************************************
1899  */
1900 __print_funct_t json_print_pwr_in_stats(struct activity *a, int curr, int tab,
1901                                         unsigned long long itv)
1902 {
1903         int i;
1904         struct stats_pwr_in *spc;
1905         int sep = FALSE;
1906
1907         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1908                 goto close_json_markup;
1909
1910         json_markup_power_management(tab, OPEN_JSON_MARKUP);
1911         tab++;
1912
1913         xprintf(tab++, "\"voltage-input\": [");
1914
1915         for (i = 0; i < a->nr; i++) {
1916                 spc = (struct stats_pwr_in *) ((char *) a->buf[curr]  + i * a->msize);
1917
1918                 if (sep) {
1919                         printf(",\n");
1920                 }
1921                 sep = TRUE;
1922
1923                 xprintf0(tab, "{\"number\": %d, "
1924                          "\"inV\": %.2f, "
1925                          "\"percent-in\": %.2f, "
1926                          "\"device\": \"%s\"}",
1927                          i,
1928                          spc->in,
1929                          (spc->in_max - spc->in_min) ?
1930                          (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100 :
1931                          0.0,
1932                          spc->device);
1933         }
1934
1935         printf("\n");
1936         xprintf0(--tab, "]");
1937         tab--;
1938
1939 close_json_markup:
1940         if (CLOSE_MARKUP(a->options)) {
1941                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1942         }
1943 }
1944
1945 /*
1946  ***************************************************************************
1947  * Display huge pages statistics in JSON.
1948  *
1949  * IN:
1950  * @a           Activity structure with statistics.
1951  * @curr        Index in array for current sample statistics.
1952  * @tab         Indentation in output.
1953  * @itv         Interval of time in jiffies.
1954  ***************************************************************************
1955  */
1956 __print_funct_t json_print_huge_stats(struct activity *a, int curr, int tab,
1957                                       unsigned long long itv)
1958 {
1959         struct stats_huge
1960                 *smc = (struct stats_huge *) a->buf[curr];
1961
1962         xprintf0(tab, "\"hugepages\": {"
1963                  "\"hugfree\": %lu, "
1964                  "\"hugused\": %lu, "
1965                  "\"hugused-percent\": %.2f}",
1966                  smc->frhkb,
1967                  smc->tlhkb - smc->frhkb,
1968                  smc->tlhkb ?
1969                  SP_VALUE(smc->frhkb, smc->tlhkb, smc->tlhkb) :
1970                  0.0);
1971 }
1972
1973 /*
1974  ***************************************************************************
1975  * Display weighted CPU frequency statistics in JSON.
1976  *
1977  * IN:
1978  * @a           Activity structure with statistics.
1979  * @curr        Index in array for current sample statistics.
1980  * @tab         Indentation in output.
1981  * @itv         Interval of time in jiffies.
1982  ***************************************************************************
1983  */
1984 __print_funct_t json_print_pwr_wghfreq_stats(struct activity *a, int curr, int tab,
1985                                              unsigned long long itv)
1986 {
1987         int i, k;
1988         struct stats_pwr_wghfreq *spc, *spp, *spc_k, *spp_k;
1989         unsigned long long tis, tisfreq;
1990         int sep = FALSE;
1991         char cpuno[8];
1992
1993         if (!IS_SELECTED(a->options) || (a->nr <= 0))
1994                 goto close_json_markup;
1995
1996         json_markup_power_management(tab, OPEN_JSON_MARKUP);
1997         tab++;
1998
1999         xprintf(tab++, "\"cpu-weighted-frequency\": [");
2000
2001         for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
2002
2003                 spc = (struct stats_pwr_wghfreq *) ((char *) a->buf[curr]  + i * a->msize * a->nr2);
2004                 spp = (struct stats_pwr_wghfreq *) ((char *) a->buf[!curr] + i * a->msize * a->nr2);
2005
2006                 /* Should current CPU (including CPU "all") be displayed? */
2007                 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
2008
2009                         /* Yes... */
2010                         tisfreq = 0;
2011                         tis = 0;
2012
2013                         for (k = 0; k < a->nr2; k++) {
2014
2015                                 spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * a->msize);
2016                                 if (!spc_k->freq)
2017                                         break;
2018                                 spp_k = (struct stats_pwr_wghfreq *) ((char *) spp + k * a->msize);
2019
2020                                 tisfreq += (spc_k->freq / 1000) *
2021                                            (spc_k->time_in_state - spp_k->time_in_state);
2022                                 tis     += (spc_k->time_in_state - spp_k->time_in_state);
2023                         }
2024
2025                         if (!i) {
2026                                 /* This is CPU "all" */
2027                                 strcpy(cpuno, "all");
2028                         }
2029                         else {
2030                                 sprintf(cpuno, "%d", i - 1);
2031                         }
2032
2033                         if (sep) {
2034                                 printf(",\n");
2035                         }
2036                         sep = TRUE;
2037
2038                         xprintf0(tab, "{\"number\": \"%s\", "
2039                                  "\"weighted-frequency\": %.2f}",
2040                                  cpuno,
2041                                  tis ? ((double) tisfreq) / tis : 0.0);
2042                 }
2043         }
2044
2045         printf("\n");
2046         xprintf0(--tab, "]");
2047         tab--;
2048
2049 close_json_markup:
2050         if (CLOSE_MARKUP(a->options)) {
2051                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
2052         }
2053 }
2054
2055 /*
2056  ***************************************************************************
2057  * Display USB devices statistics in JSON.
2058  *
2059  * IN:
2060  * @a           Activity structure with statistics.
2061  * @curr        Index in array for current sample statistics.
2062  * @tab         Indentation in output.
2063  * @itv         Interval of time in jiffies.
2064  ***************************************************************************
2065  */
2066 __print_funct_t json_print_pwr_usb_stats(struct activity *a, int curr, int tab,
2067                                          unsigned long long itv)
2068 {
2069         int i;
2070         struct stats_pwr_usb *suc;
2071         int sep = FALSE;
2072
2073         if (!IS_SELECTED(a->options) || (a->nr <= 0))
2074                 goto close_json_markup;
2075
2076         json_markup_power_management(tab, OPEN_JSON_MARKUP);
2077         tab++;
2078
2079         xprintf(tab++, "\"usb-devices\": [");
2080
2081         for (i = 0; i < a->nr; i++) {
2082                 suc = (struct stats_pwr_usb *) ((char *) a->buf[curr]  + i * a->msize);
2083
2084                 if (!suc->bus_nr)
2085                         /* Bus#0 doesn't exist: We are at the end of the list */
2086                         break;
2087
2088                 if (sep) {
2089                         printf(",\n");
2090                 }
2091                 sep = TRUE;
2092
2093                 xprintf0(tab, "{\"bus_number\": %d, "
2094                          "\"idvendor\": \"%x\", "
2095                          "\"idprod\": \"%x\", "
2096                          "\"maxpower\": %u, "
2097                          "\"manufact\": \"%s\", "
2098                          "\"product\": \"%s\"}",
2099                          suc->bus_nr,
2100                          suc->vendor_id,
2101                          suc->product_id,
2102                          suc->bmaxpower << 1,
2103                          suc->manufacturer,
2104                          suc->product);
2105         }
2106
2107         printf("\n");
2108         xprintf0(--tab, "]");
2109         tab--;
2110
2111 close_json_markup:
2112         if (CLOSE_MARKUP(a->options)) {
2113                 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
2114         }
2115 }
2116
2117 /*
2118  ***************************************************************************
2119  * Display filesystems statistics in JSON.
2120  *
2121  * IN:
2122  * @a           Activity structure with statistics.
2123  * @curr        Index in array for current sample statistics.
2124  * @tab         Indentation in output.
2125  * @itv         Interval of time in jiffies.
2126  ***************************************************************************
2127  */
2128 __print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
2129                                             unsigned long long itv)
2130 {
2131         int i;
2132         struct stats_filesystem *sfc;
2133         int sep = FALSE;
2134
2135         xprintf(tab++, "\"filesystems\": [");
2136
2137         for (i = 0; i < a->nr; i++) {
2138                 sfc = (struct stats_filesystem *) ((char *) a->buf[curr]  + i * a->msize);
2139
2140                 if (!sfc->f_blocks)
2141                         /* Size of filesystem is zero: We are at the end of the list */
2142                         break;
2143
2144                 if (sep) {
2145                         printf(",\n");
2146                 }
2147                 sep = TRUE;
2148
2149                 xprintf0(tab, "{\"%s\": \"%s\", "
2150                          "\"MBfsfree\": %.0f, "
2151                          "\"MBfsused\": %.0f, "
2152                          "\"%%fsused\": %.2f, "
2153                          "\"%%ufsused\": %.2f, "
2154                          "\"Ifree\": %llu, "
2155                          "\"Iused\": %llu, "
2156                          "\"%%Iused\": %.2f}",
2157                          DISPLAY_MOUNT(a->opt_flags) ? "mountpoint" : "filesystem",
2158                          DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name,
2159                          (double) sfc->f_bfree / 1024 / 1024,
2160                          (double) (sfc->f_blocks - sfc->f_bfree) / 1024 / 1024,
2161                          sfc->f_blocks ? SP_VALUE(sfc->f_bfree, sfc->f_blocks, sfc->f_blocks)
2162                                      : 0.0,
2163                          sfc->f_blocks ? SP_VALUE(sfc->f_bavail, sfc->f_blocks, sfc->f_blocks)
2164                                      : 0.0,
2165                          sfc->f_ffree,
2166                          sfc->f_files - sfc->f_ffree,
2167                          sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files)
2168                                     : 0.0);
2169         }
2170
2171         printf("\n");
2172         xprintf0(--tab, "]");
2173 }
2174
2175 /*
2176  ***************************************************************************
2177  * Display Fibre Channel HBA statistics in JSON.
2178  *
2179  * IN:
2180  * @a           Activity structure with statistics.
2181  * @curr        Index in array for current sample statistics.
2182  * @tab         Indentation in output.
2183  * @itv         Interval of time in jiffies.
2184  ***************************************************************************
2185  */
2186 __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab,
2187                                         unsigned long long itv)
2188 {
2189         int i;
2190         struct stats_fchost *sfcc, *sfcp;
2191         int sep = FALSE;
2192
2193         if (!IS_SELECTED(a->options) || (a->nr <= 0))
2194                 goto close_json_markup;
2195
2196         json_markup_network(tab, OPEN_JSON_MARKUP);
2197         tab++;
2198
2199         xprintf(tab++, "\"fchosts\": [");
2200
2201         for (i = 0; i < a->nr; i++) {
2202                 sfcc = (struct stats_fchost *) ((char *) a->buf[curr]  + i * a->msize);
2203                 sfcp = (struct stats_fchost *) ((char *) a->buf[!curr]  + i * a->msize);
2204
2205                 if (!sfcc->fchost_name[0])
2206                         /* We are at the end of the list */
2207                         break;
2208
2209                 if (sep)
2210                         printf(",\n");
2211
2212                 sep = TRUE;
2213
2214                 xprintf0(tab, "{\"fchost\": \"%s\", "
2215                          "\"fch_rxf\": %.2f, "
2216                          "\"fch_txf\": %.2f, "
2217                          "\"fch_rxw\": %.2f, "
2218                          "\"fch_txw\": %.2f}",
2219                          sfcc->fchost_name,
2220                          S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv),
2221                          S_VALUE(sfcp->f_txframes, sfcc->f_txframes, itv),
2222                          S_VALUE(sfcp->f_rxwords,  sfcc->f_rxwords,  itv),
2223                          S_VALUE(sfcp->f_txwords,  sfcc->f_txwords,  itv));
2224         }
2225
2226         printf("\n");
2227         xprintf0(--tab, "]");
2228
2229         tab --;
2230
2231 close_json_markup:
2232         if (CLOSE_MARKUP(a->options)) {
2233                 json_markup_network(tab, CLOSE_JSON_MARKUP);
2234         }
2235 }
2236
2237 /*
2238  ***************************************************************************
2239  * Display softnet statistics in JSON.
2240  *
2241  * IN:
2242  * @a           Activity structure with statistics.
2243  * @curr        Index in array for current sample statistics.
2244  * @tab         Indentation in output.
2245  * @itv         Interval of time in jiffies.
2246  ***************************************************************************
2247  */
2248 __print_funct_t json_print_softnet_stats(struct activity *a, int curr, int tab,
2249                                          unsigned long long itv)
2250 {
2251         if (!IS_SELECTED(a->options) || (a->nr <= 0))
2252                 goto close_json_markup;
2253
2254         json_markup_network(tab, OPEN_JSON_MARKUP);
2255
2256         /* FIXME */
2257
2258 close_json_markup:
2259         if (CLOSE_MARKUP(a->options)) {
2260                 json_markup_network(tab, CLOSE_JSON_MARKUP);
2261         }
2262 }