~ubuntu-branches/ubuntu/vivid/sysstat/vivid-proposed

« back to all changes in this revision

Viewing changes to json_stats.c

  • Committer: Package Import Robot
  • Author(s): Robert Luberda
  • Date: 2011-12-03 17:38:42 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20111203173842-9hrhekn3639twx4p
Tags: 10.0.3-1
* New upstream (stable) release.
* Switch to devhelper v9.
* debian/control: Add VCS fields, update source/options.
* debian/rules: remove .pc/.dpkg-source-unapply file in configure target
  to fix broken behaviour of dpkg-buildpackage (see Bug#649521).

Show diffs side-by-side

added added

removed removed

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