kernel - Add a sampling history mechanism called kcollect (2)
[dragonfly.git] / sys / sys / kcollect.h
blob05a20ee4533fee870361dfef03f95f57244bb8ba
1 /*
2 * SYS/KCOLLECT.H
3 */
5 #ifndef _SYS_KCOLLECT_H_
6 #define _SYS_KCOLLECT_H_
8 #define KCOLLECT_ENTRIES 31
11 * Record format.
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.
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.
28 typedef struct {
29 uint32_t ticks;
30 uint32_t hz; /* record #0 only */
31 uint64_t data[KCOLLECT_ENTRIES];
32 } kcollect_t;
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_INTRPCT 4 /* whole machine intr % (or other) */
39 #define KCOLLECT_SWAPPCT 5 /* total swap used % */
40 #define KCOLLECT_SWAPANO 6 /* anonymous swap used MB */
41 #define KCOLLECT_SWAPCAC 7 /* swapcache swap used MB */
43 #define KCOLLECT_VMFAULT 8 /* all vm faults incl zero-fill */
44 #define KCOLLECT_COWFAULT 9 /* all vm faults incl zero-fill */
45 #define KCOLLECT_ZFILL 10 /* zero-fill faults */
47 #define KCOLLECT_MEMFRE 11 /* amount of free memory, bytes */
48 #define KCOLLECT_MEMCAC 12 /* amount of almost free memory */
49 #define KCOLLECT_MEMINA 13 /* amount of inactive memory */
50 #define KCOLLECT_MEMACT 14 /* amount of active memory */
51 #define KCOLLECT_MEMWIR 15 /* amount of wired/kernel memory */
53 #define KCOLLECT_SYSCALLS 16 /* system calls */
54 #define KCOLLECT_NLOOKUP 17 /* path lookups */
56 #define KCOLLECT_INTR 18 /* nominal external interrupts */
57 #define KCOLLECT_IPI 19 /* inter-cpu interrupts */
58 #define KCOLLECT_TIMER 20 /* timer interrupts */
60 #define KCOLLECT_DYNAMIC_START 24 /* dynamic entries */
62 #define KCOLLECT_LOAD_FORMAT '2' /* N.NN (modulo 100) */
63 #define KCOLLECT_USERPCT_FORMAT 'p' /* percentage of single cpu x 100 */
64 #define KCOLLECT_SYSTPCT_FORMAT 'p' /* percentage of single cpu x 100 */
65 #define KCOLLECT_IDLEPCT_FORMAT 'p' /* percentage of single cpu x 100 */
67 #define KCOLLECT_SWAPPCT_FORMAT 'p' /* percentage of single cpu x 100 */
68 #define KCOLLECT_SWAPANO_FORMAT 'm' /* in megabytes (1024*1024) */
69 #define KCOLLECT_SWAPCAC_FORMAT 'm' /* in megabytes (1024*1024) */
71 #define KCOLLECT_VMFAULT_FORMAT 'c' /* count over period */
72 #define KCOLLECT_COWFAULT_FORMAT 'c' /* count over period */
73 #define KCOLLECT_ZFILL_FORMAT 'c' /* count over period */
75 #define KCOLLECT_MEMFRE_FORMAT 'b' /* total bytes */
76 #define KCOLLECT_MEMCAC_FORMAT 'b' /* total bytes */
77 #define KCOLLECT_MEMINA_FORMAT 'b' /* total bytes */
78 #define KCOLLECT_MEMACT_FORMAT 'b' /* total bytes */
79 #define KCOLLECT_MEMWIR_FORMAT 'b' /* total bytes */
81 #define KCOLLECT_SYSCALLS_FORMAT 'c' /* count over period */
82 #define KCOLLECT_NLOOKUP_FORMAT 'c' /* count over period */
83 #define KCOLLECT_INTR_FORMAT 'c' /* count over period */
84 #define KCOLLECT_IPI_FORMAT 'c' /* count over period */
85 #define KCOLLECT_TIMER_FORMAT 'c' /* count over period */
87 #define KCOLLECT_SCALE(fmt, scale) ((fmt) | ((uint64_t)(scale) << 8))
88 #define KCOLLECT_GETFMT(scale) ((char)(scale))
89 #define KCOLLECT_GETSCALE(scale) ((scale) >> 8)
91 #ifdef _KERNEL
93 typedef uint64_t (*kcallback_t)(int n);
95 int kcollect_register(int which, const char *id,
96 kcallback_t func, uint64_t scale);
97 void kcollect_unregister(int n);
98 void kcollect_setvalue(int n, uint64_t value);
99 void kcollect_setscale(int n, uint64_t value);
101 #endif
103 #endif