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