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 /* Number of seconds per day */
37 #define SEC_PER_DAY 3600 * 24
39 /* Maximum number of CPUs */
40 #if defined(__CPU_SETSIZE) && __CPU_SETSIZE > 8192
41 #define NR_CPUS __CPU_SETSIZE
46 /* Maximum number of interrupts */
49 /* Size of /proc/interrupts line, CPU data excluded */
50 #define INTERRUPTS_LINE 128
58 #define STAT "/proc/stat"
59 #define UPTIME "/proc/uptime"
60 #define DISKSTATS "/proc/diskstats"
61 #define INTERRUPTS "/proc/interrupts"
62 #define MEMINFO "/proc/meminfo"
63 #define SYSFS_BLOCK "/sys/block"
64 #define SYSFS_DEV_BLOCK "/sys/dev/block"
65 #define SYSFS_DEVCPU "/sys/devices/system/cpu"
66 #define SYSFS_TIME_IN_STATE "cpufreq/stats/time_in_state"
68 #define DEVMAP_DIR "/dev/mapper"
69 #define DEVICES "/proc/devices"
70 #define SYSFS_USBDEV "/sys/bus/usb/devices"
71 #define DEV_DISK_BY "/dev/disk/by"
72 #define SYSFS_IDVENDOR "idVendor"
73 #define SYSFS_IDPRODUCT "idProduct"
74 #define SYSFS_BMAXPOWER "bMaxPower"
75 #define SYSFS_MANUFACTURER "manufacturer"
76 #define SYSFS_PRODUCT "product"
77 #define SYSFS_FCHOST "/sys/class/fc_host"
79 #define MAX_FILE_LEN 256
80 #define MAX_PF_NAME 1024
81 #define MAX_NAME_LEN 128
83 #define IGNORE_VIRTUAL_DEVICES FALSE
84 #define ACCEPT_VIRTUAL_DEVICES TRUE
86 /* Environment variables */
87 #define ENV_TIME_FMT "S_TIME_FORMAT"
88 #define ENV_TIME_DEFTM "S_TIME_DEF_TIME"
89 #define ENV_COLORS "S_COLORS"
90 #define ENV_COLORS_SGR "S_COLORS_SGR"
92 #define C_NEVER "never"
93 #define C_ALWAYS "always"
95 #define DIGITS "0123456789"
98 ***************************************************************************
99 * Macro functions definitions.
100 ***************************************************************************
103 /* Allocate and init structure */
104 #define SREALLOC(S, TYPE, SIZE) do { \
108 if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
112 /* If the ptr was null, then it's a malloc() */ \
114 memset(S, 0, (SIZE)); \
118 /* Should never happen */ \
119 fprintf(stderr, "srealloc\n"); \
125 * Macros used to display statistics values.
127 * NB: Define SP_VALUE() to normalize to %;
128 * HZ is 1024 on IA64 and % should be normalized to 100.
129 * SP_VALUE_100() will not output value bigger than 100; this is needed for some
130 * corner cases, should be used with care.
132 #define S_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * HZ)
133 #define SP_VALUE(m,n,p) (((double) ((n) - (m))) / (p) * 100)
134 #define SP_VALUE_100(m,n,p) MINIMUM((((double) ((n) - (m))) / (p) * 100), 100.0)
137 * Under very special circumstances, STDOUT may become unavailable.
138 * This is what we try to guess here.
140 #define TEST_STDOUT(_fd_) do { \
141 if (write(_fd_, "", 0) == -1) { \
147 #define MINIMUM(a,b) ((a) < (b) ? (a) : (b))
149 #define PANIC(m) sysstat_panic(__FUNCTION__, m)
151 /* Number of ticks per second */
153 extern unsigned int hz;
155 /* Number of bit shifts to convert pages to kB */
156 extern unsigned int kb_shift;
159 * kB <-> number of pages.
160 * Page size depends on machine architecture (4 kB, 8 kB, 16 kB, 64 kB...)
162 #define KB_TO_PG(k) ((k) >> kb_shift)
163 #define PG_TO_KB(k) ((k) << kb_shift)
165 /* Type of persistent device names used in sar and iostat */
166 extern char persistent_name_type[MAX_FILE_LEN];
169 ***************************************************************************
171 ***************************************************************************
174 #define C_LIGHT_RED "\e[31;22m"
175 #define C_BOLD_RED "\e[31;1m"
176 #define C_LIGHT_GREEN "\e[32;22m"
177 #define C_LIGHT_YELLOW "\e[33;22m"
178 #define C_BOLD_YELLOW "\e[33;1m"
179 #define C_BOLD_BLUE "\e[34;1m"
180 #define C_LIGHT_CYAN "\e[36;22m"
181 #define C_NORMAL "\e[0m"
183 #define PERCENT_LIMIT_HIGH 75.0
184 #define PERCENT_LIMIT_LOW 50.0
186 #define MAX_SGR_LEN 16
195 ***************************************************************************
196 * Structures definitions
197 ***************************************************************************
200 /* Structure used for extended disk statistics */
201 struct ext_disk_stats {
209 ***************************************************************************
210 * Functions prototypes
211 ***************************************************************************
214 void compute_ext_disk_stats
215 (struct stats_disk *, struct stats_disk *, unsigned long long,
216 struct ext_disk_stats *);
222 (int, int, int, ...);
224 (int, char *, char *, int);
226 (int, int, int, ...);
228 (int, char *, char *);
237 unsigned int get_devmap_major
239 unsigned long long get_interval
240 (unsigned long long, unsigned long long);
247 unsigned long long get_per_cpu_interval
248 (struct stats_cpu *, struct stats_cpu *);
249 char *get_persistent_name_from_pretty
251 char *get_persistent_type_dir
253 char *get_pretty_name_from_persistent
266 (unsigned long long, unsigned long long, unsigned long long);
270 (struct tm *, char *, char *, char *, char *, int, int);
278 (int, const char *, ...);
280 (int, const char *, ...);
282 #endif /* _COMMON_H */