Restructuring of vfs layer to include a "this" pointer - can be an fsp or
[kamenim/samba-autobuild/.git] / source3 / include / profile.h
1 #ifndef _PROFILE_H_
2 #define _PROFILE_H_
3 /* 
4    Unix SMB/Netbios implementation.
5    Version 1.9.
6    store smbd profiling information in shared memory
7    Copyright (C) Andrew Tridgell 1999
8    
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.
13    
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.
18    
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.
22
23 */
24
25 /* this file defines the profile structure in the profile shared
26    memory area */
27
28 #define PROF_SHMEM_KEY ((key_t)0x07021999)
29 #define PROF_SHM_MAGIC 0x6349985
30 #define PROF_SHM_VERSION 2
31
32 /* time values in the following structure are in milliseconds */
33
34 struct profile_struct {
35         int prof_shm_magic;
36         int prof_shm_version;
37 /* general counters */
38         unsigned smb_count; /* how many SMB packets we have processed */
39         unsigned uid_changes; /* how many times we change our effective uid */
40 /* system call counters */
41         unsigned syscall_opendir_count;
42         unsigned syscall_opendir_time;
43         unsigned syscall_readdir_count;
44         unsigned syscall_readdir_time;
45         unsigned syscall_mkdir_count;
46         unsigned syscall_mkdir_time;
47         unsigned syscall_rmdir_count;
48         unsigned syscall_rmdir_time;
49         unsigned syscall_closedir_count;
50         unsigned syscall_closedir_time;
51         unsigned syscall_open_count;
52         unsigned syscall_open_time;
53         unsigned syscall_close_count;
54         unsigned syscall_close_time;
55         unsigned syscall_read_count;
56         unsigned syscall_read_time;
57         unsigned syscall_read_bytes;    /* bytes read with read syscall */
58         unsigned syscall_write_count;
59         unsigned syscall_write_time;
60         unsigned syscall_write_bytes;   /* bytes written with write syscall */
61         unsigned syscall_lseek_count;
62         unsigned syscall_lseek_time;
63         unsigned syscall_rename_count;
64         unsigned syscall_rename_time;
65         unsigned syscall_fsync_count;
66         unsigned syscall_fsync_time;
67         unsigned syscall_stat_count;
68         unsigned syscall_stat_time;
69         unsigned syscall_fstat_count;
70         unsigned syscall_fstat_time;
71         unsigned syscall_lstat_count;
72         unsigned syscall_lstat_time;
73         unsigned syscall_unlink_count;
74         unsigned syscall_unlink_time;
75         unsigned syscall_chmod_count;
76         unsigned syscall_chmod_time;
77         unsigned syscall_chown_count;
78         unsigned syscall_chown_time;
79         unsigned syscall_chdir_count;
80         unsigned syscall_chdir_time;
81         unsigned syscall_getwd_count;
82         unsigned syscall_getwd_time;
83         unsigned syscall_utime_count;
84         unsigned syscall_utime_time;
85         unsigned syscall_ftruncate_count;
86         unsigned syscall_ftruncate_time;
87         unsigned syscall_fcntl_lock_count;
88         unsigned syscall_fcntl_lock_time;
89 /* stat cache counters */
90         unsigned statcache_lookups;
91         unsigned statcache_misses;
92         unsigned statcache_hits;
93 /* write cache counters */
94         unsigned writecache_read_hits;
95         unsigned writecache_abutted_writes;
96         unsigned writecache_total_writes;
97         unsigned writecache_non_oplock_writes;
98         unsigned writecache_direct_writes;
99         unsigned writecache_init_writes;
100         unsigned writecache_flushed_writes[NUM_FLUSH_REASONS];
101         unsigned writecache_num_perfect_writes;
102         unsigned writecache_num_write_caches;
103         unsigned writecache_allocated_write_caches;
104 /* counters for individual SMB types */
105         unsigned SMBmkdir_count;        /* create directory */
106         unsigned SMBmkdir_time;
107         unsigned SMBrmdir_count;        /* delete directory */
108         unsigned SMBrmdir_time;
109         unsigned SMBopen_count;         /* open file */
110         unsigned SMBopen_time;
111         unsigned SMBcreate_count;       /* create file */
112         unsigned SMBcreate_time;
113         unsigned SMBclose_count;        /* close file */
114         unsigned SMBclose_time;
115         unsigned SMBflush_count;        /* flush file */
116         unsigned SMBflush_time;
117         unsigned SMBunlink_count;       /* delete file */
118         unsigned SMBunlink_time;
119         unsigned SMBmv_count;           /* rename file */
120         unsigned SMBmv_time;
121         unsigned SMBgetatr_count;       /* get file attributes */
122         unsigned SMBgetatr_time;
123         unsigned SMBsetatr_count;       /* set file attributes */
124         unsigned SMBsetatr_time;
125         unsigned SMBread_count;         /* read from file */
126         unsigned SMBread_time;
127         unsigned SMBwrite_count;        /* write to file */
128         unsigned SMBwrite_time;
129         unsigned SMBlock_count;         /* lock byte range */
130         unsigned SMBlock_time;
131         unsigned SMBunlock_count;       /* unlock byte range */
132         unsigned SMBunlock_time;
133         unsigned SMBctemp_count;        /* create temporary file */
134         unsigned SMBctemp_time;
135         /* SMBmknew stats are currently combined with SMBcreate */
136         unsigned SMBmknew_count;        /* make new file */
137         unsigned SMBmknew_time;
138         unsigned SMBchkpth_count;       /* check directory path */
139         unsigned SMBchkpth_time;
140         unsigned SMBexit_count;         /* process exit */
141         unsigned SMBexit_time;
142         unsigned SMBlseek_count;        /* seek */
143         unsigned SMBlseek_time;
144         unsigned SMBlockread_count;     /* Lock a range and read */
145         unsigned SMBlockread_time;
146         unsigned SMBwriteunlock_count;  /* Unlock a range then write */
147         unsigned SMBwriteunlock_time;
148         unsigned SMBreadbraw_count;     /* read a block of data with no smb header */
149         unsigned SMBreadbraw_time;
150         unsigned SMBreadBmpx_count;     /* read block multiplexed */
151         unsigned SMBreadBmpx_time;
152         unsigned SMBreadBs_count;       /* read block (secondary response) */
153         unsigned SMBreadBs_time;
154         unsigned SMBwritebraw_count;    /* write a block of data with no smb header */
155         unsigned SMBwritebraw_time;
156         unsigned SMBwriteBmpx_count;    /* write block multiplexed */
157         unsigned SMBwriteBmpx_time;
158         unsigned SMBwriteBs_count;      /* write block (secondary request) */
159         unsigned SMBwriteBs_time;
160         unsigned SMBwritec_count;       /* secondary write request */
161         unsigned SMBwritec_time;
162         unsigned SMBsetattrE_count;     /* set file attributes expanded */
163         unsigned SMBsetattrE_time;
164         unsigned SMBgetattrE_count;     /* get file attributes expanded */
165         unsigned SMBgetattrE_time;
166         unsigned SMBlockingX_count;     /* lock/unlock byte ranges and X */
167         unsigned SMBlockingX_time;
168         unsigned SMBtrans_count;        /* transaction - name, bytes in/out */
169         unsigned SMBtrans_time;
170         unsigned SMBtranss_count;       /* transaction (secondary request/response) */
171         unsigned SMBtranss_time;
172         unsigned SMBioctl_count;        /* IOCTL */
173         unsigned SMBioctl_time;
174         unsigned SMBioctls_count;       /* IOCTL  (secondary request/response) */
175         unsigned SMBioctls_time;
176         unsigned SMBcopy_count;         /* copy */
177         unsigned SMBcopy_time;
178         unsigned SMBmove_count;         /* move */
179         unsigned SMBmove_time;
180         unsigned SMBecho_count;         /* echo */
181         unsigned SMBecho_time;
182         unsigned SMBwriteclose_count;   /* write a file then close it */
183         unsigned SMBwriteclose_time;
184         unsigned SMBopenX_count;        /* open and X */
185         unsigned SMBopenX_time;
186         unsigned SMBreadX_count;        /* read and X */
187         unsigned SMBreadX_time;
188         unsigned SMBwriteX_count;       /* write and X */
189         unsigned SMBwriteX_time;
190         unsigned SMBtrans2_count;       /* TRANS2 protocol set */
191         unsigned SMBtrans2_time;
192         unsigned SMBtranss2_count;      /* TRANS2 protocol set, secondary command */
193         unsigned SMBtranss2_time;
194         unsigned SMBfindclose_count;    /* Terminate a TRANSACT2_FINDFIRST */
195         unsigned SMBfindclose_time;
196         unsigned SMBfindnclose_count;   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
197         unsigned SMBfindnclose_time;
198         unsigned SMBtcon_count;         /* tree connect */
199         unsigned SMBtcon_time;
200         unsigned SMBtdis_count;         /* tree disconnect */
201         unsigned SMBtdis_time;
202         unsigned SMBnegprot_count;      /* negotiate protocol */
203         unsigned SMBnegprot_time;
204         unsigned SMBsesssetupX_count;   /* Session Set Up & X (including User Logon) */
205         unsigned SMBsesssetupX_time;
206         unsigned SMBulogoffX_count;     /* user logoff */
207         unsigned SMBulogoffX_time;
208         unsigned SMBtconX_count;        /* tree connect and X*/
209         unsigned SMBtconX_time;
210         unsigned SMBdskattr_count;      /* get disk attributes */
211         unsigned SMBdskattr_time;
212         unsigned SMBsearch_count;       /* search directory */
213         unsigned SMBsearch_time;
214         /* SBMffirst stats combined with SMBsearch */
215         unsigned SMBffirst_count;       /* find first */
216         unsigned SMBffirst_time;
217         /* SBMfunique stats combined with SMBsearch */
218         unsigned SMBfunique_count;      /* find unique */
219         unsigned SMBfunique_time;
220         unsigned SMBfclose_count;       /* find close */
221         unsigned SMBfclose_time;
222         unsigned SMBnttrans_count;      /* NT transact */
223         unsigned SMBnttrans_time;
224         unsigned SMBnttranss_count;     /* NT transact secondary */
225         unsigned SMBnttranss_time;
226         unsigned SMBntcreateX_count;    /* NT create and X */
227         unsigned SMBntcreateX_time;
228         unsigned SMBntcancel_count;     /* NT cancel */
229         unsigned SMBntcancel_time;
230         unsigned SMBsplopen_count;      /* open print spool file */
231         unsigned SMBsplopen_time;
232         unsigned SMBsplwr_count;        /* write to print spool file */
233         unsigned SMBsplwr_time;
234         unsigned SMBsplclose_count;     /* close print spool file */
235         unsigned SMBsplclose_time;
236         unsigned SMBsplretq_count;      /* return print queue */
237         unsigned SMBsplretq_time;
238         unsigned SMBsends_count;        /* send single block message */
239         unsigned SMBsends_time;
240         unsigned SMBsendb_count;        /* send broadcast message */
241         unsigned SMBsendb_time;
242         unsigned SMBfwdname_count;      /* forward user name */
243         unsigned SMBfwdname_time;
244         unsigned SMBcancelf_count;      /* cancel forward */
245         unsigned SMBcancelf_time;
246         unsigned SMBgetmac_count;       /* get machine name */
247         unsigned SMBgetmac_time;
248         unsigned SMBsendstrt_count;     /* send start of multi-block message */
249         unsigned SMBsendstrt_time;
250         unsigned SMBsendend_count;      /* send end of multi-block message */
251         unsigned SMBsendend_time;
252         unsigned SMBsendtxt_count;      /* send text of multi-block message */
253         unsigned SMBsendtxt_time;
254         unsigned SMBinvalid_count;      /* invalid command */
255         unsigned SMBinvalid_time;
256 /* Pathworks setdir command */
257         unsigned pathworks_setdir_count;
258         unsigned pathworks_setdir_time;
259 /* These are the TRANS2 sub commands */
260         unsigned Trans2_open_count;
261         unsigned Trans2_open_time;
262         unsigned Trans2_findfirst_count;
263         unsigned Trans2_findfirst_time;
264         unsigned Trans2_findnext_count;
265         unsigned Trans2_findnext_time;
266         unsigned Trans2_qfsinfo_count;
267         unsigned Trans2_qfsinfo_time;
268         unsigned Trans2_setfsinfo_count;
269         unsigned Trans2_setfsinfo_time;
270         unsigned Trans2_qpathinfo_count;
271         unsigned Trans2_qpathinfo_time;
272         unsigned Trans2_setpathinfo_count;
273         unsigned Trans2_setpathinfo_time;
274         unsigned Trans2_qfileinfo_count;
275         unsigned Trans2_qfileinfo_time;
276         unsigned Trans2_setfileinfo_count;
277         unsigned Trans2_setfileinfo_time;
278         unsigned Trans2_fsctl_count;
279         unsigned Trans2_fsctl_time;
280         unsigned Trans2_ioctl_count;
281         unsigned Trans2_ioctl_time;
282         unsigned Trans2_findnotifyfirst_count;
283         unsigned Trans2_findnotifyfirst_time;
284         unsigned Trans2_findnotifynext_count;
285         unsigned Trans2_findnotifynext_time;
286         unsigned Trans2_mkdir_count;
287         unsigned Trans2_mkdir_time;
288         unsigned Trans2_session_setup_count;
289         unsigned Trans2_session_setup_time;
290         unsigned Trans2_get_dfs_referral_count;
291         unsigned Trans2_get_dfs_referral_time;
292         unsigned Trans2_report_dfs_inconsistancy_count;
293         unsigned Trans2_report_dfs_inconsistancy_time;
294 /* These are the NT transact sub commands. */
295         unsigned NT_transact_create_count;
296         unsigned NT_transact_create_time;
297         unsigned NT_transact_ioctl_count;
298         unsigned NT_transact_ioctl_time;
299         unsigned NT_transact_set_security_desc_count;
300         unsigned NT_transact_set_security_desc_time;
301         unsigned NT_transact_notify_change_count;
302         unsigned NT_transact_notify_change_time;
303         unsigned NT_transact_rename_count;
304         unsigned NT_transact_rename_time;
305         unsigned NT_transact_query_security_desc_count;
306         unsigned NT_transact_query_security_desc_time;
307 };
308
309
310 extern struct profile_struct *profile_p;
311
312 #define INC_PROFILE_COUNT(x) if (profile_p) profile_p->x++
313 #define DEC_PROFILE_COUNT(x) if (profile_p) profile_p->x--
314 #define ADD_PROFILE_COUNT(x,y) if (profile_p) profile_p->x += (y)
315
316 #define START_PROFILE(x) \
317         struct timeval starttime; \
318         struct timeval endtime; \
319         GetTimeOfDay(&starttime); \
320         INC_PROFILE_COUNT(x##_count)
321
322 #define END_PROFILE(y) \
323         GetTimeOfDay(&endtime); \
324         ADD_PROFILE_COUNT((y##_time),TvalDiff(&starttime,&endtime))
325
326 #endif