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_mkdirat) \
52 SMBPROFILE_STATS_BASIC(syscall_closedir) \
53 SMBPROFILE_STATS_BASIC(syscall_open) \
54 SMBPROFILE_STATS_BASIC(syscall_createfile) \
55 SMBPROFILE_STATS_BASIC(syscall_close) \
56 SMBPROFILE_STATS_BYTES(syscall_pread) \
57 SMBPROFILE_STATS_BYTES(syscall_asys_pread) \
58 SMBPROFILE_STATS_BYTES(syscall_pwrite) \
59 SMBPROFILE_STATS_BYTES(syscall_asys_pwrite) \
60 SMBPROFILE_STATS_BASIC(syscall_lseek) \
61 SMBPROFILE_STATS_BYTES(syscall_sendfile) \
62 SMBPROFILE_STATS_BYTES(syscall_recvfile) \
63 SMBPROFILE_STATS_BASIC(syscall_renameat) \
64 SMBPROFILE_STATS_BYTES(syscall_asys_fsync) \
65 SMBPROFILE_STATS_BASIC(syscall_stat) \
66 SMBPROFILE_STATS_BASIC(syscall_fstat) \
67 SMBPROFILE_STATS_BASIC(syscall_lstat) \
68 SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \
69 SMBPROFILE_STATS_BASIC(syscall_unlinkat) \
70 SMBPROFILE_STATS_BASIC(syscall_chmod) \
71 SMBPROFILE_STATS_BASIC(syscall_fchmod) \
72 SMBPROFILE_STATS_BASIC(syscall_fchown) \
73 SMBPROFILE_STATS_BASIC(syscall_lchown) \
74 SMBPROFILE_STATS_BASIC(syscall_chdir) \
75 SMBPROFILE_STATS_BASIC(syscall_getwd) \
76 SMBPROFILE_STATS_BASIC(syscall_ntimes) \
77 SMBPROFILE_STATS_BASIC(syscall_ftruncate) \
78 SMBPROFILE_STATS_BASIC(syscall_fallocate) \
79 SMBPROFILE_STATS_BASIC(syscall_fcntl_lock) \
80 SMBPROFILE_STATS_BASIC(syscall_kernel_flock) \
81 SMBPROFILE_STATS_BASIC(syscall_fcntl) \
82 SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \
83 SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \
84 SMBPROFILE_STATS_BASIC(syscall_readlinkat) \
85 SMBPROFILE_STATS_BASIC(syscall_symlinkat) \
86 SMBPROFILE_STATS_BASIC(syscall_linkat) \
87 SMBPROFILE_STATS_BASIC(syscall_mknodat) \
88 SMBPROFILE_STATS_BASIC(syscall_realpath) \
89 SMBPROFILE_STATS_BASIC(syscall_get_quota) \
90 SMBPROFILE_STATS_BASIC(syscall_set_quota) \
91 SMBPROFILE_STATS_BASIC(syscall_get_sd) \
92 SMBPROFILE_STATS_BASIC(syscall_set_sd) \
93 SMBPROFILE_STATS_BASIC(syscall_brl_lock) \
94 SMBPROFILE_STATS_BASIC(syscall_brl_unlock) \
95 SMBPROFILE_STATS_BASIC(syscall_brl_cancel) \
96 SMBPROFILE_STATS_BYTES(syscall_asys_getxattrat) \
97 SMBPROFILE_STATS_SECTION_END \
99 SMBPROFILE_STATS_SECTION_START(acl, "ACL Calls") \
100 SMBPROFILE_STATS_BASIC(get_nt_acl) \
101 SMBPROFILE_STATS_BASIC(fget_nt_acl) \
102 SMBPROFILE_STATS_BASIC(fset_nt_acl) \
103 SMBPROFILE_STATS_SECTION_END \
105 SMBPROFILE_STATS_SECTION_START(statcache, "Stat Cache") \
106 SMBPROFILE_STATS_COUNT(statcache_lookups) \
107 SMBPROFILE_STATS_COUNT(statcache_misses) \
108 SMBPROFILE_STATS_COUNT(statcache_hits) \
109 SMBPROFILE_STATS_SECTION_END \
111 SMBPROFILE_STATS_SECTION_START(SMB, "SMB Calls") \
112 SMBPROFILE_STATS_BASIC(SMBmkdir) \
113 SMBPROFILE_STATS_BASIC(SMBrmdir) \
114 SMBPROFILE_STATS_BASIC(SMBopen) \
115 SMBPROFILE_STATS_BASIC(SMBcreate) \
116 SMBPROFILE_STATS_BASIC(SMBclose) \
117 SMBPROFILE_STATS_BASIC(SMBflush) \
118 SMBPROFILE_STATS_BASIC(SMBunlink) \
119 SMBPROFILE_STATS_BASIC(SMBmv) \
120 SMBPROFILE_STATS_BASIC(SMBgetatr) \
121 SMBPROFILE_STATS_BASIC(SMBsetatr) \
122 SMBPROFILE_STATS_BASIC(SMBread) \
123 SMBPROFILE_STATS_BASIC(SMBwrite) \
124 SMBPROFILE_STATS_BASIC(SMBlock) \
125 SMBPROFILE_STATS_BASIC(SMBunlock) \
126 SMBPROFILE_STATS_BASIC(SMBctemp) \
127 SMBPROFILE_STATS_BASIC(SMBmknew) \
128 SMBPROFILE_STATS_BASIC(SMBcheckpath) \
129 SMBPROFILE_STATS_BASIC(SMBexit) \
130 SMBPROFILE_STATS_BASIC(SMBlseek) \
131 SMBPROFILE_STATS_BASIC(SMBlockread) \
132 SMBPROFILE_STATS_BASIC(SMBwriteunlock) \
133 SMBPROFILE_STATS_BASIC(SMBreadbraw) \
134 SMBPROFILE_STATS_BASIC(SMBreadBmpx) \
135 SMBPROFILE_STATS_BASIC(SMBreadBs) \
136 SMBPROFILE_STATS_BASIC(SMBwritebraw) \
137 SMBPROFILE_STATS_BASIC(SMBwriteBmpx) \
138 SMBPROFILE_STATS_BASIC(SMBwriteBs) \
139 SMBPROFILE_STATS_BASIC(SMBwritec) \
140 SMBPROFILE_STATS_BASIC(SMBsetattrE) \
141 SMBPROFILE_STATS_BASIC(SMBgetattrE) \
142 SMBPROFILE_STATS_BASIC(SMBlockingX) \
143 SMBPROFILE_STATS_BASIC(SMBtrans) \
144 SMBPROFILE_STATS_BASIC(SMBtranss) \
145 SMBPROFILE_STATS_BASIC(SMBioctl) \
146 SMBPROFILE_STATS_BASIC(SMBioctls) \
147 SMBPROFILE_STATS_BASIC(SMBcopy) \
148 SMBPROFILE_STATS_BASIC(SMBmove) \
149 SMBPROFILE_STATS_BASIC(SMBecho) \
150 SMBPROFILE_STATS_BASIC(SMBwriteclose) \
151 SMBPROFILE_STATS_BASIC(SMBopenX) \
152 SMBPROFILE_STATS_BASIC(SMBreadX) \
153 SMBPROFILE_STATS_BASIC(SMBwriteX) \
154 SMBPROFILE_STATS_BASIC(SMBtrans2) \
155 SMBPROFILE_STATS_BASIC(SMBtranss2) \
156 SMBPROFILE_STATS_BASIC(SMBfindclose) \
157 SMBPROFILE_STATS_BASIC(SMBfindnclose) \
158 SMBPROFILE_STATS_BASIC(SMBtcon) \
159 SMBPROFILE_STATS_BASIC(SMBtdis) \
160 SMBPROFILE_STATS_BASIC(SMBnegprot) \
161 SMBPROFILE_STATS_BASIC(SMBsesssetupX) \
162 SMBPROFILE_STATS_BASIC(SMBulogoffX) \
163 SMBPROFILE_STATS_BASIC(SMBtconX) \
164 SMBPROFILE_STATS_BASIC(SMBdskattr) \
165 SMBPROFILE_STATS_BASIC(SMBsearch) \
166 SMBPROFILE_STATS_BASIC(SMBffirst) \
167 SMBPROFILE_STATS_BASIC(SMBfunique) \
168 SMBPROFILE_STATS_BASIC(SMBfclose) \
169 SMBPROFILE_STATS_BASIC(SMBnttrans) \
170 SMBPROFILE_STATS_BASIC(SMBnttranss) \
171 SMBPROFILE_STATS_BASIC(SMBntcreateX) \
172 SMBPROFILE_STATS_BASIC(SMBntcancel) \
173 SMBPROFILE_STATS_BASIC(SMBntrename) \
174 SMBPROFILE_STATS_BASIC(SMBsplopen) \
175 SMBPROFILE_STATS_BASIC(SMBsplwr) \
176 SMBPROFILE_STATS_BASIC(SMBsplclose) \
177 SMBPROFILE_STATS_BASIC(SMBsplretq) \
178 SMBPROFILE_STATS_BASIC(SMBsends) \
179 SMBPROFILE_STATS_BASIC(SMBsendb) \
180 SMBPROFILE_STATS_BASIC(SMBfwdname) \
181 SMBPROFILE_STATS_BASIC(SMBcancelf) \
182 SMBPROFILE_STATS_BASIC(SMBgetmac) \
183 SMBPROFILE_STATS_BASIC(SMBsendstrt) \
184 SMBPROFILE_STATS_BASIC(SMBsendend) \
185 SMBPROFILE_STATS_BASIC(SMBsendtxt) \
186 SMBPROFILE_STATS_BASIC(SMBinvalid) \
187 SMBPROFILE_STATS_SECTION_END \
189 SMBPROFILE_STATS_SECTION_START(Trans2, "Trans2 Calls") \
190 SMBPROFILE_STATS_BASIC(Trans2_open) \
191 SMBPROFILE_STATS_BASIC(Trans2_findfirst) \
192 SMBPROFILE_STATS_BASIC(Trans2_findnext) \
193 SMBPROFILE_STATS_BASIC(Trans2_qfsinfo) \
194 SMBPROFILE_STATS_BASIC(Trans2_setfsinfo) \
195 SMBPROFILE_STATS_BASIC(Trans2_qpathinfo) \
196 SMBPROFILE_STATS_BASIC(Trans2_setpathinfo) \
197 SMBPROFILE_STATS_BASIC(Trans2_qfileinfo) \
198 SMBPROFILE_STATS_BASIC(Trans2_setfileinfo) \
199 SMBPROFILE_STATS_BASIC(Trans2_fsctl) \
200 SMBPROFILE_STATS_BASIC(Trans2_ioctl) \
201 SMBPROFILE_STATS_BASIC(Trans2_findnotifyfirst) \
202 SMBPROFILE_STATS_BASIC(Trans2_findnotifynext) \
203 SMBPROFILE_STATS_BASIC(Trans2_mkdir) \
204 SMBPROFILE_STATS_BASIC(Trans2_session_setup) \
205 SMBPROFILE_STATS_BASIC(Trans2_get_dfs_referral) \
206 SMBPROFILE_STATS_BASIC(Trans2_report_dfs_inconsistancy) \
207 SMBPROFILE_STATS_SECTION_END \
209 SMBPROFILE_STATS_SECTION_START(NT_transact, "NT Transact Calls") \
210 SMBPROFILE_STATS_BASIC(NT_transact_create) \
211 SMBPROFILE_STATS_BASIC(NT_transact_ioctl) \
212 SMBPROFILE_STATS_BASIC(NT_transact_set_security_desc) \
213 SMBPROFILE_STATS_BASIC(NT_transact_notify_change) \
214 SMBPROFILE_STATS_BASIC(NT_transact_rename) \
215 SMBPROFILE_STATS_BASIC(NT_transact_query_security_desc) \
216 SMBPROFILE_STATS_BASIC(NT_transact_get_user_quota) \
217 SMBPROFILE_STATS_BASIC(NT_transact_set_user_quota) \
218 SMBPROFILE_STATS_SECTION_END \
220 SMBPROFILE_STATS_SECTION_START(smb2, "SMB2 Calls") \
221 SMBPROFILE_STATS_IOBYTES(smb2_negprot) \
222 SMBPROFILE_STATS_IOBYTES(smb2_sesssetup) \
223 SMBPROFILE_STATS_IOBYTES(smb2_logoff) \
224 SMBPROFILE_STATS_IOBYTES(smb2_tcon) \
225 SMBPROFILE_STATS_IOBYTES(smb2_tdis) \
226 SMBPROFILE_STATS_IOBYTES(smb2_create) \
227 SMBPROFILE_STATS_IOBYTES(smb2_close) \
228 SMBPROFILE_STATS_IOBYTES(smb2_flush) \
229 SMBPROFILE_STATS_IOBYTES(smb2_read) \
230 SMBPROFILE_STATS_IOBYTES(smb2_write) \
231 SMBPROFILE_STATS_IOBYTES(smb2_lock) \
232 SMBPROFILE_STATS_IOBYTES(smb2_ioctl) \
233 SMBPROFILE_STATS_IOBYTES(smb2_cancel) \
234 SMBPROFILE_STATS_IOBYTES(smb2_keepalive) \
235 SMBPROFILE_STATS_IOBYTES(smb2_find) \
236 SMBPROFILE_STATS_IOBYTES(smb2_notify) \
237 SMBPROFILE_STATS_IOBYTES(smb2_getinfo) \
238 SMBPROFILE_STATS_IOBYTES(smb2_setinfo) \
239 SMBPROFILE_STATS_IOBYTES(smb2_break) \
240 SMBPROFILE_STATS_SECTION_END \
244 /* this file defines the profile structure in the profile shared
247 /* time values in the following structure are in microseconds */
249 struct smbprofile_stats_count
{
250 uint64_t count
; /* number of events */
253 struct smbprofile_stats_time
{
254 uint64_t time
; /* microseconds */
257 struct smbprofile_stats_time_async
{
259 struct smbprofile_stats_time
*stats
;
262 struct smbprofile_stats_basic
{
263 uint64_t count
; /* number of events */
264 uint64_t time
; /* microseconds */
267 struct smbprofile_stats_basic_async
{
269 struct smbprofile_stats_basic
*stats
;
272 struct smbprofile_stats_bytes
{
273 uint64_t count
; /* number of events */
274 uint64_t time
; /* microseconds */
275 uint64_t idle
; /* idle time compared to 'time' microseconds */
276 uint64_t bytes
; /* bytes */
279 struct smbprofile_stats_bytes_async
{
283 struct smbprofile_stats_bytes
*stats
;
286 struct smbprofile_stats_iobytes
{
287 uint64_t count
; /* number of events */
288 uint64_t time
; /* microseconds */
289 uint64_t idle
; /* idle time compared to 'time' microseconds */
290 uint64_t inbytes
; /* bytes read */
291 uint64_t outbytes
; /* bytes written */
294 struct smbprofile_stats_iobytes_async
{
298 struct smbprofile_stats_iobytes
*stats
;
301 struct profile_stats
{
304 #define SMBPROFILE_STATS_START
305 #define SMBPROFILE_STATS_SECTION_START(name, display)
306 #define SMBPROFILE_STATS_COUNT(name) \
307 struct smbprofile_stats_count name##_stats;
308 #define SMBPROFILE_STATS_TIME(name) \
309 struct smbprofile_stats_time name##_stats;
310 #define SMBPROFILE_STATS_BASIC(name) \
311 struct smbprofile_stats_basic name##_stats;
312 #define SMBPROFILE_STATS_BYTES(name) \
313 struct smbprofile_stats_bytes name##_stats;
314 #define SMBPROFILE_STATS_IOBYTES(name) \
315 struct smbprofile_stats_iobytes name##_stats;
316 #define SMBPROFILE_STATS_SECTION_END
317 #define SMBPROFILE_STATS_END
318 SMBPROFILE_STATS_ALL_SECTIONS
319 #undef SMBPROFILE_STATS_START
320 #undef SMBPROFILE_STATS_SECTION_START
321 #undef SMBPROFILE_STATS_COUNT
322 #undef SMBPROFILE_STATS_TIME
323 #undef SMBPROFILE_STATS_BASIC
324 #undef SMBPROFILE_STATS_BYTES
325 #undef SMBPROFILE_STATS_IOBYTES
326 #undef SMBPROFILE_STATS_SECTION_END
327 #undef SMBPROFILE_STATS_END
331 #define _SMBPROFILE_COUNT_INCREMENT(_stats, _area, _v) do { \
332 if (smbprofile_state.config.do_count) { \
333 (_area)->values._stats.count += (_v); \
334 smbprofile_dump_schedule(); \
337 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) \
338 _SMBPROFILE_COUNT_INCREMENT(_name##_stats, _area, _v)
340 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name) \
341 struct smbprofile_stats_time_async _async_name;
342 #define _SMBPROFILE_TIME_ASYNC_START(_stats, _area, _async) do { \
343 (_async) = (struct smbprofile_stats_time_async) {}; \
344 if (smbprofile_state.config.do_times) { \
345 (_async).stats = &((_area)->values._stats), \
346 (_async).start = profile_timestamp(); \
349 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) \
350 _SMBPROFILE_TIME_ASYNC_START(_name##_stats, _area, _async)
351 #define SMBPROFILE_TIME_ASYNC_END(_async) do { \
352 if ((_async).start != 0) { \
353 (_async).stats->time += profile_timestamp() - (_async).start; \
354 (_async) = (struct smbprofile_stats_basic_async) {}; \
355 smbprofile_dump_schedule(); \
359 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) \
360 struct smbprofile_stats_basic_async _async_name;
361 #define _SMBPROFILE_BASIC_ASYNC_START(_stats, _area, _async) do { \
362 (_async) = (struct smbprofile_stats_basic_async) {}; \
363 if (smbprofile_state.config.do_count) { \
364 if (smbprofile_state.config.do_times) { \
365 (_async).start = profile_timestamp(); \
366 (_async).stats = &((_area)->values._stats); \
368 (_area)->values._stats.count += 1; \
369 smbprofile_dump_schedule(); \
372 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) \
373 _SMBPROFILE_BASIC_ASYNC_START(_name##_stats, _area, _async)
374 #define SMBPROFILE_BASIC_ASYNC_END(_async) do { \
375 if ((_async).start != 0) { \
376 (_async).stats->time += profile_timestamp() - (_async).start; \
377 (_async) = (struct smbprofile_stats_basic_async) {}; \
378 smbprofile_dump_schedule(); \
382 #define _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async) do { \
383 (_async).stats = &((_area)->values._stats); \
384 if (smbprofile_state.config.do_times) { \
385 (_async).start = profile_timestamp(); \
388 #define _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) do { \
389 if ((_async).start != 0) { \
390 if ((_async).idle_start == 0) { \
391 (_async).idle_start = profile_timestamp(); \
395 #define _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) do { \
396 if ((_async).idle_start != 0) { \
397 (_async).idle_time += \
398 profile_timestamp() - (_async).idle_start; \
399 (_async).idle_start = 0; \
402 #define _SMBPROFILE_TIMER_ASYNC_END(_async) do { \
403 if ((_async).start != 0) { \
404 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async); \
405 (_async).stats->time += profile_timestamp() - (_async).start; \
406 (_async).stats->idle += (_async).idle_time; \
410 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) \
411 struct smbprofile_stats_bytes_async _async_name;
412 #define _SMBPROFILE_BYTES_ASYNC_START(_stats, _area, _async, _bytes) do { \
413 (_async) = (struct smbprofile_stats_bytes_async) {}; \
414 if (smbprofile_state.config.do_count) { \
415 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
416 (_area)->values._stats.count += 1; \
417 (_area)->values._stats.bytes += (_bytes); \
418 smbprofile_dump_schedule(); \
421 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _bytes) \
422 _SMBPROFILE_BYTES_ASYNC_START(_name##_stats, _area, _async, _bytes)
423 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) \
424 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
425 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) \
426 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
427 #define SMBPROFILE_BYTES_ASYNC_END(_async) do { \
428 if ((_async).stats != NULL) { \
429 _SMBPROFILE_TIMER_ASYNC_END(_async); \
430 (_async) = (struct smbprofile_stats_bytes_async) {}; \
431 smbprofile_dump_schedule(); \
435 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) \
436 struct smbprofile_stats_iobytes_async _async_name;
437 #define _SMBPROFILE_IOBYTES_ASYNC_START(_stats, _area, _async, _inbytes) do { \
438 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
439 if (smbprofile_state.config.do_count) { \
440 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
441 (_area)->values._stats.count += 1; \
442 (_area)->values._stats.inbytes += (_inbytes); \
443 smbprofile_dump_schedule(); \
446 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) \
447 _SMBPROFILE_IOBYTES_ASYNC_START(_name##_stats, _area, _async, _inbytes)
448 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) \
449 _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
450 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) \
451 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
452 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) do { \
453 if ((_async).stats != NULL) { \
454 (_async).stats->outbytes += (_outbytes); \
455 _SMBPROFILE_TIMER_ASYNC_END(_async); \
456 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
457 smbprofile_dump_schedule(); \
461 extern struct profile_stats
*profile_p
;
463 struct smbprofile_global_state
{
466 struct tevent_context
*ev
;
467 struct tevent_timer
*te
;
476 struct profile_stats global
;
480 extern struct smbprofile_global_state smbprofile_state
;
482 void smbprofile_dump_schedule_timer(void);
483 void smbprofile_dump_setup(struct tevent_context
*ev
);
485 static inline void smbprofile_dump_schedule(void)
487 if (likely(smbprofile_state
.internal
.te
!= NULL
)) {
491 if (unlikely(smbprofile_state
.internal
.ev
== NULL
)) {
495 smbprofile_dump_schedule_timer();
498 static inline bool smbprofile_dump_pending(void)
500 if (smbprofile_state
.internal
.te
== NULL
) {
507 void smbprofile_dump(void);
509 void smbprofile_cleanup(pid_t pid
, pid_t dst
);
510 void smbprofile_stats_accumulate(struct profile_stats
*acc
,
511 const struct profile_stats
*add
);
512 void smbprofile_collect(struct profile_stats
*stats
);
514 static inline uint64_t profile_timestamp(void)
518 /* we might prefer to use the _COARSE clock variant of CLOCK_MONOTONIC
519 that one is faster but cached and "just" tick-wise precise */
520 clock_gettime_mono(&ts
);
521 return (ts
.tv_sec
* 1000000) + (ts
.tv_nsec
/ 1000); /* usec */
524 #define DO_PROFILE_INC(x) \
525 _SMBPROFILE_COUNT_INCREMENT(x##_stats, profile_p, 1); \
527 #define START_PROFILE(x) \
528 struct smbprofile_stats_basic_async __profasync_##x = {}; \
529 _SMBPROFILE_BASIC_ASYNC_START(x##_stats, profile_p, __profasync_##x);
531 #define START_PROFILE_BYTES(x,n) \
532 struct smbprofile_stats_bytes_async __profasync_##x = {}; \
533 _SMBPROFILE_BYTES_ASYNC_START(x##_stats, profile_p, __profasync_##x, n);
535 #define END_PROFILE(x) \
536 SMBPROFILE_BASIC_ASYNC_END(__profasync_##x)
538 #define END_PROFILE_BYTES(x) \
539 SMBPROFILE_BYTES_ASYNC_END(__profasync_##x)
541 #define PROFILE_TIMESTAMP(x) clock_gettime_mono(x)
543 #else /* WITH_PROFILE */
545 #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v)
547 #define SMBPROFILE_TIME_ASYNC_STATE(_async_name)
548 #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async)
549 #define SMBPROFILE_TIME_ASYNC_END(_async)
551 #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name)
552 #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async)
553 #define SMBPROFILE_BASIC_ASYNC_END(_async)
555 #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name)
556 #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _inbytes)
557 #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async)
558 #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async)
559 #define SMBPROFILE_BYTES_ASYNC_END(_async)
561 #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name)
562 #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes)
563 #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async)
564 #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async)
565 #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes)
567 #define DO_PROFILE_INC(x)
568 #define START_PROFILE(x)
569 #define START_PROFILE_BYTES(x,n)
570 #define END_PROFILE(x)
571 #define END_PROFILE_BYTES(x)
573 #define PROFILE_TIMESTAMP(x) (*(x)=(struct timespec){0})
575 static inline bool smbprofile_dump_pending(void)
580 static inline void smbprofile_dump_setup(struct tevent_context
*ev
)
585 static inline void smbprofile_dump(void)
590 static inline void smbprofile_cleanup(pid_t pid
, pid_t dst
)
595 #endif /* WITH_PROFILE */
597 /* The following definitions come from profile/profile.c */
600 void set_profile_level(int level
, const struct server_id
*src
);
602 struct messaging_context
;
603 bool profile_setup(struct messaging_context
*msg_ctx
, bool rdonly
);