xref: /dragonfly/lib/libhammer/stats.c (revision dadd6466)
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 
41 static
42 int
43 dosysctl(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 
54 int
55 libhammer_stats_redo(int64_t *value)
56 {
57 	return (dosysctl("vfs.hammer.stats_redo", value));
58 }
59 
60 int
61 libhammer_stats_undo(int64_t *value)
62 {
63 	return (dosysctl("vfs.hammer.stats_undo", value));
64 }
65 
66 int
67 libhammer_stats_commits(int64_t *value)
68 {
69 	return (dosysctl("vfs.hammer.stats_commits", value));
70 }
71 
72 int
73 libhammer_stats_inode_flushes(int64_t *value)
74 {
75 	return (dosysctl("vfs.hammer.stats_inode_flushes", value));
76 }
77 
78 int
79 libhammer_stats_disk_write(int64_t *value)
80 {
81 	return (dosysctl("vfs.hammer.stats_disk_write", value));
82 }
83 
84 int
85 libhammer_stats_disk_read(int64_t *value)
86 {
87 	return (dosysctl("vfs.hammer.stats_disk_read", value));
88 }
89 
90 int
91 libhammer_stats_file_iopsw(int64_t *value)
92 {
93 	return (dosysctl("vfs.hammer.stats_file_iopsw", value));
94 }
95 
96 int
97 libhammer_stats_file_iopsr(int64_t *value)
98 {
99 	return (dosysctl("vfs.hammer.stats_file_iopsr", value));
100 }
101 
102 int
103 libhammer_stats_file_write(int64_t *value)
104 {
105 	return (dosysctl("vfs.hammer.stats_file_write", value));
106 }
107 
108 int
109 libhammer_stats_file_read(int64_t *value)
110 {
111 	return (dosysctl("vfs.hammer.stats_file_read", value));
112 }
113 
114 int
115 libhammer_stats_record_iterations(int64_t *value)
116 {
117 	return (dosysctl("vfs.hammer.stats_record_iterations", value));
118 }
119 
120 int
121 libhammer_stats_root_iterations(int64_t *value)
122 {
123 	return (dosysctl("vfs.hammer.stats_btree_root_iterations", value));
124 }
125 
126 int
127 libhammer_stats_btree_iterations(int64_t *value)
128 {
129 	return (dosysctl("vfs.hammer.stats_btree_iterations", value));
130 }
131 
132 int
133 libhammer_stats_btree_splits(int64_t *value)
134 {
135 	return (dosysctl("vfs.hammer.stats_btree_splits", value));
136 }
137 
138 int
139 libhammer_stats_btree_elements(int64_t *value)
140 {
141 	return (dosysctl("vfs.hammer.stats_btree_elements", value));
142 }
143 
144 int
145 libhammer_stats_btree_deletes(int64_t *value)
146 {
147 	return (dosysctl("vfs.hammer.stats_btree_deletes", value));
148 }
149 
150 int
151 libhammer_stats_btree_inserts(int64_t *value)
152 {
153 	return (dosysctl("vfs.hammer.stats_btree_inserts", value));
154 }
155 
156 int
157 libhammer_stats_btree_lookups(int64_t *value)
158 {
159 	return (dosysctl("vfs.hammer.stats_btree_lookups", value));
160 }
161 
162 int
163 libhammer_stats_btree_searches(int64_t *value)
164 {
165 	return (dosysctl("vfs.hammer.stats_btree_searches", value));
166 }
167 
168 int
169 libhammer_btree_stats(struct libhammer_btree_stats *bstats)
170 {
171 	int error = 0;
172 
173 	error = libhammer_stats_btree_elements(&bstats->elements);
174 	error = libhammer_stats_btree_iterations(&bstats->iterations);
175 	error = libhammer_stats_btree_splits(&bstats->splits);
176 	error = libhammer_stats_btree_inserts(&bstats->inserts);
177 	error = libhammer_stats_btree_deletes(&bstats->deletes);
178 	error = libhammer_stats_btree_lookups(&bstats->lookups);
179 	error = libhammer_stats_btree_searches(&bstats->searches);
180 
181 	return error;
182 }
183 
184 int
185 libhammer_io_stats(struct libhammer_io_stats *iostats)
186 {
187 	int error = 0;
188 
189 	error = libhammer_stats_undo(&iostats->undo);
190 	error = libhammer_stats_commits(&iostats->commits);
191 	error = libhammer_stats_inode_flushes(&iostats->inode_flushes);
192 	error = libhammer_stats_disk_write(&iostats->dev_writes);
193 	error = libhammer_stats_disk_read(&iostats->dev_reads);
194 	error = libhammer_stats_file_iopsw(&iostats->file_iop_writes);
195 	error = libhammer_stats_file_iopsr(&iostats->file_iop_reads);
196 	error = libhammer_stats_file_write(&iostats->file_writes);
197 	error = libhammer_stats_file_read(&iostats->file_reads);
198 
199 	return error;
200 }
201