umount(8): Add missing braces.
[dragonfly.git] / lib / libhammer / stats.c
blobe523fe8237867ed2d7f3cfa4041d53497bce44cb
1 /*
2 * Copyright (c) 2013 The DragonFly Project. All rights reserved.
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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
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.
36 #include <stdio.h>
37 #include <sys/sysctl.h>
39 #include "libhammer.h"
41 static
42 int
43 dosysctl(const char *sname, int64_t *value)
45 size_t len;
46 int error;
48 len = sizeof(*value);
49 error = sysctlbyname(sname, value, &len, NULL, 0);
51 return error;
54 int
55 libhammer_stats_redo(int64_t *value)
57 return (dosysctl("vfs.hammer.stats_redo", value));
60 int
61 libhammer_stats_undo(int64_t *value)
63 return (dosysctl("vfs.hammer.stats_undo", value));
66 int
67 libhammer_stats_commits(int64_t *value)
69 return (dosysctl("vfs.hammer.stats_commits", value));
72 int
73 libhammer_stats_inode_flushes(int64_t *value)
75 return (dosysctl("vfs.hammer.stats_inode_flushes", value));
78 int
79 libhammer_stats_disk_write(int64_t *value)
81 return (dosysctl("vfs.hammer.stats_disk_write", value));
84 int
85 libhammer_stats_disk_read(int64_t *value)
87 return (dosysctl("vfs.hammer.stats_disk_read", value));
90 int
91 libhammer_stats_file_iopsw(int64_t *value)
93 return (dosysctl("vfs.hammer.stats_file_iopsw", value));
96 int
97 libhammer_stats_file_iopsr(int64_t *value)
99 return (dosysctl("vfs.hammer.stats_file_iopsr", value));
103 libhammer_stats_file_write(int64_t *value)
105 return (dosysctl("vfs.hammer.stats_file_write", value));
109 libhammer_stats_file_read(int64_t *value)
111 return (dosysctl("vfs.hammer.stats_file_read", value));
115 libhammer_stats_record_iterations(int64_t *value)
117 return (dosysctl("vfs.hammer.stats_record_iterations", value));
121 libhammer_stats_root_iterations(int64_t *value)
123 return (dosysctl("vfs.hammer.stats_btree_root_iterations", value));
127 libhammer_stats_btree_iterations(int64_t *value)
129 return (dosysctl("vfs.hammer.stats_btree_iterations", value));
133 libhammer_stats_btree_splits(int64_t *value)
135 return (dosysctl("vfs.hammer.stats_btree_splits", value));
139 libhammer_stats_btree_elements(int64_t *value)
141 return (dosysctl("vfs.hammer.stats_btree_elements", value));
145 libhammer_stats_btree_deletes(int64_t *value)
147 return (dosysctl("vfs.hammer.stats_btree_deletes", value));
151 libhammer_stats_btree_inserts(int64_t *value)
153 return (dosysctl("vfs.hammer.stats_btree_inserts", value));
157 libhammer_stats_btree_lookups(int64_t *value)
159 return (dosysctl("vfs.hammer.stats_btree_lookups", value));
163 libhammer_stats_btree_searches(int64_t *value)
165 return (dosysctl("vfs.hammer.stats_btree_searches", value));
169 libhammer_btree_stats(struct libhammer_btree_stats *bstats)
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;
189 libhammer_io_stats(struct libhammer_io_stats *iostats)
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;