2 * sysstat: System performance tools for Linux
3 * (C) 1999-2022 by Sebastien Godard (sysstat <at> orange.fr)
9 /* Maximum length of sensors device name */
10 #define MAX_SENSORS_DEV_LEN 20
13 #include <sched.h> /* For __CPU_SETSIZE */
18 #ifdef HAVE_SYS_SYSMACROS_H
19 /* Needed on some non-glibc environments */
20 #include <sys/sysmacros.h>
24 ***************************************************************************
25 * Various keywords and constants
26 ***************************************************************************
32 #define PLAIN_OUTPUT 0
36 /* Index in units array (see common.c) */
40 #define UNIT_KILOBYTE 2
44 /* Timestamp buffer length */
45 #define TIMESTAMP_LEN 64
47 /* Number of seconds per day */
48 #define SEC_PER_DAY 3600 * 24
50 /* Maximum number of CPUs */
51 #if defined(__CPU_SETSIZE) && __CPU_SETSIZE > 8192
52 #define NR_CPUS __CPU_SETSIZE
57 /* Maximum number of interrupts */
60 /* Size of /proc/interrupts line, CPU data excluded */
61 #define INTERRUPTS_LINE 128
66 #define K_LOWERALL "all"
67 #define K_LOWERSUM "sum"
72 #define __DISKSTATS "diskstats"
73 #define __BLOCK "block"
74 #define __DEV_BLOCK "dev/block"
75 #define SLASH_SYS PRE "/sys"
76 #define SLASH_DEV PRE "/dev/"
77 #define STAT PRE "/proc/stat"
78 #define UPTIME PRE "/proc/uptime"
79 #define DISKSTATS PRE "/proc/" __DISKSTATS
80 #define INTERRUPTS PRE "/proc/interrupts"
81 #define MEMINFO PRE "/proc/meminfo"
82 #define SYSFS_BLOCK SLASH_SYS "/" __BLOCK
83 #define SYSFS_DEV_BLOCK SLASH_SYS "/" __DEV_BLOCK
84 #define SYSFS_DEVCPU PRE "/sys/devices/system/cpu"
85 #define SYSFS_TIME_IN_STATE "cpufreq/stats/time_in_state"
87 #define DEVMAP_DIR PRE "/dev/mapper"
88 #define DEVICES PRE "/proc/devices"
89 #define SYSFS_USBDEV PRE "/sys/bus/usb/devices"
90 #define DEV_DISK_BY PRE "/dev/disk/by"
91 #define DEV_DISK_BY_ID PRE "/dev/disk/by-id"
92 #define SYSFS_IDVENDOR "idVendor"
93 #define SYSFS_IDPRODUCT "idProduct"
94 #define SYSFS_BMAXPOWER "bMaxPower"
95 #define SYSFS_MANUFACTURER "manufacturer"
96 #define SYSFS_PRODUCT "product"
97 #define SYSFS_FCHOST PRE "/sys/class/fc_host"
99 #define MAX_FILE_LEN 512
100 #define MAX_PF_NAME 1024
101 #define MAX_NAME_LEN 128
103 #define IGNORE_VIRTUAL_DEVICES FALSE
104 #define ACCEPT_VIRTUAL_DEVICES TRUE
106 /* Environment variables */
107 #define ENV_TIME_FMT "S_TIME_FORMAT"
108 #define ENV_TIME_DEFTM "S_TIME_DEF_TIME"
109 #define ENV_COLORS "S_COLORS"
110 #define ENV_COLORS_SGR "S_COLORS_SGR"
111 #define ENV_REPEAT_HEADER "S_REPEAT_HEADER"
113 #define C_NEVER "never"
114 #define C_ALWAYS "always"
116 #define DIGITS "0123456789"
117 #define XDIGITS "0123456789-"
120 ***************************************************************************
121 * Macro functions definitions.
122 ***************************************************************************
126 * Macro used to define activity bitmap size.
127 * All those bitmaps have an additional bit used for global activity
128 * (eg. CPU "all" or total number of interrupts). That's why we do "(m) + 1".
130 #define BITMAP_SIZE(m) ((((m) + 1) >> 3) + 1)
132 /* Allocate and init structure */
133 #define SREALLOC(S, TYPE, SIZE) do { \
136 if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
140 /* If the ptr was null, then it's a malloc() */ \
142 memset(S, 0, (SIZE)); \
146 /* Should never happen */ \
147 fprintf(stderr, "srealloc\n"); \
153 * Macros used to display statistics values.
156 /* With S_VALUE macro, the interval of time (@p) is given in 1/100th of a second */
157 #define S_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100)
158 /* Define SP_VALUE() to normalize to % */
159 #define SP_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100)
162 * Under very special circumstances, STDOUT may become unavailable.
163 * This is what we try to guess here.
165 #define TEST_STDOUT(_fd_) do { \
166 if (write(_fd_, "", 0) == -1) { \
172 #define MINIMUM(a,b) ((a) < (b) ? (a) : (b))
174 #define PANIC(m) sysstat_panic(__FUNCTION__, m)
176 /* Number of ticks per second */
178 extern unsigned long hz;
180 /* Number of bit shifts to convert pages to kB */
181 extern unsigned int kb_shift;
184 * kB <-> number of pages.
185 * Page size depends on machine architecture (4 kB, 8 kB, 16 kB, 64 kB...)
187 #define KB_TO_PG(k) ((k) >> kb_shift)
188 #define PG_TO_KB(k) ((k) << kb_shift)
190 /* Type of persistent device names used in sar and iostat */
191 extern char persistent_name_type[MAX_FILE_LEN];
194 ***************************************************************************
196 ***************************************************************************
199 #define C_LIGHT_RED "\e[31;22m"
200 #define C_BOLD_RED "\e[31;1m"
201 #define C_LIGHT_GREEN "\e[32;22m"
202 #define C_LIGHT_YELLOW "\e[33;22m"
203 #define C_BOLD_MAGENTA "\e[35;1m"
204 #define C_BOLD_BLUE "\e[34;1m"
205 #define C_LIGHT_BLUE "\e[34;22m"
206 #define C_NORMAL "\e[0m"
208 #define PERCENT_LIMIT_HIGH 75.0
209 #define PERCENT_LIMIT_LOW 50.0
211 #define MAX_SGR_LEN 16
216 #define IS_DEBUG IS_RESTART
221 ***************************************************************************
222 * Structures definitions
223 ***************************************************************************
226 /* Structure used for extended disk statistics */
227 struct ext_disk_stats {
234 ***************************************************************************
235 * Functions prototypes
236 ***************************************************************************
251 (char *, char *, int);
255 (char *, unsigned long long *, unsigned int *);
256 int get_wwnid_from_pretty
257 (char *, unsigned long long *, unsigned int *);
267 (int, int, int, int, ...);
269 (int, char *, char *, int);
271 (int, int, int, int, ...);
273 (int, char *, char *);
275 (int, int, int, ...);
280 char *get_device_name
281 (unsigned int, unsigned int, unsigned long long [],
282 unsigned int, unsigned int, unsigned int, unsigned int, char *);
283 unsigned int get_devmap_major
285 unsigned long long get_interval
286 (unsigned long long, unsigned long long);
287 char *get_persistent_name_from_pretty
289 char *get_persistent_type_dir
291 char *get_pretty_name_from_persistent
300 (unsigned long long, unsigned long long, unsigned long long);
303 int parse_range_values
304 (char *t, int, int *, int *);
306 (char *, unsigned char[], int, const char *);
308 (struct tm *, char *, char *, char *, char *, int, int);
310 (struct tm *, char[], int);
314 (int, const char *, ...);
316 (int, const char *, ...);
318 #endif /* SOURCE_SADC undefined */
319 #endif /* _COMMON_H */