4 Unix SMB/CIFS implementation.
5 store smbd profiling information in shared memory
6 Copyright (C) Andrew Tridgell 1999
7 Copyright (C) James Peach 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 struct tevent_context
;
28 #define SMBPROFILE_STATS_ALL_SECTIONS \
29 SMBPROFILE_STATS_START \
31 SMBPROFILE_STATS_SECTION_START(global, "SMBD loop") \
32 SMBPROFILE_STATS_COUNT(connect) \
33 SMBPROFILE_STATS_COUNT(disconnect) \
34 SMBPROFILE_STATS_BASIC(idle) \
35 SMBPROFILE_STATS_TIME(cpu_user) \
36 SMBPROFILE_STATS_TIME(cpu_system) \
37 SMBPROFILE_STATS_COUNT(request) \
38 SMBPROFILE_STATS_BASIC(push_sec_ctx) \
39 SMBPROFILE_STATS_BASIC(set_sec_ctx) \
40 SMBPROFILE_STATS_BASIC(set_root_sec_ctx) \
41 SMBPROFILE_STATS_BASIC(pop_sec_ctx) \
42 SMBPROFILE_STATS_SECTION_END \
44 SMBPROFILE_STATS_SECTION_START(syscall, "System Calls") \
45 SMBPROFILE_STATS_BASIC(syscall_opendir) \
46 SMBPROFILE_STATS_BASIC(syscall_fdopendir) \
47 SMBPROFILE_STATS_BASIC(syscall_readdir) \
48 SMBPROFILE_STATS_BASIC(syscall_seekdir) \
49 SMBPROFILE_STATS_BASIC(syscall_telldir) \
50 SMBPROFILE_STATS_BASIC(syscall_rewinddir) \
51 SMBPROFILE_STATS_BASIC(syscall_mkdir) \
52 SMBPROFILE_STATS_BASIC(syscall_rmdir) \
53 SMBPROFILE_STATS_BASIC(syscall_closedir) \
54 SMBPROFILE_STATS_BASIC(syscall_open) \
55 SMBPROFILE_STATS_BASIC(syscall_createfile) \
56 SMBPROFILE_STATS_BASIC(syscall_close) \
57 SMBPROFILE_STATS_BYTES(syscall_read) \
58 SMBPROFILE_STATS_BYTES(syscall_pread) \
59 SMBPROFILE_STATS_BYTES(syscall_asys_pread) \
60 SMBPROFILE_STATS_BYTES(syscall_write) \
61 SMBPROFILE_STATS_BYTES(syscall_pwrite) \
62 SMBPROFILE_STATS_BYTES(syscall_asys_pwrite) \
63 SMBPROFILE_STATS_BASIC(syscall_lseek) \
64 SMBPROFILE_STATS_BYTES(syscall_sendfile) \
65 SMBPROFILE_STATS_BYTES(syscall_recvfile) \
66 SMBPROFILE_STATS_BASIC(syscall_rename) \
67 SMBPROFILE_STATS_BASIC(syscall_rename_at) \
68 SMBPROFILE_STATS_BASIC(syscall_fsync) \
69 SMBPROFILE_STATS_BASIC(syscall_asys_fsync) \
70 SMBPROFILE_STATS_BASIC(syscall_stat) \
71 SMBPROFILE_STATS_BASIC(syscall_fstat) \
72 SMBPROFILE_STATS_BASIC(syscall_lstat) \
73 SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \
74 SMBPROFILE_STATS_BASIC(syscall_unlink) \
75 SMBPROFILE_STATS_BASIC(syscall_chmod) \
76 SMBPROFILE_STATS_BASIC(syscall_fchmod) \
77 SMBPROFILE_STATS_BASIC(syscall_chown) \
78 SMBPROFILE_STATS_BASIC(syscall_fchown) \
79 SMBPROFILE_STATS_BASIC(syscall_lchown) \
80 SMBPROFILE_STATS_BASIC(syscall_chdir) \
81 SMBPROFILE_STATS_BASIC(syscall_getwd) \
82 SMBPROFILE_STATS_BASIC(syscall_ntimes) \
83 SMBPROFILE_STATS_BASIC(syscall_ftruncate) \
84 SMBPROFILE_STATS_BASIC(syscall_fallocate) \
85 SMBPROFILE_STATS_BASIC(syscall_fcntl_lock) \
86 SMBPROFILE_STATS_BASIC(syscall_kernel_flock) \
87 SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \
88 SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \
89 SMBPROFILE_STATS_BASIC(syscall_readlink) \
90 SMBPROFILE_STATS_BASIC(syscall_symlink) \
91 SMBPROFILE_STATS_BASIC(syscall_link) \
92 SMBPROFILE_STATS_BASIC(syscall_mknod) \
93 SMBPROFILE_STATS_BASIC(syscall_realpath) \
94 SMBPROFILE_STATS_BASIC(syscall_get_quota) \
95 SMBPROFILE_STATS_BASIC(syscall_set_quota) \
96 SMBPROFILE_STATS_BASIC(syscall_get_sd) \
97 SMBPROFILE_STATS_BASIC(syscall_set_sd) \
98 SMBPROFILE_STATS_BASIC(syscall_brl_lock) \
99 SMBPROFILE_STATS_BASIC(syscall_brl_unlock) \
100 SMBPROFILE_STATS_BASIC(syscall_brl_cancel) \
101 SMBPROFILE_STATS_SECTION_END \
103 SMBPROFILE_STATS_SECTION_START(acl, "ACL Calls") \
104 SMBPROFILE_STATS_BASIC(get_nt_acl) \
105 SMBPROFILE_STATS_BASIC(fget_nt_acl) \
106 SMBPROFILE_STATS_BASIC(fset_nt_acl) \
107 SMBPROFILE_STATS_BASIC(chmod_acl) \
108 SMBPROFILE_STATS_BASIC(fchmod_acl) \
109 SMBPROFILE_STATS_SECTION_END \
111 SMBPROFILE_STATS_SECTION_START(statcache, "Stat Cache") \
112 SMBPROFILE_STATS_COUNT(statcache_lookups) \
113 SMBPROFILE_STATS_COUNT(statcache_misses) \
114 SMBPROFILE_STATS_COUNT(statcache_hits) \
115 SMBPROFILE_STATS_SECTION_END \
117 SMBPROFILE_STATS_SECTION_START(writecache, "Write Cache") \
118 SMBPROFILE_STATS_COUNT(writecache_allocations) \
119 SMBPROFILE_STATS_COUNT(writecache_deallocations) \
120 SMBPROFILE_STATS_COUNT(writecache_cached_reads) \
121 SMBPROFILE_STATS_COUNT(writecache_total_writes) \
122 SMBPROFILE_STATS_COUNT(writecache_init_writes) \
123 SMBPROFILE_STATS_COUNT(writecache_abutted_writes) \
124 SMBPROFILE_STATS_COUNT(writecache_non_oplock_writes) \
125 SMBPROFILE_STATS_COUNT(writecache_direct_writes) \
126 SMBPROFILE_STATS_COUNT(writecache_cached_writes) \
127 SMBPROFILE_STATS_COUNT(writecache_perfect_writes) \
128 SMBPROFILE_STATS_COUNT(writecache_flush_reason_seek) \
129 SMBPROFILE_STATS_COUNT(writecache_flush_reason_read) \
130 SMBPROFILE_STATS_COUNT(writecache_flush_reason_readraw) \
131 SMBPROFILE_STATS_COUNT(writecache_flush_reason_write) \
132 SMBPROFILE_STATS_COUNT(writecache_flush_reason_oplock) \
133 SMBPROFILE_STATS_COUNT(writecache_flush_reason_close) \
134 SMBPROFILE_STATS_COUNT(writecache_flush_reason_sync) \
135 SMBPROFILE_STATS_COUNT(writecache_flush_reason_sizechange) \
136 SMBPROFILE_STATS_SECTION_END \
138 SMBPROFILE_STATS_SECTION_START(SMB, "SMB Calls") \
139 SMBPROFILE_STATS_BASIC(SMBmkdir) \
140 SMBPROFILE_STATS_BASIC(SMBrmdir) \
141 SMBPROFILE_STATS_BASIC(SMBopen) \
142 SMBPROFILE_STATS_BASIC(SMBcreate) \
143 SMBPROFILE_STATS_BASIC(SMBclose) \
144 SMBPROFILE_STATS_BASIC(SMBflush) \
145 SMBPROFILE_STATS_BASIC(SMBunlink) \
146 SMBPROFILE_STATS_BASIC(SMBmv) \
147 SMBPROFILE_STATS_BASIC(SMBgetatr) \
148 SMBPROFILE_STATS_BASIC(SMBsetatr) \
149 SMBPROFILE_STATS_BASIC(SMBread) \
150 SMBPROFILE_STATS_BASIC(SMBwrite) \
151 SMBPROFILE_STATS_BASIC(SMBlock) \
152 SMBPROFILE_STATS_BASIC(SMBunlock) \
153 SMBPROFILE_STATS_BASIC(SMBctemp) \
154 SMBPROFILE_STATS_BASIC(SMBmknew) \
155 SMBPROFILE_STATS_BASIC(SMBcheckpath) \
156 SMBPROFILE_STATS_BASIC(SMBexit) \
157 SMBPROFILE_STATS_BASIC(SMBlseek) \
158 SMBPROFILE_STATS_BASIC(SMBlockread) \
159 SMBPROFILE_STATS_BASIC(SMBwriteunlock) \
160 SMBPROFILE_STATS_BASIC(SMBreadbraw) \
161 SMBPROFILE_STATS_BASIC(SMBreadBmpx) \
162 SMBPROFILE_STATS_BASIC(SMBreadBs) \
163 SMBPROFILE_STATS_BASIC(SMBwritebraw) \
164 SMBPROFILE_STATS_BASIC(SMBwriteBmpx) \
165 SMBPROFILE_STATS_BASIC(SMBwriteBs) \
166 SMBPROFILE_STATS_BASIC(SMBwritec) \
167 SMBPROFILE_STATS_BASIC(SMBsetattrE) \
168 SMBPROFILE_STATS_BASIC(SMBgetattrE) \
169 SMBPROFILE_STATS_BASIC(SMBlockingX) \
170 SMBPROFILE_STATS_BASIC(SMBtrans) \
171 SMBPROFILE_STATS_BASIC(SMBtranss) \
172 SMBPROFILE_STATS_BASIC(SMBioctl) \
173 SMBPROFILE_STATS_BASIC(SMBioctls) \
174 SMBPROFILE_STATS_BASIC(SMBcopy) \
175 SMBPROFILE_STATS_BASIC(SMBmove) \
176 SMBPROFILE_STATS_BASIC(SMBecho) \
177 SMBPROFILE_STATS_BASIC(SMBwriteclose) \
178 SMBPROFILE_STATS_BASIC(SMBopenX) \
179 SMBPROFILE_STATS_BASIC(SMBreadX) \
180 SMBPROFILE_STATS_BASIC(SMBwriteX) \
181 SMBPROFILE_STATS_BASIC(SMBtrans2) \
182 SMBPROFILE_STATS_BASIC(SMBtranss2) \
183 SMBPROFILE_STATS_BASIC(SMBfindclose) \
184 SMBPROFILE_STATS_BASIC(SMBfindnclose) \
185 SMBPROFILE_STATS_BASIC(SMBtcon) \
186 SMBPROFILE_STATS_BASIC(SMBtdis) \
187 SMBPROFILE_STATS_BASIC(SMBnegprot) \
188 SMBPROFILE_STATS_BASIC(SMBsesssetupX) \
189 SMBPROFILE_STATS_BASIC(SMBulogoffX) \
190 SMBPROFILE_STATS_BASIC(SMBtconX) \
191 SMBPROFILE_STATS_BASIC(SMBdskattr) \
192 SMBPROFILE_STATS_BASIC(SMBsearch) \
193 SMBPROFILE_STATS_BASIC(SMBffirst) \
194 SMBPROFILE_STATS_BASIC(SMBfunique) \
195 SMBPROFILE_STATS_BASIC(SMBfclose) \
196 SMBPROFILE_STATS_BASIC(SMBnttrans) \
197 SMBPROFILE_STATS_BASIC(SMBnttranss) \
198 SMBPROFILE_STATS_BASIC(SMBntcreateX) \
199 SMBPROFILE_STATS_BASIC(SMBntcancel) \
200 SMBPROFILE_STATS_BASIC(SMBntrename) \
201 SMBPROFILE_STATS_BASIC(SMBsplopen) \
202 SMBPROFILE_STATS_BASIC(SMBsplwr) \
203 SMBPROFILE_STATS_BASIC(SMBsplclose) \
204 SMBPROFILE_STATS_BASIC(SMBsplretq) \
205 SMBPROFILE_STATS_BASIC(SMBsends) \
206 SMBPROFILE_STATS_BASIC(SMBsendb) \
207 SMBPROFILE_STATS_BASIC(SMBfwdname) \
208 SMBPROFILE_STATS_BASIC(SMBcancelf) \
209 SMBPROFILE_STATS_BASIC(SMBgetmac) \
210 SMBPROFILE_STATS_BASIC(SMBsendstrt) \
211 SMBPROFILE_STATS_BASIC(SMBsendend) \
212 SMBPROFILE_STATS_BASIC(SMBsendtxt) \
213 SMBPROFILE_STATS_BASIC(SMBinvalid) \
214 SMBPROFILE_STATS_SECTION_END \
216 SMBPROFILE_STATS_SECTION_START(Trans2, "Trans2 Calls") \
217 SMBPROFILE_STATS_BASIC(Trans2_open) \
218 SMBPROFILE_STATS_BASIC(Trans2_findfirst) \
219 SMBPROFILE_STATS_BASIC(Trans2_findnext) \
220 SMBPROFILE_STATS_BASIC(Trans2_qfsinfo) \
221 SMBPROFILE_STATS_BASIC(Trans2_setfsinfo) \
222 SMBPROFILE_STATS_BASIC(Trans2_qpathinfo) \
223 SMBPROFILE_STATS_BASIC(Trans2_setpathinfo) \
224 SMBPROFILE_STATS_BASIC(Trans2_qfileinfo) \
225 SMBPROFILE_STATS_BASIC(Trans2_setfileinfo) \
226 SMBPROFILE_STATS_BASIC(Trans2_fsctl) \
227 SMBPROFILE_STATS_BASIC(Trans2_ioctl) \
228 SMBPROFILE_STATS_BASIC(Trans2_findnotifyfirst) \
229 SMBPROFILE_STATS_BASIC(Trans2_findnotifynext) \
230 SMBPROFILE_STATS_BASIC(Trans2_mkdir) \
231 SMBPROFILE_STATS_BASIC(Trans2_session_setup) \
232 SMBPROFILE_STATS_BASIC(Trans2_get_dfs_referral) \
233 SMBPROFILE_STATS_BASIC(Trans2_report_dfs_inconsistancy) \
234 SMBPROFILE_STATS_SECTION_END \
236 SMBPROFILE_STATS_SECTION_START(NT_transact, "NT Transact Calls") \
237 SMBPROFILE_STATS_BASIC(NT_transact_create) \
238 SMBPROFILE_STATS_BASIC(NT_transact_ioctl) \
239 SMBPROFILE_STATS_BASIC(NT_transact_set_security_desc) \
240 SMBPROFILE_STATS_BASIC(NT_transact_notify_change) \
241 SMBPROFILE_STATS_BASIC(NT_transact_rename) \
242 SMBPROFILE_STATS_BASIC(NT_transact_query_security_desc) \
243 SMBPROFILE_STATS_BASIC(NT_transact_get_user_quota) \
244 SMBPROFILE_STATS_BASIC(NT_transact_set_user_quota) \
245 SMBPROFILE_STATS_SECTION_END \
247 SMBPROFILE_STATS_SECTION_START(smb2, "SMB2 Calls") \
248 SMBPROFILE_STATS_IOBYTES(smb2_negprot) \
249 SMBPROFILE_STATS_IOBYTES(smb2_sesssetup) \
250 SMBPROFILE_STATS_IOBYTES(smb2_logoff) \
251 SMBPROFILE_STATS_IOBYTES(smb2_tcon) \
252 SMBPROFILE_STATS_IOBYTES(smb2_tdis) \
253 SMBPROFILE_STATS_IOBYTES(smb2_create) \
254 SMBPROFILE_STATS_IOBYTES(smb2_close) \
255 SMBPROFILE_STATS_IOBYTES(smb2_flush) \
256 SMBPROFILE_STATS_IOBYTES(smb2_read) \
257 SMBPROFILE_STATS_IOBYTES(smb2_write) \
258 SMBPROFILE_STATS_IOBYTES(smb2_lock) \
259 SMBPROFILE_STATS_IOBYTES(smb2_ioctl) \
260 SMBPROFILE_STATS_IOBYTES(smb2_cancel) \
261 SMBPROFILE_STATS_IOBYTES(smb2_keepalive) \
262 SMBPROFILE_STATS_IOBYTES(smb2_find) \
263 SMBPROFILE_STATS_IOBYTES(smb2_notify) \
264 SMBPROFILE_STATS_IOBYTES(smb2_getinfo) \
265 SMBPROFILE_STATS_IOBYTES(smb2_setinfo) \
266 SMBPROFILE_STATS_IOBYTES(smb2_break) \
267 SMBPROFILE_STATS_SECTION_END \
271 /* this file defines the profile structure in the profile shared
274 /* time values in the following structure are in microseconds */
276 struct smbprofile_stats_count
{
277 uint64_t count
; /* number of events */
280 struct smbprofile_stats_time
{
281 uint64_t time
; /* microseconds */
284 struct smbprofile_stats_time_async
{
286 struct smbprofile_stats_time
*stats
;
289 struct smbprofile_stats_basic
{
290 uint64_t count
; /* number of events */
291 uint64_t time
; /* microseconds */
294 struct smbprofile_stats_basic_async
{
296 struct smbprofile_stats_basic
*stats
;
299 struct smbprofile_stats_bytes
{
300 uint64_t count
; /* number of events */
301 uint64_t time
; /* microseconds */
302 uint64_t idle
; /* idle time compared to 'time' microseconds */
303 uint64_t bytes
; /* bytes */
306 struct smbprofile_stats_bytes_async
{
310 struct smbprofile_stats_bytes
*stats
;
313 struct smbprofile_stats_iobytes
{
314 uint64_t count
; /* number of events */
315 uint64_t time
; /* microseconds */
316 uint64_t idle
; /* idle time compared to 'time' microseconds */
317 uint64_t inbytes
; /* bytes read */
318 uint64_t outbytes
; /* bytes written */
321 struct smbprofile_stats_iobytes_async
{
325 struct smbprofile_stats_iobytes
*stats
;
328 struct profile_stats
{
331 #define SMBPROFILE_STATS_START
332 #define SMBPROFILE_STATS_SECTION_START(name, display)
333 #define SMBPROFILE_STATS_COUNT(name) \
334 struct smbprofile_stats_count name##_stats;
335 #define SMBPROFILE_STATS_TIME(name) \
336 struct smbprofile_stats_time name##_stats;
337 #define SMBPROFILE_STATS_BASIC(name) \
338 struct smbprofile_stats_basic name##_stats;
339 #define SMBPROFILE_STATS_BYTES(name) \
340 struct smbprofile_stats_bytes name##_stats;
341 #define SMBPROFILE_STATS_IOBYTES(name) \
342 struct smbprofile_stats_iobytes name##_stats;
343 #define SMBPROFILE_STATS_SECTION_END
344 #define SMBPROFILE_STATS_END
345 SMBPROFILE_STATS_ALL_SECTIONS
346 #undef SMBPROFILE_STATS_START
347 #undef SMBPROFILE_STATS_SECTION_START
348 #undef SMBPROFILE_STATS_COUNT
349 #undef SMBPROFILE_STATS_TIME
350 #undef SMBPROFILE_STATS_BASIC
351 #undef SMBPROFILE_STATS_BYTES
352 #undef SMBPROFILE_STATS_IOBYTES
353 #undef SMBPROFILE_STATS_SECTION_END
354 #undef SMBPROFILE_STATS_END
358 #define _SMBPROFILE_COUNT_INCREMENT(_stats, _area, _v) do { \
359 if (smbprofile_state.config.do_count) { \
360 (_area)->values._stats.count += (_v); \
361 smbprofile_dump_schedule(); \
364 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) \
365 _SMBPROFILE_COUNT_INCREMENT(_name##_stats, _area, _v)
367 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name) \
368 struct smbprofile_stats_time_async _async_name;
369 #define _SMBPROFILE_TIME_ASYNC_START(_stats, _area, _async) do { \
370 (_async) = (struct smbprofile_stats_time_async) {}; \
371 if (smbprofile_state.config.do_times) { \
372 (_async).stats = &((_area)->values._stats), \
373 (_async).start = profile_timestamp(); \
376 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) \
377 _SMBPROFILE_TIME_ASYNC_START(_name##_stats, _area, _async)
378 #define SMBPROFILE_TIME_ASYNC_END(_async) do { \
379 if ((_async).start != 0) { \
380 (_async).stats->time += profile_timestamp() - (_async).start; \
381 (_async) = (struct smbprofile_stats_basic_async) {}; \
382 smbprofile_dump_schedule(); \
386 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) \
387 struct smbprofile_stats_basic_async _async_name;
388 #define _SMBPROFILE_BASIC_ASYNC_START(_stats, _area, _async) do { \
389 (_async) = (struct smbprofile_stats_basic_async) {}; \
390 if (smbprofile_state.config.do_count) { \
391 if (smbprofile_state.config.do_times) { \
392 (_async).start = profile_timestamp(); \
393 (_async).stats = &((_area)->values._stats); \
395 (_area)->values._stats.count += 1; \
396 smbprofile_dump_schedule(); \
399 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) \
400 _SMBPROFILE_BASIC_ASYNC_START(_name##_stats, _area, _async)
401 #define SMBPROFILE_BASIC_ASYNC_END(_async) do { \
402 if ((_async).start != 0) { \
403 (_async).stats->time += profile_timestamp() - (_async).start; \
404 (_async) = (struct smbprofile_stats_basic_async) {}; \
405 smbprofile_dump_schedule(); \
409 #define _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async) do { \
410 (_async).stats = &((_area)->values._stats); \
411 if (smbprofile_state.config.do_times) { \
412 (_async).start = profile_timestamp(); \
415 #define _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) do { \
416 if ((_async).start != 0) { \
417 if ((_async).idle_start == 0) { \
418 (_async).idle_start = profile_timestamp(); \
422 #define _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) do { \
423 if ((_async).idle_start != 0) { \
424 (_async).idle_time += \
425 profile_timestamp() - (_async).idle_start; \
426 (_async).idle_start = 0; \
429 #define _SMBPROFILE_TIMER_ASYNC_END(_async) do { \
430 if ((_async).start != 0) { \
431 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async); \
432 (_async).stats->time += profile_timestamp() - (_async).start; \
433 (_async).stats->idle += (_async).idle_time; \
437 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) \
438 struct smbprofile_stats_bytes_async _async_name;
439 #define _SMBPROFILE_BYTES_ASYNC_START(_stats, _area, _async, _bytes) do { \
440 (_async) = (struct smbprofile_stats_bytes_async) {}; \
441 if (smbprofile_state.config.do_count) { \
442 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
443 (_area)->values._stats.count += 1; \
444 (_area)->values._stats.bytes += (_bytes); \
445 smbprofile_dump_schedule(); \
448 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _bytes) \
449 _SMBPROFILE_BYTES_ASYNC_START(_name##_stats, _area, _async, _bytes)
450 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) \
451 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
452 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) \
453 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
454 #define SMBPROFILE_BYTES_ASYNC_END(_async) do { \
455 if ((_async).stats != NULL) { \
456 _SMBPROFILE_TIMER_ASYNC_END(_async); \
457 (_async) = (struct smbprofile_stats_bytes_async) {}; \
458 smbprofile_dump_schedule(); \
462 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) \
463 struct smbprofile_stats_iobytes_async _async_name;
464 #define _SMBPROFILE_IOBYTES_ASYNC_START(_stats, _area, _async, _inbytes) do { \
465 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
466 if (smbprofile_state.config.do_count) { \
467 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
468 (_area)->values._stats.count += 1; \
469 (_area)->values._stats.inbytes += (_inbytes); \
470 smbprofile_dump_schedule(); \
473 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) \
474 _SMBPROFILE_IOBYTES_ASYNC_START(_name##_stats, _area, _async, _inbytes)
475 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) \
476 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
477 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) \
478 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
479 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) do { \
480 if ((_async).stats != NULL) { \
481 (_async).stats->outbytes += (_outbytes); \
482 _SMBPROFILE_TIMER_ASYNC_END(_async); \
483 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
484 smbprofile_dump_schedule(); \
488 extern struct profile_stats
*profile_p
;
490 struct smbprofile_global_state
{
493 struct tevent_context
*ev
;
494 struct tevent_timer
*te
;
503 struct profile_stats global
;
507 extern struct smbprofile_global_state smbprofile_state
;
509 void smbprofile_dump_schedule_timer(void);
510 void smbprofile_dump_setup(struct tevent_context
*ev
);
512 static inline void smbprofile_dump_schedule(void)
514 if (likely(smbprofile_state
.internal
.te
!= NULL
)) {
518 if (unlikely(smbprofile_state
.internal
.ev
== NULL
)) {
522 smbprofile_dump_schedule_timer();
525 static inline bool smbprofile_dump_pending(void)
527 if (smbprofile_state
.internal
.te
== NULL
) {
534 void smbprofile_dump(void);
536 void smbprofile_cleanup(pid_t pid
, pid_t dst
);
537 void smbprofile_stats_accumulate(struct profile_stats
*acc
,
538 const struct profile_stats
*add
);
539 void smbprofile_collect(struct profile_stats
*stats
);
541 static inline uint64_t profile_timestamp(void)
545 /* we might prefer to use the _COARSE clock variant of CLOCK_MONOTONIC
546 that one is faster but cached and "just" tick-wise precise */
547 clock_gettime_mono(&ts
);
548 return (ts
.tv_sec
* 1000000) + (ts
.tv_nsec
/ 1000); /* usec */
551 #define DO_PROFILE_INC(x) \
552 _SMBPROFILE_COUNT_INCREMENT(x##_stats, profile_p, 1); \
554 #define START_PROFILE(x) \
555 struct smbprofile_stats_basic_async __profasync_##x = {}; \
556 _SMBPROFILE_BASIC_ASYNC_START(x##_stats, profile_p, __profasync_##x);
558 #define START_PROFILE_BYTES(x,n) \
559 struct smbprofile_stats_bytes_async __profasync_##x = {}; \
560 _SMBPROFILE_BYTES_ASYNC_START(x##_stats, profile_p, __profasync_##x, n);
562 #define END_PROFILE(x) \
563 SMBPROFILE_BASIC_ASYNC_END(__profasync_##x)
565 #define END_PROFILE_BYTES(x) \
566 SMBPROFILE_BYTES_ASYNC_END(__profasync_##x)
568 #define PROFILE_TIMESTAMP(x) clock_gettime_mono(x)
570 #else /* WITH_PROFILE */
572 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v)
574 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name)
575 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async)
576 #define SMBPROFILE_TIME_ASYNC_END(_async)
578 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name)
579 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async)
580 #define SMBPROFILE_BASIC_ASYNC_END(_async)
582 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name)
583 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _inbytes)
584 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async)
585 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async)
586 #define SMBPROFILE_BYTES_ASYNC_END(_async)
588 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name)
589 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes)
590 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async)
591 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async)
592 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes)
594 #define DO_PROFILE_INC(x)
595 #define START_PROFILE(x)
596 #define START_PROFILE_BYTES(x,n)
597 #define END_PROFILE(x)
598 #define END_PROFILE_BYTES(x)
600 #define PROFILE_TIMESTAMP(x) (*(x)=(struct timespec){0})
602 static inline bool smbprofile_dump_pending(void)
607 static inline void smbprofile_dump_setup(struct tevent_context
*ev
)
612 static inline void smbprofile_dump(void)
617 static inline void smbprofile_cleanup(pid_t pid
, pid_t dst
)
622 #endif /* WITH_PROFILE */
624 /* The following definitions come from profile/profile.c */
627 void set_profile_level(int level
, const struct server_id
*src
);
629 struct messaging_context
;
630 bool profile_setup(struct messaging_context
*msg_ctx
, bool rdonly
);