tests/gkdi: Remove implicit clock skew offset
[Samba.git] / source3 / include / smbprofile.h
blob91af220051d90bd77dce57198f0f50959ec11e74
1 #ifndef _PROFILE_H_
2 #define _PROFILE_H_
3 /*
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 #include "replace.h"
25 #include <tdb.h>
26 #include "lib/util/time.h"
28 struct tevent_context;
30 #ifdef WITH_PROFILE
32 #define SMBPROFILE_STATS_ALL_SECTIONS \
33 SMBPROFILE_STATS_START \
35 SMBPROFILE_STATS_SECTION_START(global, "SMBD loop") \
36 SMBPROFILE_STATS_COUNT(connect) \
37 SMBPROFILE_STATS_COUNT(disconnect) \
38 SMBPROFILE_STATS_BASIC(idle) \
39 SMBPROFILE_STATS_TIME(cpu_user) \
40 SMBPROFILE_STATS_TIME(cpu_system) \
41 SMBPROFILE_STATS_COUNT(request) \
42 SMBPROFILE_STATS_BASIC(push_sec_ctx) \
43 SMBPROFILE_STATS_BASIC(set_sec_ctx) \
44 SMBPROFILE_STATS_BASIC(set_root_sec_ctx) \
45 SMBPROFILE_STATS_BASIC(pop_sec_ctx) \
46 SMBPROFILE_STATS_SECTION_END \
48 SMBPROFILE_STATS_SECTION_START(syscall, "System Calls") \
49 SMBPROFILE_STATS_BASIC(syscall_opendir) \
50 SMBPROFILE_STATS_BASIC(syscall_fdopendir) \
51 SMBPROFILE_STATS_BASIC(syscall_readdir) \
52 SMBPROFILE_STATS_BASIC(syscall_rewinddir) \
53 SMBPROFILE_STATS_BASIC(syscall_mkdirat) \
54 SMBPROFILE_STATS_BASIC(syscall_closedir) \
55 SMBPROFILE_STATS_BASIC(syscall_open) \
56 SMBPROFILE_STATS_BASIC(syscall_openat) \
57 SMBPROFILE_STATS_BASIC(syscall_createfile) \
58 SMBPROFILE_STATS_BASIC(syscall_close) \
59 SMBPROFILE_STATS_BYTES(syscall_pread) \
60 SMBPROFILE_STATS_BYTES(syscall_asys_pread) \
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_renameat) \
67 SMBPROFILE_STATS_BYTES(syscall_asys_fsync) \
68 SMBPROFILE_STATS_BASIC(syscall_stat) \
69 SMBPROFILE_STATS_BASIC(syscall_fstat) \
70 SMBPROFILE_STATS_BASIC(syscall_lstat) \
71 SMBPROFILE_STATS_BASIC(syscall_fstatat) \
72 SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \
73 SMBPROFILE_STATS_BASIC(syscall_unlinkat) \
74 SMBPROFILE_STATS_BASIC(syscall_chmod) \
75 SMBPROFILE_STATS_BASIC(syscall_fchmod) \
76 SMBPROFILE_STATS_BASIC(syscall_fchown) \
77 SMBPROFILE_STATS_BASIC(syscall_lchown) \
78 SMBPROFILE_STATS_BASIC(syscall_chdir) \
79 SMBPROFILE_STATS_BASIC(syscall_getwd) \
80 SMBPROFILE_STATS_BASIC(syscall_fntimes) \
81 SMBPROFILE_STATS_BASIC(syscall_ftruncate) \
82 SMBPROFILE_STATS_BASIC(syscall_fallocate) \
83 SMBPROFILE_STATS_BASIC(syscall_fcntl_lock) \
84 SMBPROFILE_STATS_BASIC(syscall_fcntl) \
85 SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \
86 SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \
87 SMBPROFILE_STATS_BASIC(syscall_readlinkat) \
88 SMBPROFILE_STATS_BASIC(syscall_symlinkat) \
89 SMBPROFILE_STATS_BASIC(syscall_linkat) \
90 SMBPROFILE_STATS_BASIC(syscall_mknodat) \
91 SMBPROFILE_STATS_BASIC(syscall_realpath) \
92 SMBPROFILE_STATS_BASIC(syscall_get_quota) \
93 SMBPROFILE_STATS_BASIC(syscall_set_quota) \
94 SMBPROFILE_STATS_BASIC(syscall_get_sd) \
95 SMBPROFILE_STATS_BASIC(syscall_set_sd) \
96 SMBPROFILE_STATS_BASIC(syscall_brl_lock) \
97 SMBPROFILE_STATS_BASIC(syscall_brl_unlock) \
98 SMBPROFILE_STATS_BASIC(syscall_brl_cancel) \
99 SMBPROFILE_STATS_BYTES(syscall_asys_getxattrat) \
100 SMBPROFILE_STATS_SECTION_END \
102 SMBPROFILE_STATS_SECTION_START(acl, "ACL Calls") \
103 SMBPROFILE_STATS_BASIC(get_nt_acl) \
104 SMBPROFILE_STATS_BASIC(get_nt_acl_at) \
105 SMBPROFILE_STATS_BASIC(fget_nt_acl) \
106 SMBPROFILE_STATS_BASIC(fset_nt_acl) \
107 SMBPROFILE_STATS_SECTION_END \
109 SMBPROFILE_STATS_SECTION_START(statcache, "Stat Cache") \
110 SMBPROFILE_STATS_COUNT(statcache_lookups) \
111 SMBPROFILE_STATS_COUNT(statcache_misses) \
112 SMBPROFILE_STATS_COUNT(statcache_hits) \
113 SMBPROFILE_STATS_SECTION_END \
115 SMBPROFILE_STATS_SECTION_START(SMB, "SMB Calls") \
116 SMBPROFILE_STATS_BASIC(SMBmkdir) \
117 SMBPROFILE_STATS_BASIC(SMBrmdir) \
118 SMBPROFILE_STATS_BASIC(SMBopen) \
119 SMBPROFILE_STATS_BASIC(SMBcreate) \
120 SMBPROFILE_STATS_BASIC(SMBclose) \
121 SMBPROFILE_STATS_BASIC(SMBflush) \
122 SMBPROFILE_STATS_BASIC(SMBunlink) \
123 SMBPROFILE_STATS_BASIC(SMBmv) \
124 SMBPROFILE_STATS_BASIC(SMBgetatr) \
125 SMBPROFILE_STATS_BASIC(SMBsetatr) \
126 SMBPROFILE_STATS_BASIC(SMBread) \
127 SMBPROFILE_STATS_BASIC(SMBwrite) \
128 SMBPROFILE_STATS_BASIC(SMBlock) \
129 SMBPROFILE_STATS_BASIC(SMBunlock) \
130 SMBPROFILE_STATS_BASIC(SMBctemp) \
131 SMBPROFILE_STATS_BASIC(SMBmknew) \
132 SMBPROFILE_STATS_BASIC(SMBcheckpath) \
133 SMBPROFILE_STATS_BASIC(SMBexit) \
134 SMBPROFILE_STATS_BASIC(SMBlseek) \
135 SMBPROFILE_STATS_BASIC(SMBlockread) \
136 SMBPROFILE_STATS_BASIC(SMBwriteunlock) \
137 SMBPROFILE_STATS_BASIC(SMBreadbraw) \
138 SMBPROFILE_STATS_BASIC(SMBreadBmpx) \
139 SMBPROFILE_STATS_BASIC(SMBreadBs) \
140 SMBPROFILE_STATS_BASIC(SMBwritebraw) \
141 SMBPROFILE_STATS_BASIC(SMBwriteBmpx) \
142 SMBPROFILE_STATS_BASIC(SMBwriteBs) \
143 SMBPROFILE_STATS_BASIC(SMBwritec) \
144 SMBPROFILE_STATS_BASIC(SMBsetattrE) \
145 SMBPROFILE_STATS_BASIC(SMBgetattrE) \
146 SMBPROFILE_STATS_BASIC(SMBlockingX) \
147 SMBPROFILE_STATS_BASIC(SMBtrans) \
148 SMBPROFILE_STATS_BASIC(SMBtranss) \
149 SMBPROFILE_STATS_BASIC(SMBioctl) \
150 SMBPROFILE_STATS_BASIC(SMBioctls) \
151 SMBPROFILE_STATS_BASIC(SMBcopy) \
152 SMBPROFILE_STATS_BASIC(SMBmove) \
153 SMBPROFILE_STATS_BASIC(SMBecho) \
154 SMBPROFILE_STATS_BASIC(SMBwriteclose) \
155 SMBPROFILE_STATS_BASIC(SMBopenX) \
156 SMBPROFILE_STATS_BASIC(SMBreadX) \
157 SMBPROFILE_STATS_BASIC(SMBwriteX) \
158 SMBPROFILE_STATS_BASIC(SMBtrans2) \
159 SMBPROFILE_STATS_BASIC(SMBtranss2) \
160 SMBPROFILE_STATS_BASIC(SMBfindclose) \
161 SMBPROFILE_STATS_BASIC(SMBfindnclose) \
162 SMBPROFILE_STATS_BASIC(SMBtcon) \
163 SMBPROFILE_STATS_BASIC(SMBtdis) \
164 SMBPROFILE_STATS_BASIC(SMBnegprot) \
165 SMBPROFILE_STATS_BASIC(SMBsesssetupX) \
166 SMBPROFILE_STATS_BASIC(SMBulogoffX) \
167 SMBPROFILE_STATS_BASIC(SMBtconX) \
168 SMBPROFILE_STATS_BASIC(SMBdskattr) \
169 SMBPROFILE_STATS_BASIC(SMBsearch) \
170 SMBPROFILE_STATS_BASIC(SMBffirst) \
171 SMBPROFILE_STATS_BASIC(SMBfunique) \
172 SMBPROFILE_STATS_BASIC(SMBfclose) \
173 SMBPROFILE_STATS_BASIC(SMBnttrans) \
174 SMBPROFILE_STATS_BASIC(SMBnttranss) \
175 SMBPROFILE_STATS_BASIC(SMBntcreateX) \
176 SMBPROFILE_STATS_BASIC(SMBntcancel) \
177 SMBPROFILE_STATS_BASIC(SMBntrename) \
178 SMBPROFILE_STATS_BASIC(SMBsplopen) \
179 SMBPROFILE_STATS_BASIC(SMBsplwr) \
180 SMBPROFILE_STATS_BASIC(SMBsplclose) \
181 SMBPROFILE_STATS_BASIC(SMBsplretq) \
182 SMBPROFILE_STATS_BASIC(SMBsends) \
183 SMBPROFILE_STATS_BASIC(SMBsendb) \
184 SMBPROFILE_STATS_BASIC(SMBfwdname) \
185 SMBPROFILE_STATS_BASIC(SMBcancelf) \
186 SMBPROFILE_STATS_BASIC(SMBgetmac) \
187 SMBPROFILE_STATS_BASIC(SMBsendstrt) \
188 SMBPROFILE_STATS_BASIC(SMBsendend) \
189 SMBPROFILE_STATS_BASIC(SMBsendtxt) \
190 SMBPROFILE_STATS_BASIC(SMBinvalid) \
191 SMBPROFILE_STATS_SECTION_END \
193 SMBPROFILE_STATS_SECTION_START(Trans2, "Trans2 Calls") \
194 SMBPROFILE_STATS_BASIC(Trans2_open) \
195 SMBPROFILE_STATS_BASIC(Trans2_findfirst) \
196 SMBPROFILE_STATS_BASIC(Trans2_findnext) \
197 SMBPROFILE_STATS_BASIC(Trans2_qfsinfo) \
198 SMBPROFILE_STATS_BASIC(Trans2_setfsinfo) \
199 SMBPROFILE_STATS_BASIC(Trans2_qpathinfo) \
200 SMBPROFILE_STATS_BASIC(Trans2_setpathinfo) \
201 SMBPROFILE_STATS_BASIC(Trans2_qfileinfo) \
202 SMBPROFILE_STATS_BASIC(Trans2_setfileinfo) \
203 SMBPROFILE_STATS_BASIC(Trans2_fsctl) \
204 SMBPROFILE_STATS_BASIC(Trans2_ioctl) \
205 SMBPROFILE_STATS_BASIC(Trans2_findnotifyfirst) \
206 SMBPROFILE_STATS_BASIC(Trans2_findnotifynext) \
207 SMBPROFILE_STATS_BASIC(Trans2_mkdir) \
208 SMBPROFILE_STATS_BASIC(Trans2_session_setup) \
209 SMBPROFILE_STATS_BASIC(Trans2_get_dfs_referral) \
210 SMBPROFILE_STATS_BASIC(Trans2_report_dfs_inconsistancy) \
211 SMBPROFILE_STATS_SECTION_END \
213 SMBPROFILE_STATS_SECTION_START(NT_transact, "NT Transact Calls") \
214 SMBPROFILE_STATS_BASIC(NT_transact_create) \
215 SMBPROFILE_STATS_BASIC(NT_transact_ioctl) \
216 SMBPROFILE_STATS_BASIC(NT_transact_set_security_desc) \
217 SMBPROFILE_STATS_BASIC(NT_transact_notify_change) \
218 SMBPROFILE_STATS_BASIC(NT_transact_rename) \
219 SMBPROFILE_STATS_BASIC(NT_transact_query_security_desc) \
220 SMBPROFILE_STATS_BASIC(NT_transact_get_user_quota) \
221 SMBPROFILE_STATS_BASIC(NT_transact_set_user_quota) \
222 SMBPROFILE_STATS_SECTION_END \
224 SMBPROFILE_STATS_SECTION_START(smb2, "SMB2 Calls") \
225 SMBPROFILE_STATS_IOBYTES(smb2_negprot) \
226 SMBPROFILE_STATS_IOBYTES(smb2_sesssetup) \
227 SMBPROFILE_STATS_IOBYTES(smb2_logoff) \
228 SMBPROFILE_STATS_IOBYTES(smb2_tcon) \
229 SMBPROFILE_STATS_IOBYTES(smb2_tdis) \
230 SMBPROFILE_STATS_IOBYTES(smb2_create) \
231 SMBPROFILE_STATS_IOBYTES(smb2_close) \
232 SMBPROFILE_STATS_IOBYTES(smb2_flush) \
233 SMBPROFILE_STATS_IOBYTES(smb2_read) \
234 SMBPROFILE_STATS_IOBYTES(smb2_write) \
235 SMBPROFILE_STATS_IOBYTES(smb2_lock) \
236 SMBPROFILE_STATS_IOBYTES(smb2_ioctl) \
237 SMBPROFILE_STATS_IOBYTES(smb2_cancel) \
238 SMBPROFILE_STATS_IOBYTES(smb2_keepalive) \
239 SMBPROFILE_STATS_IOBYTES(smb2_find) \
240 SMBPROFILE_STATS_IOBYTES(smb2_notify) \
241 SMBPROFILE_STATS_IOBYTES(smb2_getinfo) \
242 SMBPROFILE_STATS_IOBYTES(smb2_setinfo) \
243 SMBPROFILE_STATS_IOBYTES(smb2_break) \
244 SMBPROFILE_STATS_SECTION_END \
246 SMBPROFILE_STATS_END
248 /* this file defines the profile structure in the profile shared
249 memory area */
251 /* time values in the following structure are in microseconds */
253 struct smbprofile_stats_count {
254 uint64_t count; /* number of events */
257 struct smbprofile_stats_time {
258 uint64_t time; /* microseconds */
261 struct smbprofile_stats_time_async {
262 uint64_t start;
263 struct smbprofile_stats_time *stats;
266 struct smbprofile_stats_basic {
267 uint64_t count; /* number of events */
268 uint64_t time; /* microseconds */
271 struct smbprofile_stats_basic_async {
272 uint64_t start;
273 struct smbprofile_stats_basic *stats;
276 struct smbprofile_stats_bytes {
277 uint64_t count; /* number of events */
278 uint64_t time; /* microseconds */
279 uint64_t idle; /* idle time compared to 'time' microseconds */
280 uint64_t bytes; /* bytes */
283 struct smbprofile_stats_bytes_async {
284 uint64_t start;
285 uint64_t idle_start;
286 uint64_t idle_time;
287 struct smbprofile_stats_bytes *stats;
290 struct smbprofile_stats_iobytes {
291 uint64_t count; /* number of events */
292 uint64_t time; /* microseconds */
293 uint64_t idle; /* idle time compared to 'time' microseconds */
294 uint64_t inbytes; /* bytes read */
295 uint64_t outbytes; /* bytes written */
298 struct smbprofile_stats_iobytes_async {
299 uint64_t start;
300 uint64_t idle_start;
301 uint64_t idle_time;
302 struct smbprofile_stats_iobytes *stats;
305 struct profile_stats {
306 uint64_t magic;
307 struct {
308 #define SMBPROFILE_STATS_START
309 #define SMBPROFILE_STATS_SECTION_START(name, display)
310 #define SMBPROFILE_STATS_COUNT(name) \
311 struct smbprofile_stats_count name##_stats;
312 #define SMBPROFILE_STATS_TIME(name) \
313 struct smbprofile_stats_time name##_stats;
314 #define SMBPROFILE_STATS_BASIC(name) \
315 struct smbprofile_stats_basic name##_stats;
316 #define SMBPROFILE_STATS_BYTES(name) \
317 struct smbprofile_stats_bytes name##_stats;
318 #define SMBPROFILE_STATS_IOBYTES(name) \
319 struct smbprofile_stats_iobytes name##_stats;
320 #define SMBPROFILE_STATS_SECTION_END
321 #define SMBPROFILE_STATS_END
322 SMBPROFILE_STATS_ALL_SECTIONS
323 #undef SMBPROFILE_STATS_START
324 #undef SMBPROFILE_STATS_SECTION_START
325 #undef SMBPROFILE_STATS_COUNT
326 #undef SMBPROFILE_STATS_TIME
327 #undef SMBPROFILE_STATS_BASIC
328 #undef SMBPROFILE_STATS_BYTES
329 #undef SMBPROFILE_STATS_IOBYTES
330 #undef SMBPROFILE_STATS_SECTION_END
331 #undef SMBPROFILE_STATS_END
332 } values;
335 #define _SMBPROFILE_COUNT_INCREMENT(_stats, _area, _v) do { \
336 if (smbprofile_state.config.do_count) { \
337 (_area)->values._stats.count += (_v); \
338 smbprofile_dump_schedule(); \
340 } while(0)
341 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) \
342 _SMBPROFILE_COUNT_INCREMENT(_name##_stats, _area, _v)
344 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name) \
345 struct smbprofile_stats_time_async _async_name;
346 #define _SMBPROFILE_TIME_ASYNC_START(_stats, _area, _async) do { \
347 (_async) = (struct smbprofile_stats_time_async) {}; \
348 if (smbprofile_state.config.do_times) { \
349 (_async).stats = &((_area)->values._stats), \
350 (_async).start = profile_timestamp(); \
352 } while(0)
353 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) \
354 _SMBPROFILE_TIME_ASYNC_START(_name##_stats, _area, _async)
355 #define SMBPROFILE_TIME_ASYNC_END(_async) do { \
356 if ((_async).start != 0) { \
357 (_async).stats->time += profile_timestamp() - (_async).start; \
358 (_async) = (struct smbprofile_stats_basic_async) {}; \
359 smbprofile_dump_schedule(); \
361 } while(0)
363 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) \
364 struct smbprofile_stats_basic_async _async_name;
365 #define _SMBPROFILE_BASIC_ASYNC_START(_stats, _area, _async) do { \
366 (_async) = (struct smbprofile_stats_basic_async) {}; \
367 if (smbprofile_state.config.do_count) { \
368 if (smbprofile_state.config.do_times) { \
369 (_async).start = profile_timestamp(); \
370 (_async).stats = &((_area)->values._stats); \
372 (_area)->values._stats.count += 1; \
373 smbprofile_dump_schedule(); \
375 } while(0)
376 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) \
377 _SMBPROFILE_BASIC_ASYNC_START(_name##_stats, _area, _async)
378 #define SMBPROFILE_BASIC_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(); \
384 } while(0)
386 #define _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async) do { \
387 (_async).stats = &((_area)->values._stats); \
388 if (smbprofile_state.config.do_times) { \
389 (_async).start = profile_timestamp(); \
391 } while(0)
392 #define _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) do { \
393 if ((_async).start != 0) { \
394 if ((_async).idle_start == 0) { \
395 (_async).idle_start = profile_timestamp(); \
398 } while(0)
399 #define _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) do { \
400 if ((_async).idle_start != 0) { \
401 (_async).idle_time += \
402 profile_timestamp() - (_async).idle_start; \
403 (_async).idle_start = 0; \
405 } while(0)
406 #define _SMBPROFILE_TIMER_ASYNC_END(_async) do { \
407 if ((_async).start != 0) { \
408 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async); \
409 (_async).stats->time += profile_timestamp() - (_async).start; \
410 (_async).stats->idle += (_async).idle_time; \
412 } while(0)
414 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) \
415 struct smbprofile_stats_bytes_async _async_name;
416 #define _SMBPROFILE_BYTES_ASYNC_START(_stats, _area, _async, _bytes) do { \
417 (_async) = (struct smbprofile_stats_bytes_async) {}; \
418 if (smbprofile_state.config.do_count) { \
419 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
420 (_area)->values._stats.count += 1; \
421 (_area)->values._stats.bytes += (_bytes); \
422 smbprofile_dump_schedule(); \
424 } while(0)
425 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _bytes) \
426 _SMBPROFILE_BYTES_ASYNC_START(_name##_stats, _area, _async, _bytes)
427 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) \
428 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
429 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) \
430 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
431 #define SMBPROFILE_BYTES_ASYNC_END(_async) do { \
432 if ((_async).stats != NULL) { \
433 _SMBPROFILE_TIMER_ASYNC_END(_async); \
434 (_async) = (struct smbprofile_stats_bytes_async) {}; \
435 smbprofile_dump_schedule(); \
437 } while(0)
439 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) \
440 struct smbprofile_stats_iobytes_async _async_name;
441 #define _SMBPROFILE_IOBYTES_ASYNC_START(_stats, _area, _async, _inbytes) do { \
442 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
443 if (smbprofile_state.config.do_count) { \
444 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
445 (_area)->values._stats.count += 1; \
446 (_area)->values._stats.inbytes += (_inbytes); \
447 smbprofile_dump_schedule(); \
449 } while(0)
450 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) \
451 _SMBPROFILE_IOBYTES_ASYNC_START(_name##_stats, _area, _async, _inbytes)
452 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) \
453 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
454 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) \
455 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
456 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) do { \
457 if ((_async).stats != NULL) { \
458 (_async).stats->outbytes += (_outbytes); \
459 _SMBPROFILE_TIMER_ASYNC_END(_async); \
460 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
461 smbprofile_dump_schedule(); \
463 } while(0)
465 extern struct profile_stats *profile_p;
467 struct smbprofile_global_state {
468 struct {
469 struct tdb_wrap *db;
470 struct tevent_context *ev;
471 struct tevent_timer *te;
472 } internal;
474 struct {
475 bool do_count;
476 bool do_times;
477 } config;
479 struct {
480 struct profile_stats global;
481 } stats;
484 extern struct smbprofile_global_state smbprofile_state;
486 void smbprofile_dump_schedule_timer(void);
487 void smbprofile_dump_setup(struct tevent_context *ev);
489 static inline void smbprofile_dump_schedule(void)
491 if (likely(smbprofile_state.internal.te != NULL)) {
492 return;
495 if (unlikely(smbprofile_state.internal.ev == NULL)) {
496 return;
499 smbprofile_dump_schedule_timer();
502 static inline bool smbprofile_active(void)
504 return smbprofile_state.config.do_count;
507 static inline bool smbprofile_dump_pending(void)
509 if (smbprofile_state.internal.te == NULL) {
510 return false;
513 return true;
516 void smbprofile_dump(void);
518 void smbprofile_cleanup(pid_t pid, pid_t dst);
519 void smbprofile_stats_accumulate(struct profile_stats *acc,
520 const struct profile_stats *add);
521 int smbprofile_magic(const struct profile_stats *stats, uint64_t *_magic);
522 void smbprofile_collect_tdb(struct tdb_context *tdb,
523 uint64_t magic,
524 struct profile_stats *stats);
525 void smbprofile_collect(struct profile_stats *stats);
527 static inline uint64_t profile_timestamp(void)
529 struct timespec ts;
531 /* we might prefer to use the _COARSE clock variant of CLOCK_MONOTONIC
532 that one is faster but cached and "just" tick-wise precise */
533 clock_gettime_mono(&ts);
534 return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); /* usec */
537 #define DO_PROFILE_INC(x) \
538 _SMBPROFILE_COUNT_INCREMENT(x##_stats, profile_p, 1); \
540 #define START_PROFILE(x) \
541 struct smbprofile_stats_basic_async __profasync_##x = {}; \
542 _SMBPROFILE_BASIC_ASYNC_START(x##_stats, profile_p, __profasync_##x);
544 #define START_PROFILE_BYTES(x,n) \
545 struct smbprofile_stats_bytes_async __profasync_##x = {}; \
546 _SMBPROFILE_BYTES_ASYNC_START(x##_stats, profile_p, __profasync_##x, n);
548 #define END_PROFILE(x) \
549 SMBPROFILE_BASIC_ASYNC_END(__profasync_##x)
551 #define END_PROFILE_BYTES(x) \
552 SMBPROFILE_BYTES_ASYNC_END(__profasync_##x)
554 #define PROFILE_TIMESTAMP(x) clock_gettime_mono(x)
556 #else /* WITH_PROFILE */
558 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v)
560 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name)
561 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async)
562 #define SMBPROFILE_TIME_ASYNC_END(_async)
564 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name)
565 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async)
566 #define SMBPROFILE_BASIC_ASYNC_END(_async)
568 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name)
569 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _inbytes)
570 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async)
571 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async)
572 #define SMBPROFILE_BYTES_ASYNC_END(_async)
574 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name)
575 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes)
576 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async)
577 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async)
578 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes)
580 #define DO_PROFILE_INC(x)
581 #define START_PROFILE(x)
582 #define START_PROFILE_BYTES(x,n)
583 #define END_PROFILE(x)
584 #define END_PROFILE_BYTES(x)
586 #define PROFILE_TIMESTAMP(x) (*(x)=(struct timespec){0})
588 static inline bool smbprofile_active(void)
590 return false;
593 static inline bool smbprofile_dump_pending(void)
595 return false;
598 static inline void smbprofile_dump_setup(struct tevent_context *ev)
600 return;
603 static inline void smbprofile_dump(void)
605 return;
608 static inline void smbprofile_cleanup(pid_t pid, pid_t dst)
610 return;
613 #endif /* WITH_PROFILE */
615 /* The following definitions come from profile/profile.c */
616 struct server_id;
618 void set_profile_level(int level, const struct server_id *src);
620 struct messaging_context;
621 bool profile_setup(struct messaging_context *msg_ctx, bool rdonly);
623 #endif