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