forked from sysstat/sysstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sadf_misc.c
1672 lines (1506 loc) · 50 KB
/
sadf_misc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* sadf_misc.c: Funtions used by sadf to display special records
* (C) 2011-2019 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *
***************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "sadf.h"
#include "pcp_def_metrics.h"
#ifdef USE_NLS
#include <locale.h>
#include <libintl.h>
#define _(string) gettext(string)
#else
#define _(string) (string)
#endif
#ifdef HAVE_PCP
#include <pcp/pmapi.h>
#include <pcp/import.h>
#endif
extern char *tzname[2];
extern unsigned int flags;
extern char *seps[];
extern int palette;
extern unsigned int svg_colors[][SVG_COL_PALETTE_SIZE];
/*
***************************************************************************
* Flush data to PCP archive.
*
* IN:
* @record_hdr Record header for current sample.
* @flags Flags for common options.
***************************************************************************
*/
void pcp_write_data(struct record_header *record_hdr, unsigned int flags)
{
#ifdef HAVE_PCP
int rc;
struct tm lrectime;
unsigned long long utc_sec = record_hdr->ust_time;
static long long delta_utc = LONG_MAX;
if (!PRINT_LOCAL_TIME(flags)) {
if (delta_utc == LONG_MAX) {
/* Convert a time_t value from local time to UTC */
if (gmtime_r((const time_t *) &(record_hdr->ust_time), &lrectime)) {
utc_sec = mktime(&lrectime);
delta_utc = utc_sec - record_hdr->ust_time;
}
}
else {
/*
* Once pmiWrite() has been called (after the first stats sample),
* subsequent mktime() calls will not give the same result with
* the same input data. So compute a time shift that will be used
* for the next samples.
* We should (really) be careful if pmiWrite() was to be used sooner
* than for the first stats sample (e.g. if we want to save a
* LINUX RESTART record heading the file).
*/
utc_sec += delta_utc;
}
}
/* Write data to PCP archive */
if ((rc = pmiWrite(utc_sec, 0)) < 0) {
fprintf(stderr, "PCP: pmiWrite: %s\n", pmiErrStr(rc));
exit(4);
}
#endif
}
/*
***************************************************************************
* Display restart messages (database and ppc formats).
*
* IN:
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @sep Character used as separator.
* @file_hdr System activity file standard header.
***************************************************************************
*/
void print_dbppc_restart(char *cur_date, char *cur_time, int utc, char sep,
struct file_header *file_hdr)
{
printf("%s%c-1%c", file_hdr->sa_nodename, sep, sep);
if (strlen(cur_date)) {
printf("%s ", cur_date);
}
printf("%s", cur_time);
if (strlen(cur_date) && utc) {
printf(" UTC");
}
printf("%cLINUX-RESTART\t(%d CPU)\n",
sep, file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
}
/*
***************************************************************************
* Display restart messages (ppc format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_db_restart(int *tab, int action, char *cur_date,
char *cur_time, int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action == F_MAIN) {
print_dbppc_restart(cur_date, cur_time, utc, ';', file_hdr);
}
}
/*
***************************************************************************
* Display restart messages (database format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_ppc_restart(int *tab, int action, char *cur_date,
char *cur_time, int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action == F_MAIN) {
print_dbppc_restart(cur_date, cur_time, utc, '\t', file_hdr);
}
}
/*
***************************************************************************
* Display restart messages (XML format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_xml_restart(int *tab, int action, char *cur_date,
char *cur_time, int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
if (action & F_BEGIN) {
xprintf((*tab)++, "<restarts>");
}
if (action & F_MAIN) {
xprintf(*tab, "<boot date=\"%s\" time=\"%s\" utc=\"%d\" cpu_count=\"%d\"/>",
cur_date, cur_time, utc ? 1 : 0,
file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
}
if (action & F_END) {
xprintf(--(*tab), "</restarts>");
}
}
/*
***************************************************************************
* Display restart messages (JSON format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_json_restart(int *tab, int action, char *cur_date,
char *cur_time, int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
static int sep = FALSE;
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"restarts\": [");
}
if (action & F_MAIN) {
if (sep) {
printf(",\n");
}
xprintf((*tab)++, "{");
xprintf(*tab, "\"boot\": {\"date\": \"%s\", \"time\": \"%s\", \"utc\": %d, \"cpu_count\": %d}",
cur_date, cur_time, utc ? 1 : 0,
file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
xprintf0(--(*tab), "}");
sep = TRUE;
}
if (action & F_END) {
if (sep) {
printf("\n");
sep = FALSE;
}
xprintf0(--(*tab), "]");
}
}
/*
***************************************************************************
* Display restart messages (raw format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_raw_restart(int *tab, int action, char *cur_date,
char *cur_time, int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action == F_MAIN) {
printf("%s", cur_time);
if (strlen(cur_date) && utc) {
printf(" UTC");
}
printf("; LINUX-RESTART (%d CPU)\n",
file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
}
}
/*
***************************************************************************
* Display restart messages (PCP format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message (unused here).
* @cur_time Time string of current restart message (unused here).
* @utc True if @cur_time is expressed in UTC (unused here).
* @file_hdr System activity file standard header.
* @record_hdr Current record header.
***************************************************************************
*/
__printf_funct_t print_pcp_restart(int *tab, int action, char *cur_date, char *cur_time,
int utc, struct file_header *file_hdr,
struct record_header *record_hdr)
{
#ifdef HAVE_PCP
static int def_metrics = FALSE;
char buf[64];
if (action & F_BEGIN) {
if (!def_metrics) {
pmiAddMetric("system.restart.count",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_DISCRETE,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));
pmiAddMetric("system.restart.ncpu",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_DISCRETE,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));
def_metrics = TRUE;
}
}
if (action & F_MAIN) {
pmiPutValue("system.restart.count", NULL, "1");
snprintf(buf, sizeof(buf), "%u",
file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
pmiPutValue("system.restart.ncpu", NULL, buf);
/* Write data to PCP archive */
pcp_write_data(record_hdr, flags);
}
#endif /* HAVE_PCP */
}
/*
***************************************************************************
* Display comments (database and ppc formats).
*
* IN:
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @sep Character used as separator.
* @file_hdr System activity file standard header.
***************************************************************************
*/
void print_dbppc_comment(char *cur_date, char *cur_time, int utc,
char *comment, char sep, struct file_header *file_hdr)
{
printf("%s%c-1%c", file_hdr->sa_nodename, sep, sep);
if (strlen(cur_date)) {
printf("%s ", cur_date);
}
printf("%s", cur_time);
if (strlen(cur_date) && utc) {
printf(" UTC");
}
printf("%cCOM %s\n", sep, comment);
}
/*
***************************************************************************
* Display comments (database format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_db_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action & F_MAIN) {
print_dbppc_comment(cur_date, cur_time, utc, comment,
';', file_hdr);
}
}
/*
***************************************************************************
* Display comments (ppc format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @file_hdr System activity file standard header.
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_ppc_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action & F_MAIN) {
print_dbppc_comment(cur_date, cur_time, utc, comment,
'\t', file_hdr);
}
}
/*
***************************************************************************
* Display comments (XML format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current comment.
* @cur_time Time string of current comment.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @file_hdr System activity file standard header (unused here).
* @record_hdr Current record header (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_xml_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
if (action & F_BEGIN) {
xprintf((*tab)++, "<comments>");
}
if (action & F_MAIN) {
xprintf(*tab, "<comment date=\"%s\" time=\"%s\" utc=\"%d\" com=\"%s\"/>",
cur_date, cur_time, utc ? 1 : 0, comment);
}
if (action & F_END) {
xprintf(--(*tab), "</comments>");
}
}
/*
***************************************************************************
* Display comments (JSON format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current comment.
* @cur_time Time string of current comment.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @file_hdr System activity file standard header (unused here).
* @record_hdr Current record header (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_json_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
static int sep = FALSE;
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"comments\": [");
}
if (action & F_MAIN) {
if (sep) {
printf(",\n");
}
xprintf((*tab)++, "{");
xprintf(*tab,
"\"comment\": {\"date\": \"%s\", \"time\": \"%s\", "
"\"utc\": %d, \"com\": \"%s\"}",
cur_date, cur_time, utc ? 1 : 0, comment);
xprintf0(--(*tab), "}");
sep = TRUE;
}
if (action & F_END) {
if (sep) {
printf("\n");
sep = FALSE;
}
xprintf0(--(*tab), "]");
}
}
/*
***************************************************************************
* Display comments (raw format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message.
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @comment Comment to display.
* @file_hdr System activity file standard header (unused here).
* @record_hdr Current record header (unused here).
***************************************************************************
*/
__printf_funct_t print_raw_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
/* Actions F_BEGIN and F_END ignored */
if (action & F_MAIN) {
printf("%s", cur_time);
if (strlen(cur_date) && utc) {
printf(" UTC");
}
printf("; COM %s\n", comment);
}
}
/*
***************************************************************************
* Display comments (PCP format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @cur_date Date string of current restart message (unused here).
* @cur_time Time string of current restart message (unused here).
* @utc True if @cur_time is expressed in UTC (unused here).
* @comment Comment to display.
* @file_hdr System activity file standard header (unused here).
* @record_hdr Current record header.
***************************************************************************
*/
__printf_funct_t print_pcp_comment(int *tab, int action, char *cur_date, char *cur_time,
int utc, char *comment, struct file_header *file_hdr,
struct record_header *record_hdr)
{
#ifdef HAVE_PCP
static int def_metrics = FALSE;
if (action & F_BEGIN) {
if (!def_metrics) {
pmiAddMetric("system.comment.value",
PM_IN_NULL, PM_TYPE_STRING, PM_INDOM_NULL, PM_SEM_DISCRETE,
pmiUnits(0, 0, 0, 0, 0, 0));
def_metrics = TRUE;
}
}
if (action & F_MAIN) {
pmiPutValue("system.comment.value", NULL, comment);
/* Write data to PCP archive */
pcp_write_data(record_hdr, flags);
}
#endif /* HAVE_PCP */
}
/*
***************************************************************************
* Display the "statistics" part of the report (XML format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @act Array of activities (unused here).
* @id_seq Activity sequence (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_xml_statistics(int *tab, int action, struct activity *act[],
unsigned int id_seq[])
{
if (action & F_BEGIN) {
xprintf((*tab)++, "<statistics>");
}
if (action & F_END) {
xprintf(--(*tab), "</statistics>");
}
}
/*
***************************************************************************
* Display the "statistics" part of the report (JSON format).
*
* IN:
* @tab Number of tabulations.
* @action Action expected from current function.
* @act Array of activities (unused here).
* @id_seq Activity sequence (unused here).
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_json_statistics(int *tab, int action, struct activity *act[],
unsigned int id_seq[])
{
static int sep = FALSE;
if (action & F_BEGIN) {
printf(",\n");
xprintf((*tab)++, "\"statistics\": [");
}
if (action & F_MAIN) {
if (sep) {
xprintf(--(*tab), "},");
}
xprintf((*tab)++, "{");
sep = TRUE;
}
if (action & F_END) {
if (sep) {
xprintf(--(*tab), "}");
sep = FALSE;
}
xprintf0(--(*tab), "]");
}
}
/*
***************************************************************************
* Display the "statistics" part of the report (PCP format).
*
* IN:
* @tab Number of tabulations (unused here).
* @action Action expected from current function.
* @act Array of activities.
* @id_seq Activity sequence.
***************************************************************************
*/
__printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act[],
unsigned int id_seq[])
{
#ifdef HAVE_PCP
int i, p;
if (action & F_BEGIN) {
for (i = 0; i < NR_ACT; i++) {
if (!id_seq[i])
continue; /* Activity not in file */
p = get_activity_position(act, id_seq[i], EXIT_IF_NOT_FOUND);
if (!IS_SELECTED(act[p]->options))
continue; /* Activity not selected */
switch (act[p]->id) {
case A_CPU:
case A_PWR_CPU:
case A_NET_SOFT:
pcp_def_cpu_metrics(act[p]);
break;
case A_PCSW:
pcp_def_pcsw_metrics();
break;
case A_IRQ:
pcp_def_irq_metrics(act[p]);
break;
case A_SWAP:
pcp_def_swap_metrics();
break;
case A_PAGE:
pcp_def_paging_metrics();
break;
case A_IO:
pcp_def_io_metrics();
break;
case A_MEMORY:
pcp_def_memory_metrics(act[p]);
break;
case A_KTABLES:
pcp_def_ktables_metrics();
break;
case A_QUEUE:
pcp_def_queue_metrics();
break;
case A_SERIAL:
pcp_def_serial_metrics(act[p]);
break;
case A_DISK:
pcp_def_disk_metrics(act[p]);
break;
case A_NET_DEV:
case A_NET_EDEV:
pcp_def_net_dev_metrics(act[p]);
break;
case A_NET_NFS:
pcp_def_net_nfs_metrics();
break;
case A_NET_NFSD:
pcp_def_net_nfsd_metrics();
break;
case A_NET_SOCK:
pcp_def_net_sock_metrics();
break;
case A_NET_IP:
pcp_def_net_ip_metrics();
break;
case A_NET_EIP:
pcp_def_net_eip_metrics();
break;
case A_NET_ICMP:
pcp_def_net_icmp_metrics();
break;
case A_NET_EICMP:
pcp_def_net_eicmp_metrics();
break;
case A_NET_TCP:
pcp_def_net_tcp_metrics();
break;
case A_NET_ETCP:
pcp_def_net_etcp_metrics();
break;
case A_NET_UDP:
pcp_def_net_udp_metrics();
break;
case A_NET_SOCK6:
pcp_def_net_sock6_metrics();
break;
case A_NET_IP6:
pcp_def_net_ip6_metrics();
break;
case A_NET_EIP6:
pcp_def_net_eip6_metrics();
break;
case A_NET_ICMP6:
pcp_def_net_icmp6_metrics();
break;
case A_NET_EICMP6:
pcp_def_net_eicmp6_metrics();
break;
case A_NET_UDP6:
pcp_def_net_udp6_metrics();
break;
case A_HUGE:
pcp_def_huge_metrics();
break;
case A_PWR_FAN:
pcp_def_pwr_fan_metrics(act[p]);
break;
case A_PWR_TEMP:
pcp_def_pwr_temp_metrics(act[p]);
break;
case A_PWR_IN:
pcp_def_pwr_in_metrics(act[p]);
break;
case A_PWR_USB:
pcp_def_pwr_usb_metrics(act[p]);
break;
case A_FS:
pcp_def_filesystem_metrics(act[p]);
break;
case A_NET_FC:
pcp_def_fchost_metrics(act[p]);
break;
}
}
}
#endif /* HAVE_PCP */
}
/*
***************************************************************************
* Display the "timestamp" part of the report (db and ppc format).
*
* IN:
* @fmt Output format (F_DB_OUTPUT or F_PPC_OUTPUT).
* @file_hdr System activity file standard header.
* @cur_date Date string of current record.
* @cur_time Time string of current record.
* @utc True if @cur_time is expressed in UTC.
* @itv Interval of time with preceding record.
*
* RETURNS:
* Pointer on the "timestamp" string.
***************************************************************************
*/
char *print_dbppc_timestamp(int fmt, struct file_header *file_hdr, char *cur_date,
char *cur_time, int utc, unsigned long long itv)
{
int isdb = (fmt == F_DB_OUTPUT);
static char pre[512];
char temp1[128], temp2[256];
/* This substring appears on every output line, preformat it here */
snprintf(temp1, sizeof(temp1), "%s%s%lld%s",
file_hdr->sa_nodename, seps[isdb], itv, seps[isdb]);
if (strlen(cur_date)) {
snprintf(temp2, sizeof(temp2), "%s%s ", temp1, cur_date);
}
else {
strcpy(temp2, temp1);
}
snprintf(pre, sizeof(pre), "%s%s%s", temp2, cur_time,
strlen(cur_date) && utc ? " UTC" : "");
pre[sizeof(pre) - 1] = '\0';
if (DISPLAY_HORIZONTALLY(flags)) {
printf("%s", pre);
}
return pre;
}
/*
***************************************************************************
* Display the "timestamp" part of the report (ppc format).
*
* IN:
* @parm Pointer on specific parameters (unused here).
* @action Action expected from current function.
* @cur_date Date string of current record.
* @cur_time Time string of current record.
* @itv Interval of time with preceding record.
* @record_hdr Record header for current sample (unused here).
* @file_hdr System activity file standard header.
* @flags Flags for common options.
*
* RETURNS:
* Pointer on the "timestamp" string.
***************************************************************************
*/
__tm_funct_t print_ppc_timestamp(void *parm, int action, char *cur_date,
char *cur_time, unsigned long long itv,
struct record_header *record_hdr,
struct file_header *file_hdr, unsigned int flags)
{
int utc = !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags);
if (action & F_BEGIN) {
return print_dbppc_timestamp(F_PPC_OUTPUT, file_hdr, cur_date, cur_time, utc, itv);
}
if (action & F_END) {
if (DISPLAY_HORIZONTALLY(flags)) {
printf("\n");
}
}
return NULL;
}
/*
***************************************************************************
* Display the "timestamp" part of the report (db format).
*
* IN:
* @parm Pointer on specific parameters (unused here).
* @action Action expected from current function.
* @cur_date Date string of current record.
* @cur_time Time string of current record.
* @itv Interval of time with preceding record.
* @record_hdr Record header for current sample (unused here).
* @file_hdr System activity file standard header.
* @flags Flags for common options.
*
* RETURNS:
* Pointer on the "timestamp" string.
***************************************************************************
*/
__tm_funct_t print_db_timestamp(void *parm, int action, char *cur_date,
char *cur_time, unsigned long long itv,
struct record_header *record_hdr,
struct file_header *file_hdr, unsigned int flags)
{
int utc = !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags);
if (action & F_BEGIN) {
return print_dbppc_timestamp(F_DB_OUTPUT, file_hdr, cur_date, cur_time, utc, itv);
}
if (action & F_END) {
if (DISPLAY_HORIZONTALLY(flags)) {
printf("\n");
}
}
return NULL;
}
/*
***************************************************************************
* Display the "timestamp" part of the report (XML format).
*
* IN:
* @parm Specific parameter. Here: number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current comment.
* @cur_time Time string of current comment.
* @itv Interval of time with preceding record.
* @record_hdr Record header for current sample (unused here).
* @file_hdr System activity file standard header (unused here).
* @flags Flags for common options.
***************************************************************************
*/
__tm_funct_t print_xml_timestamp(void *parm, int action, char *cur_date,
char *cur_time, unsigned long long itv,
struct record_header *record_hdr,
struct file_header *file_hdr, unsigned int flags)
{
int utc = !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags);
int *tab = (int *) parm;
if (action & F_BEGIN) {
xprintf((*tab)++, "<timestamp date=\"%s\" time=\"%s\" utc=\"%d\" interval=\"%llu\">",
cur_date, cur_time, utc ? 1 : 0, itv);
}
if (action & F_END) {
xprintf(--(*tab), "</timestamp>");
}
return NULL;
}
/*
***************************************************************************
* Display the "timestamp" part of the report (JSON format).
*
* IN:
* @parm Specific parameter. Here: number of tabulations.
* @action Action expected from current function.
* @cur_date Date string of current comment.
* @cur_time Time string of current comment.
* @itv Interval of time with preceding record.
* @record_hdr Record header for current sample (unused here).
* @file_hdr System activity file standard header (unused here).
* @flags Flags for common options.
***************************************************************************
*/
__tm_funct_t print_json_timestamp(void *parm, int action, char *cur_date,
char *cur_time, unsigned long long itv,
struct record_header *record_hdr,
struct file_header *file_hdr, unsigned int flags)
{
int utc = !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags);
int *tab = (int *) parm;
if (action & F_BEGIN) {
xprintf0(*tab,
"\"timestamp\": {\"date\": \"%s\", \"time\": \"%s\", "
"\"utc\": %d, \"interval\": %llu}",
cur_date, cur_time, utc ? 1 : 0, itv);
}
if (action & F_MAIN) {
printf(",\n");
}
if (action & F_END) {
printf("\n");
}
return NULL;
}
/*
***************************************************************************
* Display the "timestamp" part of the report (raw format).
*
* IN:
* @parm Pointer on specific parameters (unused here).
* @action Action expected from current function.
* @cur_date Date string of current record.
* @cur_time Time string of current record.
* @itv Interval of time with preceding record (unused here).