1/*
2 * sysstat: System performance tools for Linux
3 * (C) 1999-2012 by Sebastien Godard (sysstat <at> orange.fr)
4 */
5
6#ifndef _COMMON_H
7#define _COMMON_H
8
9/* Maximum length of sensors device name */
10#define MAX_SENSORS_DEV_LEN	20
11
12#include <time.h>
13#include <sched.h>	/* For __CPU_SETSIZE */
14#include "rd_stats.h"
15
16/*
17 ***************************************************************************
18 * Various keywords and constants
19 ***************************************************************************
20 */
21
22#define FALSE	0
23#define TRUE	1
24
25#define DISP_HDR	1
26
27/* Number of seconds per day */
28#define SEC_PER_DAY	3600 * 24
29
30/* Maximum number of CPUs */
31#ifdef __CPU_SETSIZE
32#define NR_CPUS		__CPU_SETSIZE
33#else
34#define NR_CPUS		1024
35#endif
36
37/* Maximum number of interrupts */
38#define NR_IRQS			256
39
40/* Size of /proc/interrupts line, CPU data excluded */
41#define INTERRUPTS_LINE	128
42
43/* Keywords */
44#define K_ISO	"ISO"
45#define K_ALL	"ALL"
46#define K_UTC	"UTC"
47
48/* Files */
49#define STAT			"/proc/stat"
50#define UPTIME			"/proc/uptime"
51#define PPARTITIONS		"/proc/partitions"
52#define DISKSTATS		"/proc/diskstats"
53#define INTERRUPTS		"/proc/interrupts"
54#define MEMINFO			"/proc/meminfo"
55#define SYSFS_BLOCK		"/sys/block"
56#define SYSFS_DEV_BLOCK		"/sys/dev/block"
57#define SYSFS_DEVCPU		"/sys/devices/system/cpu"
58#define SYSFS_TIME_IN_STATE	"cpufreq/stats/time_in_state"
59#define S_STAT			"stat"
60#define DEVMAP_DIR		"/dev/mapper"
61#define DEVICES			"/proc/devices"
62#define SYSFS_USBDEV		"/sys/bus/usb/devices"
63#define DEV_DISK_BY		"/dev/disk/by"
64#define SYSFS_IDVENDOR		"idVendor"
65#define SYSFS_IDPRODUCT		"idProduct"
66#define SYSFS_BMAXPOWER		"bMaxPower"
67#define SYSFS_MANUFACTURER	"manufacturer"
68#define SYSFS_PRODUCT		"product"
69
70#define MAX_FILE_LEN		256
71#define MAX_PF_NAME		1024
72#define DEFAULT_DEVMAP_MAJOR	253
73#define MAX_NAME_LEN		72
74
75#define NR_DISKS		4
76
77#define IGNORE_VIRTUAL_DEVICES	FALSE
78#define ACCEPT_VIRTUAL_DEVICES	TRUE
79
80/* Environment variables */
81#define ENV_TIME_FMT		"S_TIME_FORMAT"
82#define ENV_TIME_DEFTM		"S_TIME_DEF_TIME"
83
84#define DIGITS			"0123456789"
85
86/*
87 ***************************************************************************
88 * Macro functions definitions.
89 ***************************************************************************
90 */
91
92/* Allocate and init structure */
93#define SREALLOC(S, TYPE, SIZE)	do {								 \
94   					TYPE *_p_;						 \
95				   	_p_ = S;						 \
96   				   	if (SIZE) {						 \
97   				      		if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \
98				         		perror("realloc");			 \
99				         		exit(4);				 \
100				      		}						 \
101				      		/* If the ptr was null, then it's a malloc() */	 \
102   				      		if (!_p_)					 \
103      				         		memset(S, 0, (SIZE));			 \
104				   	}							 \
105				} while (0)
106
107/*
108 * Macros used to display statistics values.
109 *
110 * NB: Define SP_VALUE() to normalize to %;
111 * HZ is 1024 on IA64 and % should be normalized to 100.
112 */
113#define S_VALUE(m,n,p)	(((double) ((n) - (m))) / (p) * HZ)
114#define SP_VALUE(m,n,p)	(((double) ((n) - (m))) / (p) * 100)
115
116/*
117 * Under very special circumstances, STDOUT may become unavailable.
118 * This is what we try to guess here.
119 */
120#define TEST_STDOUT(_fd_)	do {					\
121					if (write(_fd_, "", 0) == -1) {	\
122				        	perror("stdout");	\
123				       		exit(6);		\
124				 	}				\
125				} while (0)
126
127#define MINIMUM(a,b)	((a) < (b) ? (a) : (b))
128
129#ifdef DEBUG
130#define PANIC(m)	sysstat_panic(__FUNCTION__, m)
131#else
132#define PANIC(m)
133#endif
134
135/* Number of ticks per second */
136#define HZ		hz
137extern unsigned int hz;
138
139/* Number of bit shifts to convert pages to kB */
140extern unsigned int kb_shift;
141
142/*
143 * kB <-> number of pages.
144 * Page size depends on machine architecture (4 kB, 8 kB, 16 kB, 64 kB...)
145 */
146#define KB_TO_PG(k)	((k) >> kb_shift)
147#define PG_TO_KB(k)	((k) << kb_shift)
148
149/* Type of persistent device names used in sar and iostat */
150extern char persistent_name_type[MAX_FILE_LEN];
151
152/*
153 ***************************************************************************
154 * Structures definitions
155 ***************************************************************************
156 */
157
158/* Structure used for extended disk statistics */
159struct ext_disk_stats {
160	double util;
161	double await;
162	double svctm;
163	double arqsz;
164};
165
166/*
167 ***************************************************************************
168 * Functions prototypes
169 ***************************************************************************
170 */
171
172extern void
173	compute_ext_disk_stats(struct stats_disk *, struct stats_disk *,
174			       unsigned long long, struct ext_disk_stats *);
175extern int
176	count_bits(void *, int);
177extern int
178	count_csvalues(int, char **);
179extern char *
180	device_name(char *);
181extern void
182	get_HZ(void);
183extern unsigned int
184	get_devmap_major(void);
185extern unsigned long long
186	get_interval(unsigned long long, unsigned long long);
187extern void
188	get_kb_shift(void);
189extern time_t
190	get_localtime(struct tm *, int);
191extern time_t
192	get_time(struct tm *, int);
193unsigned long long
194	get_per_cpu_interval(struct stats_cpu *, struct stats_cpu *);
195extern char *
196	get_persistent_name_from_pretty(char *);
197extern char *
198	get_persistent_type_dir(char *);
199extern char *
200	get_pretty_name_from_persistent(char *);
201extern int
202	get_sysfs_dev_nr(int);
203extern int
204	get_win_height(void);
205extern void
206	init_nls(void);
207extern int
208	is_device(char *, int);
209extern double
210	ll_s_value(unsigned long long, unsigned long long, unsigned long long);
211extern double
212	ll_sp_value(unsigned long long, unsigned long long, unsigned long long);
213extern int
214	print_gal_header(struct tm *, char *, char *, char *, char *, int);
215extern void
216	print_version(void);
217extern char *
218	strtolower(char *);
219#ifdef DEBUG
220extern void
221	sysstat_panic(const char *, int);
222#endif
223
224#endif  /* _COMMON_H */
225