rc.d: Introduce 'dhcp_client' to wrap over dhclient and dhcpcd
[dragonfly.git] / lib / libhammer / stats.c
CommitLineData
c422eb8a
AHJ
1 /*
2 * Copyright (c) 2013 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 * by Antonio Huete Jimenez <tuxillo@quantumachine.net>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <stdio.h>
37#include <sys/sysctl.h>
38
39#include "libhammer.h"
40
41static
42int
43dosysctl(const char *sname, int64_t *value)
44{
45 size_t len;
46 int error;
47
48 len = sizeof(*value);
49 error = sysctlbyname(sname, value, &len, NULL, 0);
50
51 return error;
52}
53
54int
55libhammer_stats_redo(int64_t *value)
56{
57 return (dosysctl("vfs.hammer.stats_redo", value));
58}
59
60int
61libhammer_stats_undo(int64_t *value)
62{
63 return (dosysctl("vfs.hammer.stats_undo", value));
64}
65
66int
67libhammer_stats_commits(int64_t *value)
68{
69 return (dosysctl("vfs.hammer.stats_commits", value));
70}
71
72int
73libhammer_stats_inode_flushes(int64_t *value)
74{
75 return (dosysctl("vfs.hammer.stats_inode_flushes", value));
76}
77
78int
79libhammer_stats_disk_write(int64_t *value)
80{
81 return (dosysctl("vfs.hammer.stats_disk_write", value));
82}
83
84int
85libhammer_stats_disk_read(int64_t *value)
86{
87 return (dosysctl("vfs.hammer.stats_disk_read", value));
88}
89
90int
91libhammer_stats_file_iopsw(int64_t *value)
92{
93 return (dosysctl("vfs.hammer.stats_file_iopsw", value));
94}
95
96int
97libhammer_stats_file_iopsr(int64_t *value)
98{
99 return (dosysctl("vfs.hammer.stats_file_iopsr", value));
100}
101
102int
103libhammer_stats_file_write(int64_t *value)
104{
105 return (dosysctl("vfs.hammer.stats_file_write", value));
106}
107
108int
109libhammer_stats_file_read(int64_t *value)
110{
111 return (dosysctl("vfs.hammer.stats_file_read", value));
112}
113
114int
115libhammer_stats_record_iterations(int64_t *value)
116{
117 return (dosysctl("vfs.hammer.stats_record_iterations", value));
118}
119
120int
121libhammer_stats_root_iterations(int64_t *value)
122{
123 return (dosysctl("vfs.hammer.stats_btree_root_iterations", value));
124}
125
126int
127libhammer_stats_btree_iterations(int64_t *value)
128{
129 return (dosysctl("vfs.hammer.stats_btree_iterations", value));
130}
131
132int
133libhammer_stats_btree_splits(int64_t *value)
134{
135 return (dosysctl("vfs.hammer.stats_btree_splits", value));
136}
137
138int
139libhammer_stats_btree_elements(int64_t *value)
140{
141 return (dosysctl("vfs.hammer.stats_btree_elements", value));
142}
143
144int
145libhammer_stats_btree_deletes(int64_t *value)
146{
147 return (dosysctl("vfs.hammer.stats_btree_deletes", value));
148}
149
150int
151libhammer_stats_btree_inserts(int64_t *value)
152{
153 return (dosysctl("vfs.hammer.stats_btree_inserts", value));
154}
155
156int
157libhammer_stats_btree_lookups(int64_t *value)
158{
159 return (dosysctl("vfs.hammer.stats_btree_lookups", value));
160}
161
162int
163libhammer_stats_btree_searches(int64_t *value)
164{
165 return (dosysctl("vfs.hammer.stats_btree_searches", value));
166}
167
168int
169libhammer_btree_stats(struct libhammer_btree_stats *bstats)
170{
b1eaba80
TK
171 if (libhammer_stats_btree_elements(&bstats->elements) < 0)
172 return -1;
173 if (libhammer_stats_btree_iterations(&bstats->iterations) < 0)
174 return -1;
175 if (libhammer_stats_btree_splits(&bstats->splits) < 0)
176 return -1;
177 if (libhammer_stats_btree_inserts(&bstats->inserts) < 0)
178 return -1;
179 if (libhammer_stats_btree_deletes(&bstats->deletes) < 0)
180 return -1;
181 if (libhammer_stats_btree_lookups(&bstats->lookups) < 0)
182 return -1;
183 if (libhammer_stats_btree_searches(&bstats->searches) < 0)
184 return -1;
185 return 0;
c422eb8a
AHJ
186}
187
188int
189libhammer_io_stats(struct libhammer_io_stats *iostats)
190{
b1eaba80
TK
191 if (libhammer_stats_undo(&iostats->undo) < 0)
192 return -1;
193 if (libhammer_stats_commits(&iostats->commits) < 0)
194 return -1;
195 if (libhammer_stats_inode_flushes(&iostats->inode_flushes) < 0)
196 return -1;
197 if (libhammer_stats_disk_write(&iostats->dev_writes) < 0)
198 return -1;
199 if (libhammer_stats_disk_read(&iostats->dev_reads) < 0)
200 return -1;
201 if (libhammer_stats_file_iopsw(&iostats->file_iop_writes) < 0)
202 return -1;
203 if (libhammer_stats_file_iopsr(&iostats->file_iop_reads) < 0)
204 return -1;
205 if (libhammer_stats_file_write(&iostats->file_writes) < 0)
206 return -1;
207 if (libhammer_stats_file_read(&iostats->file_reads) < 0)
208 return -1;
209 return 0;
c422eb8a 210}