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