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