]> granicus.if.org Git - sysstat/blob - sadf.h
sadf: Create read_next_sample() function
[sysstat] / sadf.h
1 /*
2  * sadf: System activity data formatter
3  * (C) 1999-2015 by Sebastien Godard (sysstat <at> orange.fr)
4  */
5
6 #ifndef _SADF_H
7 #define _SADF_H
8
9 #include "sa.h"
10
11 /* DTD version for XML output */
12 #define XML_DTD_VERSION "3.1"
13
14 /* Possible actions for functions used to display reports */
15 #define F_BEGIN 0x01
16 #define F_MAIN  0x02
17 #define F_END   0x04
18
19 /* Various constants */
20 #define DO_SAVE         0
21 #define DO_RESTORE      1
22
23 #define IGNORE_NOTHING          0
24 #define IGNORE_RESTART          1
25 #define DONT_READ_VOLATILE      2
26 #define IGNORE_COMMENT          4
27
28 /*
29  ***************************************************************************
30  * Output format identification values.
31  ***************************************************************************
32  */
33
34 /* Number of output formats */
35 #define NR_FMT  6
36
37 /* Output formats */
38 #define F_DB_OUTPUT     1
39 #define F_HEADER_OUTPUT 2
40 #define F_PPC_OUTPUT    3
41 #define F_XML_OUTPUT    4
42 #define F_JSON_OUTPUT   5
43 #define F_CONV_OUTPUT   6
44
45 /*
46  ***************************************************************************
47  * Generic description of an output format.
48  ***************************************************************************
49  */
50
51 /* Format options */
52
53 /*
54  * Indicate that all statistics data for one activity should be displayed before
55  * displaying stats for next activity. This is what sar does in its report.
56  * Example: If stats for activities A and B at time t and t' have been collected,
57  * setting AO_GROUPED_STATS for a format will result in the following output:
58  * stats for activity A at t
59  * stats for activity A at t'
60  * stats for activity B at t
61  * stats for activity B at t'
62  * Without this option, output would be:
63  * stats for activity A at t
64  * stats for activity B at t
65  * stats for activity A at t'
66  * stats for activity B at t'
67  */
68 #define FO_GROUPED_STATS        0x01
69
70 /*
71  * Indicate that output should stop after the header is displayed.
72  */
73 #define FO_HEADER_ONLY          0x02
74
75 /*
76  * Indicate that a true sysstat activity file but with a bad
77  * format should not yield an error message.
78  */
79 #define FO_BAD_FILE_FORMAT      0x04
80
81 /*
82  * Indicate that timestamp can be displayed in local time instead of UTC
83  * if option -T or -t has been used.
84  */
85 #define FO_LOCAL_TIME           0x08
86
87 /*
88  * Indicate that all activities will be displayed horizontally
89  * if option -h is used.
90  */
91 #define FO_HORIZONTALLY         0x10
92
93 /*
94  * Indicate that the timestamp can be displayed in seconds since the epoch
95  * if option -U has been used.
96  */
97 #define FO_SEC_EPOCH            0x20
98
99 /*
100  * Indicate that the list of fields should be displayed before the first
101  * line of statistics.
102  */
103 #define FO_FIELD_LIST           0x40
104
105 #define DISPLAY_GROUPED_STATS(m)        (((m) & FO_GROUPED_STATS)       == FO_GROUPED_STATS)
106 #define ACCEPT_HEADER_ONLY(m)           (((m) & FO_HEADER_ONLY)         == FO_HEADER_ONLY)
107 #define ACCEPT_BAD_FILE_FORMAT(m)       (((m) & FO_BAD_FILE_FORMAT)     == FO_BAD_FILE_FORMAT)
108 #define ACCEPT_LOCAL_TIME(m)            (((m) & FO_LOCAL_TIME)          == FO_LOCAL_TIME)
109 #define ACCEPT_HORIZONTALLY(m)          (((m) & FO_HORIZONTALLY)        == FO_HORIZONTALLY)
110 #define ACCEPT_SEC_EPOCH(m)             (((m) & FO_SEC_EPOCH)           == FO_SEC_EPOCH)
111 #define DISPLAY_FIELD_LIST(m)           (((m) & FO_FIELD_LIST)          == FO_FIELD_LIST)
112
113 /* Type for all functions used by sadf to display stats in various formats */
114 #define __printf_funct_t void
115
116 /*
117  * Structure used to define a report.
118  * A XML-like report has the following format:
119  *       __
120  *      |
121  *      | Header block
122  *      |  __
123  *      | |
124  *      | | Statistics block
125  *      | |  __
126  *      | | |
127  *      | | | Timestamp block
128  *      | | |  __
129  *      | | | |
130  *      | | | | Activity #1
131  *      | | | |__
132  *      | | | |
133  *      | | | | ...
134  *      | | | |__
135  *      | | | |
136  *      | | | | Activity #n
137  *      | | | |__
138  *      | | |__
139  *      | |__
140  *      | |
141  *      | | Restart messages block
142  *      | |__
143  *      | |
144  *      | | Comments block
145  *      | |__
146  *      |__
147  */
148 struct report_format {
149         /*
150          * This variable contains the identification value (F_...) for this report format.
151          */
152         unsigned int id;
153         /*
154          * Format options (FO_...).
155          */
156         unsigned int options;
157         /*
158          * This function displays the report header
159          * (data displayed once at the beginning of the report).
160          */
161         __printf_funct_t (*f_header) (int *, int, char *, struct file_magic *, struct file_header *,
162                                       __nr_t, struct activity * [], unsigned int []);
163         /*
164          * This function defines the statistics part of the report.
165          * Used only with textual (XML-like) reports.
166          */
167         __printf_funct_t (*f_statistics) (int *, int);
168         /*
169          * This function defines the timestamp part of the report.
170          * Used only with textual (XML-like) reports.
171          */
172         __printf_funct_t (*f_timestamp) (int *, int, char *, char *, int, unsigned long long);
173         /*
174          * This function displays the restart messages.
175          */
176         __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
177                                        unsigned int);
178         /*
179          * This function displays the comments.
180          */
181         __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
182 };
183
184 /*
185  ***************************************************************************
186  * Various function prototypes
187  ***************************************************************************
188  */
189
190 extern void
191         convert_file(char [], struct activity *[]);
192 extern void
193         xprintf(int, const char *, ...);
194 extern void
195         xprintf0(int, const char *, ...);
196
197 /*
198  * Prototypes used to display restart messages
199  */
200 __printf_funct_t
201         print_db_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
202 __printf_funct_t
203         print_ppc_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
204 __printf_funct_t
205         print_xml_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
206 __printf_funct_t
207         print_json_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
208
209 /*
210  * Prototypes used to display comments
211  */
212 __printf_funct_t
213         print_db_comment(int *, int, char *, char *, int, char *, struct file_header *);
214 __printf_funct_t
215         print_ppc_comment(int *, int, char *, char *, int, char *, struct file_header *);
216 __printf_funct_t
217         print_xml_comment(int *, int, char *, char *, int, char *, struct file_header *);
218 __printf_funct_t
219         print_json_comment(int *, int, char *, char *, int, char *, struct file_header *);
220
221 /*
222  * Prototypes used to display the statistics part of the report
223  */
224 __printf_funct_t
225         print_xml_statistics(int *, int);
226 __printf_funct_t
227         print_json_statistics(int *, int);
228
229 /*
230  * Prototypes used to display the timestamp part of the report
231  */
232 __printf_funct_t
233         print_xml_timestamp(int *, int, char *, char *, int, unsigned long long);
234 __printf_funct_t
235         print_json_timestamp(int *, int, char *, char *, int, unsigned long long);
236
237 /*
238  * Prototypes used to display the report header
239  */
240 __printf_funct_t
241         print_xml_header(int *, int, char *, struct file_magic *, struct file_header *,
242                          __nr_t, struct activity * [], unsigned int []);
243 __printf_funct_t
244         print_json_header(int *, int, char *, struct file_magic *, struct file_header *,
245                           __nr_t, struct activity * [], unsigned int []);
246 __printf_funct_t
247         print_hdr_header(int *, int, char *, struct file_magic *, struct file_header *,
248                          __nr_t, struct activity * [], unsigned int []);
249
250 #endif  /* _SADF_H */