5 #ifndef _SYS_KCOLLECT_H_
6 #define _SYS_KCOLLECT_H_
8 #define KCOLLECT_ENTRIES 31
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
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.
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.
30 uint32_t hz; /* record #0 only */
31 uint64_t data[KCOLLECT_ENTRIES];
34 #define KCOLLECT_LOAD 0 /* machine load 1.0 = 1 cpu @ 100% */
35 #define KCOLLECT_USERPCT 1 /* whole machine user % */
36 #define KCOLLECT_SYSTPCT 2 /* whole machine sys % */
37 #define KCOLLECT_IDLEPCT 3 /* whole machine idle % */
38 #define KCOLLECT_SWAPPCT 4 /* total swap used % */
39 #define KCOLLECT_SWAPANO 5 /* anonymous swap used MB */
40 #define KCOLLECT_SWAPCAC 6 /* swapcache swap used MB */
41 #define KCOLLECT_VMFAULT 7 /* all vm faults incl zero-fill */
42 #define KCOLLECT_ZFILL 8 /* zero-fill faults */
43 #define KCOLLECT_MEMFRE 9 /* amount of free memory, bytes */
44 #define KCOLLECT_MEMCAC 10 /* amount of almost free memory */
45 #define KCOLLECT_MEMINA 11 /* amount of inactive memory */
46 #define KCOLLECT_MEMACT 12 /* amount of active memory */
47 #define KCOLLECT_MEMWIR 13 /* amount of wired/kernel memory */
49 #define KCOLLECT_DYNAMIC_START 16 /* dynamic entries */
51 #define KCOLLECT_LOAD_FORMAT '2' /* N.NN (modulo 100) */
52 #define KCOLLECT_USERPCT_FORMAT 'p' /* percentage of single cpu x 100 */
53 #define KCOLLECT_SYSTPCT_FORMAT 'p' /* percentage of single cpu x 100 */
54 #define KCOLLECT_IDLEPCT_FORMAT 'p' /* percentage of single cpu x 100 */
55 #define KCOLLECT_SWAPPCT_FORMAT 'p' /* percentage of single cpu x 100 */
56 #define KCOLLECT_SWAPANO_FORMAT 'm' /* in megabytes (1024*1024) */
57 #define KCOLLECT_SWAPCAC_FORMAT 'm' /* in megabytes (1024*1024) */
58 #define KCOLLECT_VMFAULT_FORMAT 'c' /* count over period */
59 #define KCOLLECT_ZFILL_FORMAT 'c' /* count over period */
60 #define KCOLLECT_MEMFRE_FORMAT 'b' /* total bytes */
61 #define KCOLLECT_MEMCAC_FORMAT 'b' /* total bytes */
62 #define KCOLLECT_MEMINA_FORMAT 'b' /* total bytes */
63 #define KCOLLECT_MEMACT_FORMAT 'b' /* total bytes */
64 #define KCOLLECT_MEMWIR_FORMAT 'b' /* total bytes */
66 #define KCOLLECT_SCALE(fmt, scale) ((fmt) | ((uint64_t)(scale) << 8))
67 #define KCOLLECT_GETFMT(scale) ((char)(scale))
68 #define KCOLLECT_GETSCALE(scale) ((scale) >> 8)
72 typedef uint64_t (*kcallback_t)(int n);
74 int kcollect_register(int which, const char *id,
75 kcallback_t func, uint64_t scale);
76 void kcollect_unregister(int n);
77 void kcollect_setvalue(int n, uint64_t value);