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