summaryrefslogtreecommitdiff
path: root/share/man/man9/kstat_create.9
blob: 4e8b36391d40d3e978c0007a833988a68913a890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
.\" $OpenBSD: kstat_create.9,v 1.2 2020/08/10 11:33:58 schwarze Exp $
.\"
.\" Copyright (c) 2020 David Gwynne <dlg@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: August 10 2020 $
.Dt KSTAT_CREATE 9
.Os
.Sh NAME
.Nm kstat_create ,
.\" .Nm kstat_set_wlock ,
.\" .Nm kstat_set_rlock ,
.\" .Nm kstat_set_mutex ,
.Nm kstat_install ,
.Nm kstat_destroy
.Nd kernel statistics provider API
.Sh SYNOPSIS
.In sys/kstat.h
.Ft struct kstat *
.Fo kstat_create
.Fa "const char *provider"
.Fa "unsigned int instance"
.Fa "const char *name"
.Fa "unsigned int unit"
.Fa "unsigned int type"
.Fa "unsigned int flags"
.Fc
.\" .Ft void
.\" .Fn kstat_set_wlock "struct kstat *ks" "struct rwlock *rwl"
.\" .Ft void
.\" .Fn kstat_set_rlock "struct kstat *ks" "struct rwlock *rwl"
.\" .Ft void
.\" .Fn kstat_set_mutex "struct kstat *ks" "struct mutex *mtx"
.Ft void
.Fn kstat_install "struct kstat *ks"
.Ft void
.Fn kstat_destroy "struct kstat *ks"
.Sh DESCRIPTION
Kernel subsystems can export statistics to userland using the kernel
statistics (kstat) API.
.Pp
The
.Fn kstat_create
function allocates a
.Vt kstat
structure and adds it to the list of statistics that userland can query.
A kstat is uniquely identified by a tuple made up of the
.Fa provider ,
.Fa instances ,
.Fa name ,
and
.Fa unit
arguments.
The type of information provided by the kstat is identified by the
.Fa type
argument.
The supported kstat types are
.Bl -tag -width xxx -offset indent
.It Dv KSTAT_T_RAW
The kstat provides raw bytes.
.It Dv KSTAT_T_KV
The kstat provides a series of
.Vt struct kstat_kv
structures that represent key/value information.
See
.Xr kstat_kv_init 9
for more detail.
.El
.Pp
Once a
.Vt kstat
structure has been created,
the caller is responsible for initialising the structure.
.Pp
After the structure has been initialised,
.Fn kstat_install
notifies the kstat subsystem that
.Fa ks
can be used to export information to userland.
.Pp
.Fn kstat_destroy
removes
.Fa ks
from the list of exported statistics and frees it.
.\" might want a kstat_remove...
.Sh CONTEXT
.Fn kstat_create ,
.Fn kstat_install ,
.\" .Fn kstat_set_wlock ,
.\" .Fn kstat_set_rlock ,
.\" .Fn kstat_set_mutex ,
and
.Fn kstat_destroy
can be called during autoconf, or from process context.
.Sh RETURN VALUES
.Fn kstat_create
returns a pointer to a
.Vt kstat
structure on success, or
.Dv NULL
on failure.
.Sh SEE ALSO
.Xr kstat_kv_init 9
.Sh HISTORY
These functions first appeared in
.Ox 6.8 .
.Sh AUTHORS
.An David Gwynne Aq Mt dlg@openbsd.org