4 Unix SMB/Netbios implementation.
6 store smbd profiling information in shared memory
7 Copyright (C) Andrew Tridgell 1999
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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Reasons for cache flush.
29 #define NUM_FLUSH_REASONS 8 /* Keep this in sync with the enum below. */
30 enum flush_reason_enum
{ SEEK_FLUSH
, READ_FLUSH
, WRITE_FLUSH
, READRAW_FLUSH
,
31 OPLOCK_RELEASE_FLUSH
, CLOSE_FLUSH
, SYNC_FLUSH
, SIZECHANGE_FLUSH
};
33 /* this file defines the profile structure in the profile shared
36 #define PROF_SHMEM_KEY ((key_t)0x07021999)
37 #define PROF_SHM_MAGIC 0x6349985
38 #define PROF_SHM_VERSION 7
40 /* time values in the following structure are in microseconds */
42 struct profile_stats
{
43 /* general counters */
44 unsigned smb_count
; /* how many SMB packets we have processed */
45 unsigned uid_changes
; /* how many times we change our effective uid */
46 /* system call counters */
47 unsigned syscall_opendir_count
;
48 unsigned syscall_opendir_time
;
49 unsigned syscall_readdir_count
;
50 unsigned syscall_readdir_time
;
51 unsigned syscall_mkdir_count
;
52 unsigned syscall_mkdir_time
;
53 unsigned syscall_rmdir_count
;
54 unsigned syscall_rmdir_time
;
55 unsigned syscall_closedir_count
;
56 unsigned syscall_closedir_time
;
57 unsigned syscall_open_count
;
58 unsigned syscall_open_time
;
59 unsigned syscall_close_count
;
60 unsigned syscall_close_time
;
61 unsigned syscall_read_count
;
62 unsigned syscall_read_time
;
63 unsigned syscall_read_bytes
; /* bytes read with read syscall */
64 unsigned syscall_write_count
;
65 unsigned syscall_write_time
;
66 unsigned syscall_write_bytes
; /* bytes written with write syscall */
67 unsigned syscall_lseek_count
;
68 unsigned syscall_lseek_time
;
69 unsigned syscall_sendfile_count
;
70 unsigned syscall_sendfile_time
;
71 unsigned syscall_sendfile_bytes
; /* bytes read with sendfile syscall */
72 unsigned syscall_rename_count
;
73 unsigned syscall_rename_time
;
74 unsigned syscall_fsync_count
;
75 unsigned syscall_fsync_time
;
76 unsigned syscall_stat_count
;
77 unsigned syscall_stat_time
;
78 unsigned syscall_fstat_count
;
79 unsigned syscall_fstat_time
;
80 unsigned syscall_lstat_count
;
81 unsigned syscall_lstat_time
;
82 unsigned syscall_unlink_count
;
83 unsigned syscall_unlink_time
;
84 unsigned syscall_chmod_count
;
85 unsigned syscall_chmod_time
;
86 unsigned syscall_fchmod_count
;
87 unsigned syscall_fchmod_time
;
88 unsigned syscall_chown_count
;
89 unsigned syscall_chown_time
;
90 unsigned syscall_fchown_count
;
91 unsigned syscall_fchown_time
;
92 unsigned syscall_chdir_count
;
93 unsigned syscall_chdir_time
;
94 unsigned syscall_getwd_count
;
95 unsigned syscall_getwd_time
;
96 unsigned syscall_utime_count
;
97 unsigned syscall_utime_time
;
98 unsigned syscall_ftruncate_count
;
99 unsigned syscall_ftruncate_time
;
100 unsigned syscall_fcntl_lock_count
;
101 unsigned syscall_fcntl_lock_time
;
102 unsigned syscall_readlink_count
;
103 unsigned syscall_readlink_time
;
104 unsigned syscall_symlink_count
;
105 unsigned syscall_symlink_time
;
106 unsigned syscall_link_count
;
107 unsigned syscall_link_time
;
108 unsigned syscall_mknod_count
;
109 unsigned syscall_mknod_time
;
110 unsigned syscall_realpath_count
;
111 unsigned syscall_realpath_time
;
112 /* stat cache counters */
113 unsigned statcache_lookups
;
114 unsigned statcache_misses
;
115 unsigned statcache_hits
;
116 /* write cache counters */
117 unsigned writecache_read_hits
;
118 unsigned writecache_abutted_writes
;
119 unsigned writecache_total_writes
;
120 unsigned writecache_non_oplock_writes
;
121 unsigned writecache_direct_writes
;
122 unsigned writecache_init_writes
;
123 unsigned writecache_flushed_writes
[NUM_FLUSH_REASONS
];
124 unsigned writecache_num_perfect_writes
;
125 unsigned writecache_num_write_caches
;
126 unsigned writecache_allocated_write_caches
;
127 /* counters for individual SMB types */
128 unsigned SMBmkdir_count
; /* create directory */
129 unsigned SMBmkdir_time
;
130 unsigned SMBrmdir_count
; /* delete directory */
131 unsigned SMBrmdir_time
;
132 unsigned SMBopen_count
; /* open file */
133 unsigned SMBopen_time
;
134 unsigned SMBcreate_count
; /* create file */
135 unsigned SMBcreate_time
;
136 unsigned SMBclose_count
; /* close file */
137 unsigned SMBclose_time
;
138 unsigned SMBflush_count
; /* flush file */
139 unsigned SMBflush_time
;
140 unsigned SMBunlink_count
; /* delete file */
141 unsigned SMBunlink_time
;
142 unsigned SMBmv_count
; /* rename file */
144 unsigned SMBgetatr_count
; /* get file attributes */
145 unsigned SMBgetatr_time
;
146 unsigned SMBsetatr_count
; /* set file attributes */
147 unsigned SMBsetatr_time
;
148 unsigned SMBread_count
; /* read from file */
149 unsigned SMBread_time
;
150 unsigned SMBwrite_count
; /* write to file */
151 unsigned SMBwrite_time
;
152 unsigned SMBlock_count
; /* lock byte range */
153 unsigned SMBlock_time
;
154 unsigned SMBunlock_count
; /* unlock byte range */
155 unsigned SMBunlock_time
;
156 unsigned SMBctemp_count
; /* create temporary file */
157 unsigned SMBctemp_time
;
158 /* SMBmknew stats are currently combined with SMBcreate */
159 unsigned SMBmknew_count
; /* make new file */
160 unsigned SMBmknew_time
;
161 unsigned SMBchkpth_count
; /* check directory path */
162 unsigned SMBchkpth_time
;
163 unsigned SMBexit_count
; /* process exit */
164 unsigned SMBexit_time
;
165 unsigned SMBlseek_count
; /* seek */
166 unsigned SMBlseek_time
;
167 unsigned SMBlockread_count
; /* Lock a range and read */
168 unsigned SMBlockread_time
;
169 unsigned SMBwriteunlock_count
; /* Unlock a range then write */
170 unsigned SMBwriteunlock_time
;
171 unsigned SMBreadbraw_count
; /* read a block of data with no smb header */
172 unsigned SMBreadbraw_time
;
173 unsigned SMBreadBmpx_count
; /* read block multiplexed */
174 unsigned SMBreadBmpx_time
;
175 unsigned SMBreadBs_count
; /* read block (secondary response) */
176 unsigned SMBreadBs_time
;
177 unsigned SMBwritebraw_count
; /* write a block of data with no smb header */
178 unsigned SMBwritebraw_time
;
179 unsigned SMBwriteBmpx_count
; /* write block multiplexed */
180 unsigned SMBwriteBmpx_time
;
181 unsigned SMBwriteBs_count
; /* write block (secondary request) */
182 unsigned SMBwriteBs_time
;
183 unsigned SMBwritec_count
; /* secondary write request */
184 unsigned SMBwritec_time
;
185 unsigned SMBsetattrE_count
; /* set file attributes expanded */
186 unsigned SMBsetattrE_time
;
187 unsigned SMBgetattrE_count
; /* get file attributes expanded */
188 unsigned SMBgetattrE_time
;
189 unsigned SMBlockingX_count
; /* lock/unlock byte ranges and X */
190 unsigned SMBlockingX_time
;
191 unsigned SMBtrans_count
; /* transaction - name, bytes in/out */
192 unsigned SMBtrans_time
;
193 unsigned SMBtranss_count
; /* transaction (secondary request/response) */
194 unsigned SMBtranss_time
;
195 unsigned SMBioctl_count
; /* IOCTL */
196 unsigned SMBioctl_time
;
197 unsigned SMBioctls_count
; /* IOCTL (secondary request/response) */
198 unsigned SMBioctls_time
;
199 unsigned SMBcopy_count
; /* copy */
200 unsigned SMBcopy_time
;
201 unsigned SMBmove_count
; /* move */
202 unsigned SMBmove_time
;
203 unsigned SMBecho_count
; /* echo */
204 unsigned SMBecho_time
;
205 unsigned SMBwriteclose_count
; /* write a file then close it */
206 unsigned SMBwriteclose_time
;
207 unsigned SMBopenX_count
; /* open and X */
208 unsigned SMBopenX_time
;
209 unsigned SMBreadX_count
; /* read and X */
210 unsigned SMBreadX_time
;
211 unsigned SMBwriteX_count
; /* write and X */
212 unsigned SMBwriteX_time
;
213 unsigned SMBtrans2_count
; /* TRANS2 protocol set */
214 unsigned SMBtrans2_time
;
215 unsigned SMBtranss2_count
; /* TRANS2 protocol set, secondary command */
216 unsigned SMBtranss2_time
;
217 unsigned SMBfindclose_count
; /* Terminate a TRANSACT2_FINDFIRST */
218 unsigned SMBfindclose_time
;
219 unsigned SMBfindnclose_count
; /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
220 unsigned SMBfindnclose_time
;
221 unsigned SMBtcon_count
; /* tree connect */
222 unsigned SMBtcon_time
;
223 unsigned SMBtdis_count
; /* tree disconnect */
224 unsigned SMBtdis_time
;
225 unsigned SMBnegprot_count
; /* negotiate protocol */
226 unsigned SMBnegprot_time
;
227 unsigned SMBsesssetupX_count
; /* Session Set Up & X (including User Logon) */
228 unsigned SMBsesssetupX_time
;
229 unsigned SMBulogoffX_count
; /* user logoff */
230 unsigned SMBulogoffX_time
;
231 unsigned SMBtconX_count
; /* tree connect and X*/
232 unsigned SMBtconX_time
;
233 unsigned SMBdskattr_count
; /* get disk attributes */
234 unsigned SMBdskattr_time
;
235 unsigned SMBsearch_count
; /* search directory */
236 unsigned SMBsearch_time
;
237 /* SBMffirst stats combined with SMBsearch */
238 unsigned SMBffirst_count
; /* find first */
239 unsigned SMBffirst_time
;
240 /* SBMfunique stats combined with SMBsearch */
241 unsigned SMBfunique_count
; /* find unique */
242 unsigned SMBfunique_time
;
243 unsigned SMBfclose_count
; /* find close */
244 unsigned SMBfclose_time
;
245 unsigned SMBnttrans_count
; /* NT transact */
246 unsigned SMBnttrans_time
;
247 unsigned SMBnttranss_count
; /* NT transact secondary */
248 unsigned SMBnttranss_time
;
249 unsigned SMBntcreateX_count
; /* NT create and X */
250 unsigned SMBntcreateX_time
;
251 unsigned SMBntcancel_count
; /* NT cancel */
252 unsigned SMBntcancel_time
;
253 unsigned SMBsplopen_count
; /* open print spool file */
254 unsigned SMBsplopen_time
;
255 unsigned SMBsplwr_count
; /* write to print spool file */
256 unsigned SMBsplwr_time
;
257 unsigned SMBsplclose_count
; /* close print spool file */
258 unsigned SMBsplclose_time
;
259 unsigned SMBsplretq_count
; /* return print queue */
260 unsigned SMBsplretq_time
;
261 unsigned SMBsends_count
; /* send single block message */
262 unsigned SMBsends_time
;
263 unsigned SMBsendb_count
; /* send broadcast message */
264 unsigned SMBsendb_time
;
265 unsigned SMBfwdname_count
; /* forward user name */
266 unsigned SMBfwdname_time
;
267 unsigned SMBcancelf_count
; /* cancel forward */
268 unsigned SMBcancelf_time
;
269 unsigned SMBgetmac_count
; /* get machine name */
270 unsigned SMBgetmac_time
;
271 unsigned SMBsendstrt_count
; /* send start of multi-block message */
272 unsigned SMBsendstrt_time
;
273 unsigned SMBsendend_count
; /* send end of multi-block message */
274 unsigned SMBsendend_time
;
275 unsigned SMBsendtxt_count
; /* send text of multi-block message */
276 unsigned SMBsendtxt_time
;
277 unsigned SMBinvalid_count
; /* invalid command */
278 unsigned SMBinvalid_time
;
279 /* Pathworks setdir command */
280 unsigned pathworks_setdir_count
;
281 unsigned pathworks_setdir_time
;
282 /* These are the TRANS2 sub commands */
283 unsigned Trans2_open_count
;
284 unsigned Trans2_open_time
;
285 unsigned Trans2_findfirst_count
;
286 unsigned Trans2_findfirst_time
;
287 unsigned Trans2_findnext_count
;
288 unsigned Trans2_findnext_time
;
289 unsigned Trans2_qfsinfo_count
;
290 unsigned Trans2_qfsinfo_time
;
291 unsigned Trans2_setfsinfo_count
;
292 unsigned Trans2_setfsinfo_time
;
293 unsigned Trans2_qpathinfo_count
;
294 unsigned Trans2_qpathinfo_time
;
295 unsigned Trans2_setpathinfo_count
;
296 unsigned Trans2_setpathinfo_time
;
297 unsigned Trans2_qfileinfo_count
;
298 unsigned Trans2_qfileinfo_time
;
299 unsigned Trans2_setfileinfo_count
;
300 unsigned Trans2_setfileinfo_time
;
301 unsigned Trans2_fsctl_count
;
302 unsigned Trans2_fsctl_time
;
303 unsigned Trans2_ioctl_count
;
304 unsigned Trans2_ioctl_time
;
305 unsigned Trans2_findnotifyfirst_count
;
306 unsigned Trans2_findnotifyfirst_time
;
307 unsigned Trans2_findnotifynext_count
;
308 unsigned Trans2_findnotifynext_time
;
309 unsigned Trans2_mkdir_count
;
310 unsigned Trans2_mkdir_time
;
311 unsigned Trans2_session_setup_count
;
312 unsigned Trans2_session_setup_time
;
313 unsigned Trans2_get_dfs_referral_count
;
314 unsigned Trans2_get_dfs_referral_time
;
315 unsigned Trans2_report_dfs_inconsistancy_count
;
316 unsigned Trans2_report_dfs_inconsistancy_time
;
317 /* These are the NT transact sub commands. */
318 unsigned NT_transact_create_count
;
319 unsigned NT_transact_create_time
;
320 unsigned NT_transact_ioctl_count
;
321 unsigned NT_transact_ioctl_time
;
322 unsigned NT_transact_set_security_desc_count
;
323 unsigned NT_transact_set_security_desc_time
;
324 unsigned NT_transact_notify_change_count
;
325 unsigned NT_transact_notify_change_time
;
326 unsigned NT_transact_rename_count
;
327 unsigned NT_transact_rename_time
;
328 unsigned NT_transact_query_security_desc_count
;
329 unsigned NT_transact_query_security_desc_time
;
330 /* These are ACL manipulation calls */
331 unsigned get_nt_acl_count
;
332 unsigned get_nt_acl_time
;
333 unsigned fget_nt_acl_count
;
334 unsigned fget_nt_acl_time
;
335 unsigned set_nt_acl_count
;
336 unsigned set_nt_acl_time
;
337 unsigned fset_nt_acl_count
;
338 unsigned fset_nt_acl_time
;
339 unsigned chmod_acl_count
;
340 unsigned chmod_acl_time
;
341 unsigned fchmod_acl_count
;
342 unsigned fchmod_acl_time
;
343 /* These are nmbd stats */
344 unsigned name_release_count
;
345 unsigned name_release_time
;
346 unsigned name_refresh_count
;
347 unsigned name_refresh_time
;
348 unsigned name_registration_count
;
349 unsigned name_registration_time
;
350 unsigned node_status_count
;
351 unsigned node_status_time
;
352 unsigned name_query_count
;
353 unsigned name_query_time
;
354 unsigned host_announce_count
;
355 unsigned host_announce_time
;
356 unsigned workgroup_announce_count
;
357 unsigned workgroup_announce_time
;
358 unsigned local_master_announce_count
;
359 unsigned local_master_announce_time
;
360 unsigned master_browser_announce_count
;
361 unsigned master_browser_announce_time
;
362 unsigned lm_host_announce_count
;
363 unsigned lm_host_announce_time
;
364 unsigned get_backup_list_count
;
365 unsigned get_backup_list_time
;
366 unsigned reset_browser_count
;
367 unsigned reset_browser_time
;
368 unsigned announce_request_count
;
369 unsigned announce_request_time
;
370 unsigned lm_announce_request_count
;
371 unsigned lm_announce_request_time
;
372 unsigned domain_logon_count
;
373 unsigned domain_logon_time
;
374 unsigned sync_browse_lists_count
;
375 unsigned sync_browse_lists_time
;
376 unsigned run_elections_count
;
377 unsigned run_elections_time
;
378 unsigned election_count
;
379 unsigned election_time
;
382 struct profile_header
{
384 int prof_shm_version
;
385 struct profile_stats stats
;
388 extern struct profile_header
*profile_h
;
389 extern struct profile_stats
*profile_p
;
390 extern struct timeval profile_starttime
;
391 extern struct timeval profile_endtime
;
392 extern struct timeval profile_starttime_nested
;
393 extern struct timeval profile_endtime_nested
;
394 extern BOOL do_profile_flag
;
395 extern BOOL do_profile_times
;
397 /* these are helper macros - do not call them directly in the code
398 * use the DO_PROFILE_* START_PROFILE and END_PROFILE ones
399 * below which test for the profile flage first
401 #define INC_PROFILE_COUNT(x) profile_p->x++
402 #define DEC_PROFILE_COUNT(x) profile_p->x--
403 #define ADD_PROFILE_COUNT(x,y) profile_p->x += (y)
404 #define PROFILE_TIME \
405 ((profile_endtime.tv_sec - profile_starttime.tv_sec) *1000000 + \
406 ((int)profile_endtime.tv_usec - (int)profile_starttime.tv_usec))
407 #define PROFILE_TIME_NESTED \
408 ((profile_endtime_nested.tv_sec - profile_starttime_nested.tv_sec) *1000000 + \
409 ((int)profile_endtime_nested.tv_usec - (int)profile_starttime_nested.tv_usec))
412 #define DO_PROFILE_INC(x) \
413 if (do_profile_flag) { \
414 INC_PROFILE_COUNT(x); \
416 #define DO_PROFILE_DEC(x) \
417 if (do_profile_flag) { \
418 DEC_PROFILE_COUNT(x); \
420 #define DO_PROFILE_DEC_INC(x,y) \
421 if (do_profile_flag) { \
422 DEC_PROFILE_COUNT(x); \
423 INC_PROFILE_COUNT(y); \
425 #define DO_PROFILE_ADD(x,n) \
426 if (do_profile_flag) { \
427 ADD_PROFILE_COUNT(x,n); \
429 #define START_PROFILE(x) \
430 if (do_profile_flag) { \
431 if (do_profile_times) \
432 GetTimeOfDay(&profile_starttime); \
433 INC_PROFILE_COUNT(x##_count); \
435 #define START_PROFILE_NESTED(x) \
436 if (do_profile_flag) { \
437 if (do_profile_times) \
438 GetTimeOfDay(&profile_starttime_nested); \
439 INC_PROFILE_COUNT(x##_count); \
441 #define START_PROFILE_BYTES(x,n) \
442 if (do_profile_flag) { \
443 if (do_profile_times) \
444 GetTimeOfDay(&profile_starttime); \
445 INC_PROFILE_COUNT(x##_count); \
446 ADD_PROFILE_COUNT(x##_bytes,n); \
448 #define END_PROFILE(x) \
449 if (do_profile_times) { \
450 GetTimeOfDay(&profile_endtime); \
451 ADD_PROFILE_COUNT(x##_time,PROFILE_TIME); \
453 #define END_PROFILE_NESTED(x) \
454 if (do_profile_times) { \
455 GetTimeOfDay(&profile_endtime_nested); \
456 ADD_PROFILE_COUNT(x##_time,PROFILE_TIME_NESTED); \
459 #define DO_PROFILE_INC(x)
460 #define DO_PROFILE_DEC(x)
461 #define DO_PROFILE_DEC_INC(x,y)
462 #define DO_PROFILE_ADD(x,n)
463 #define START_PROFILE(x)
464 #define START_PROFILE_NESTED(x)
465 #define START_PROFILE_BYTES(x,n)
466 #define END_PROFILE(x)
467 #define END_PROFILE_NESTED(x)