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