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