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