xref: /dragonfly/sys/sys/kcollect.h (revision 6700dd34)
1 /*
2  * SYS/KCOLLECT.H
3  */
4 
5 #ifndef _SYS_KCOLLECT_H_
6 #define _SYS_KCOLLECT_H_
7 
8 #define KCOLLECT_ENTRIES        29
9 
10 /*
11  * Record format.
12  *
13  * Note that the first record returned by the sysctl contains scale and
14  * format data in the data[0] fields.  The format is stored in the low
15  * 8-bits and the scale in the remaining bits, unsigned.  ticks is set to
16  * the current ticks as-of when the sysctl was issues and hz is set to hz
17  * for the machine, to interpret ticks.  Caller can calculate dates from
18  * that.
19  *
20  * The second record stores identifying strings in the data field,
21  * up to 8 characters per entry.  An 8-character-long string will not be
22  * zero terminated.  The ticks and hz fields will be 0.
23  *
24  * All remaining records contain data going backwards in time.  The ticks
25  * field will be set as-of when the data is collected, hz will be 0, and
26  * the data[] fields will contain the raw values according to the format.
27  */
28 typedef struct {
29 	uint32_t	ticks;
30 	uint32_t	hz;			/* record #0 only */
31 	struct timeval	realtime;
32 	uint64_t	data[KCOLLECT_ENTRIES];
33 } kcollect_t;
34 
35 #define KCOLLECT_LOAD		0	/* machine load 1.0 = 1 cpu @ 100%  */
36 #define KCOLLECT_USERPCT	1	/* whole machine user % */
37 #define KCOLLECT_SYSTPCT	2	/* whole machine sys % */
38 #define KCOLLECT_IDLEPCT	3	/* whole machine idle % */
39 #define KCOLLECT_INTRPCT	4	/* whole machine intr % (or other) */
40 #define KCOLLECT_SWAPPCT	5	/* total swap used % */
41 #define KCOLLECT_SWAPANO	6	/* anonymous swap used MB */
42 #define KCOLLECT_SWAPCAC	7	/* swapcache swap used MB */
43 
44 #define KCOLLECT_VMFAULT	8	/* all vm faults incl zero-fill */
45 #define KCOLLECT_COWFAULT	9	/* all vm faults incl zero-fill */
46 #define KCOLLECT_ZFILL		10	/* zero-fill faults */
47 
48 #define KCOLLECT_MEMFRE		11	/* amount of free memory, bytes */
49 #define KCOLLECT_MEMCAC		12	/* amount of almost free memory */
50 #define KCOLLECT_MEMINA		13	/* amount of inactive memory */
51 #define KCOLLECT_MEMACT		14	/* amount of active memory */
52 #define KCOLLECT_MEMWIR		15	/* amount of wired/kernel memory */
53 
54 #define KCOLLECT_SYSCALLS	16	/* system calls */
55 #define KCOLLECT_NLOOKUP	17	/* path lookups */
56 
57 #define KCOLLECT_INTR		18	/* nominal external interrupts */
58 #define KCOLLECT_IPI		19	/* inter-cpu interrupts */
59 #define KCOLLECT_TIMER		20	/* timer interrupts */
60 
61 #define KCOLLECT_DYNAMIC_START	24	/* dynamic entries */
62 
63 #define KCOLLECT_LOAD_FORMAT	'2'	/* N.NN (modulo 100) */
64 #define KCOLLECT_USERPCT_FORMAT	'p'	/* percentage of single cpu x 100 */
65 #define KCOLLECT_SYSTPCT_FORMAT	'p'	/* percentage of single cpu x 100 */
66 #define KCOLLECT_IDLEPCT_FORMAT	'p'	/* percentage of single cpu x 100 */
67 
68 #define KCOLLECT_SWAPPCT_FORMAT	'p'	/* percentage of single cpu x 100 */
69 #define KCOLLECT_SWAPANO_FORMAT	'm'	/* in megabytes (1024*1024) */
70 #define KCOLLECT_SWAPCAC_FORMAT	'm'	/* in megabytes (1024*1024) */
71 
72 #define KCOLLECT_VMFAULT_FORMAT	'c'	/* count over period */
73 #define KCOLLECT_COWFAULT_FORMAT 'c'	/* count over period */
74 #define KCOLLECT_ZFILL_FORMAT 	'c'	/* count over period */
75 
76 #define KCOLLECT_MEMFRE_FORMAT 	'b'	/* total bytes (not pages) */
77 #define KCOLLECT_MEMCAC_FORMAT 	'b'	/* total bytes (not pages) */
78 #define KCOLLECT_MEMINA_FORMAT 	'b'	/* total bytes (not pages) */
79 #define KCOLLECT_MEMACT_FORMAT 	'b'	/* total bytes (not pages) */
80 #define KCOLLECT_MEMWIR_FORMAT 	'b'	/* total bytes (not pages) */
81 
82 #define KCOLLECT_SYSCALLS_FORMAT 	'c'	/* count over period */
83 #define KCOLLECT_NLOOKUP_FORMAT 	'c'	/* count over period */
84 #define KCOLLECT_INTR_FORMAT	 	'c'	/* count over period */
85 #define KCOLLECT_IPI_FORMAT 		'c'	/* count over period */
86 #define KCOLLECT_TIMER_FORMAT 		'c'	/* count over period */
87 
88 #define KCOLLECT_SCALE(fmt, scale)	((fmt) | ((uint64_t)(scale) << 8))
89 #define KCOLLECT_GETFMT(scale)		((char)(scale))
90 #define KCOLLECT_GETSCALE(scale)	((scale) >> 8)
91 
92 #define KCOLLECT_INTERVAL		10	/* in seconds */
93 
94 #ifdef _KERNEL
95 
96 typedef uint64_t (*kcallback_t)(int n);
97 
98 int kcollect_register(int which, const char *id,
99 			kcallback_t func, uint64_t scale);
100 void kcollect_unregister(int n);
101 void kcollect_setvalue(int n, uint64_t value);
102 void kcollect_setscale(int n, uint64_t value);
103 
104 #endif
105 
106 #endif
107