2 * sysstat: System performance tools for Linux
3 * (C) 1999-2016 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 */
16 #ifdef HAVE_SYS_SYSMACROS_H
17 /* Needed on some non-glibc environments */
18 #include <sys/sysmacros.h>
24 ***************************************************************************
25 * Various keywords and constants
26 ***************************************************************************
32 #define PLAIN_OUTPUT 0
36 /* Timestamp buffer length */
37 #define TIMESTAMP_LEN 64
39 /* Number of seconds per day */
40 #define SEC_PER_DAY 3600 * 24
42 /* Maximum number of CPUs */
43 #if defined(__CPU_SETSIZE) && __CPU_SETSIZE > 8192
44 #define NR_CPUS __CPU_SETSIZE
49 /* Maximum number of interrupts */
52 /* Size of /proc/interrupts line, CPU data excluded */
53 #define INTERRUPTS_LINE 128
62 #define STAT "/proc/stat"
63 #define UPTIME "/proc/uptime"
64 #define DISKSTATS "/proc/diskstats"
65 #define INTERRUPTS "/proc/interrupts"
66 #define MEMINFO "/proc/meminfo"
67 #define SYSFS_BLOCK "/sys/block"
68 #define SYSFS_DEV_BLOCK "/sys/dev/block"
69 #define SYSFS_DEVCPU "/sys/devices/system/cpu"
70 #define SYSFS_TIME_IN_STATE "cpufreq/stats/time_in_state"
72 #define DEVMAP_DIR "/dev/mapper"
73 #define DEVICES "/proc/devices"
74 #define SYSFS_USBDEV "/sys/bus/usb/devices"
75 #define DEV_DISK_BY "/dev/disk/by"
76 #define SYSFS_IDVENDOR "idVendor"
77 #define SYSFS_IDPRODUCT "idProduct"
78 #define SYSFS_BMAXPOWER "bMaxPower"
79 #define SYSFS_MANUFACTURER "manufacturer"
80 #define SYSFS_PRODUCT "product"
81 #define SYSFS_FCHOST "/sys/class/fc_host"
83 #define MAX_FILE_LEN 256
84 #define MAX_PF_NAME 1024
85 #define MAX_NAME_LEN 128
87 #define IGNORE_VIRTUAL_DEVICES FALSE
88 #define ACCEPT_VIRTUAL_DEVICES TRUE
90 /* Environment variables */
91 #define ENV_TIME_FMT "S_TIME_FORMAT"
92 #define ENV_TIME_DEFTM "S_TIME_DEF_TIME"
93 #define ENV_COLORS "S_COLORS"
94 #define ENV_COLORS_SGR "S_COLORS_SGR"
96 #define C_NEVER "never"
97 #define C_ALWAYS "always"
99 #define DIGITS "0123456789"
102 ***************************************************************************
103 * Macro functions definitions.
104 ***************************************************************************
107 /* Allocate and init structure */
108 #define SREALLOC(S, TYPE, SIZE) do { \
112 if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
116 /* If the ptr was null, then it's a malloc() */ \
118 memset(S, 0, (SIZE)); \
122 /* Should never happen */ \
123 fprintf(stderr, "srealloc\n"); \
129 * Macros used to display statistics values.
131 * NB: Define SP_VALUE() to normalize to %;
132 * HZ is 1024 on IA64 and % should be normalized to 100.
133 * SP_VALUE_100() will not output value bigger than 100; this is needed for some
134 * corner cases, should be used with care.
136 #define S_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * HZ)
137 #define SP_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100)
138 #define SP_VALUE_100(m,n,p) MINIMUM((((double) ((n) - (m))) / (p) * 100), 100.0)
141 * Under very special circumstances, STDOUT may become unavailable.
142 * This is what we try to guess here.
144 #define TEST_STDOUT(_fd_) do { \
145 if (write(_fd_, "", 0) == -1) { \
151 #define MINIMUM(a,b) ((a) < (b) ? (a) : (b))
153 #define PANIC(m) sysstat_panic(__FUNCTION__, m)
155 /* Number of ticks per second */
157 extern unsigned int hz;
159 /* Number of bit shifts to convert pages to kB */
160 extern unsigned int kb_shift;
163 * kB <-> number of pages.
164 * Page size depends on machine architecture (4 kB, 8 kB, 16 kB, 64 kB...)
166 #define KB_TO_PG(k) ((k) >> kb_shift)
167 #define PG_TO_KB(k) ((k) << kb_shift)
169 /* Type of persistent device names used in sar and iostat */
170 extern char persistent_name_type[MAX_FILE_LEN];
173 ***************************************************************************
175 ***************************************************************************
178 #define C_LIGHT_RED "\e[31;22m"
179 #define C_BOLD_RED "\e[31;1m"
180 #define C_LIGHT_GREEN "\e[32;22m"
181 #define C_LIGHT_YELLOW "\e[33;22m"
182 #define C_BOLD_YELLOW "\e[33;1m"
183 #define C_BOLD_BLUE "\e[34;1m"
184 #define C_LIGHT_CYAN "\e[36;22m"
185 #define C_NORMAL "\e[0m"
187 #define PERCENT_LIMIT_HIGH 75.0
188 #define PERCENT_LIMIT_LOW 50.0
190 #define MAX_SGR_LEN 16
199 ***************************************************************************
200 * Structures definitions
201 ***************************************************************************
204 /* Structure used for extended disk statistics */
205 struct ext_disk_stats {
213 ***************************************************************************
214 * Functions prototypes
215 ***************************************************************************
218 void compute_ext_disk_stats
219 (struct stats_disk *, struct stats_disk *, unsigned long long,
220 struct ext_disk_stats *);
226 (int, int, int, ...);
228 (int, char *, char *, int);
230 (int, int, int, ...);
232 (int, char *, char *);
241 unsigned int get_devmap_major
243 unsigned long long get_interval
244 (unsigned long long, unsigned long long);
251 unsigned long long get_per_cpu_interval
252 (struct stats_cpu *, struct stats_cpu *);
253 char *get_persistent_name_from_pretty
255 char *get_persistent_type_dir
257 char *get_pretty_name_from_persistent
270 (unsigned long long, unsigned long long, unsigned long long);
274 (struct tm *, char *, char *, char *, char *, int, int);
282 (int, const char *, ...);
284 (int, const char *, ...);
286 #endif /* _COMMON_H */