LCOV - code coverage report
Current view: top level - source3/include - smbprofile.h (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 3 13 23.1 %
Date: 2024-06-13 04:01:37 Functions: 1 3 33.3 %

          Line data    Source code
       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             :    Copyright (C) James Peach 2006
       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 3 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, see <http://www.gnu.org/licenses/>.
      21             : 
      22             : */
      23             : 
      24             : struct tevent_context;
      25             : 
      26             : #ifdef WITH_PROFILE
      27             : 
      28             : #define SMBPROFILE_STATS_ALL_SECTIONS \
      29             :         SMBPROFILE_STATS_START \
      30             :         \
      31             :         SMBPROFILE_STATS_SECTION_START(global, "SMBD loop") \
      32             :         SMBPROFILE_STATS_COUNT(connect) \
      33             :         SMBPROFILE_STATS_COUNT(disconnect) \
      34             :         SMBPROFILE_STATS_BASIC(idle) \
      35             :         SMBPROFILE_STATS_TIME(cpu_user) \
      36             :         SMBPROFILE_STATS_TIME(cpu_system) \
      37             :         SMBPROFILE_STATS_COUNT(request) \
      38             :         SMBPROFILE_STATS_BASIC(push_sec_ctx) \
      39             :         SMBPROFILE_STATS_BASIC(set_sec_ctx) \
      40             :         SMBPROFILE_STATS_BASIC(set_root_sec_ctx) \
      41             :         SMBPROFILE_STATS_BASIC(pop_sec_ctx) \
      42             :         SMBPROFILE_STATS_SECTION_END \
      43             :         \
      44             :         SMBPROFILE_STATS_SECTION_START(syscall, "System Calls") \
      45             :         SMBPROFILE_STATS_BASIC(syscall_opendir) \
      46             :         SMBPROFILE_STATS_BASIC(syscall_fdopendir) \
      47             :         SMBPROFILE_STATS_BASIC(syscall_readdir) \
      48             :         SMBPROFILE_STATS_BASIC(syscall_seekdir) \
      49             :         SMBPROFILE_STATS_BASIC(syscall_telldir) \
      50             :         SMBPROFILE_STATS_BASIC(syscall_rewinddir) \
      51             :         SMBPROFILE_STATS_BASIC(syscall_mkdirat) \
      52             :         SMBPROFILE_STATS_BASIC(syscall_closedir) \
      53             :         SMBPROFILE_STATS_BASIC(syscall_open) \
      54             :         SMBPROFILE_STATS_BASIC(syscall_openat) \
      55             :         SMBPROFILE_STATS_BASIC(syscall_createfile) \
      56             :         SMBPROFILE_STATS_BASIC(syscall_close) \
      57             :         SMBPROFILE_STATS_BYTES(syscall_pread) \
      58             :         SMBPROFILE_STATS_BYTES(syscall_asys_pread) \
      59             :         SMBPROFILE_STATS_BYTES(syscall_pwrite) \
      60             :         SMBPROFILE_STATS_BYTES(syscall_asys_pwrite) \
      61             :         SMBPROFILE_STATS_BASIC(syscall_lseek) \
      62             :         SMBPROFILE_STATS_BYTES(syscall_sendfile) \
      63             :         SMBPROFILE_STATS_BYTES(syscall_recvfile) \
      64             :         SMBPROFILE_STATS_BASIC(syscall_renameat) \
      65             :         SMBPROFILE_STATS_BYTES(syscall_asys_fsync) \
      66             :         SMBPROFILE_STATS_BASIC(syscall_stat) \
      67             :         SMBPROFILE_STATS_BASIC(syscall_fstat) \
      68             :         SMBPROFILE_STATS_BASIC(syscall_lstat) \
      69             :         SMBPROFILE_STATS_BASIC(syscall_fstatat) \
      70             :         SMBPROFILE_STATS_BASIC(syscall_get_alloc_size) \
      71             :         SMBPROFILE_STATS_BASIC(syscall_unlinkat) \
      72             :         SMBPROFILE_STATS_BASIC(syscall_chmod) \
      73             :         SMBPROFILE_STATS_BASIC(syscall_fchmod) \
      74             :         SMBPROFILE_STATS_BASIC(syscall_fchown) \
      75             :         SMBPROFILE_STATS_BASIC(syscall_lchown) \
      76             :         SMBPROFILE_STATS_BASIC(syscall_chdir) \
      77             :         SMBPROFILE_STATS_BASIC(syscall_getwd) \
      78             :         SMBPROFILE_STATS_BASIC(syscall_fntimes) \
      79             :         SMBPROFILE_STATS_BASIC(syscall_ftruncate) \
      80             :         SMBPROFILE_STATS_BASIC(syscall_fallocate) \
      81             :         SMBPROFILE_STATS_BASIC(syscall_fcntl_lock) \
      82             :         SMBPROFILE_STATS_BASIC(syscall_fcntl) \
      83             :         SMBPROFILE_STATS_BASIC(syscall_linux_setlease) \
      84             :         SMBPROFILE_STATS_BASIC(syscall_fcntl_getlock) \
      85             :         SMBPROFILE_STATS_BASIC(syscall_readlinkat) \
      86             :         SMBPROFILE_STATS_BASIC(syscall_symlinkat) \
      87             :         SMBPROFILE_STATS_BASIC(syscall_linkat) \
      88             :         SMBPROFILE_STATS_BASIC(syscall_mknodat) \
      89             :         SMBPROFILE_STATS_BASIC(syscall_realpath) \
      90             :         SMBPROFILE_STATS_BASIC(syscall_get_quota) \
      91             :         SMBPROFILE_STATS_BASIC(syscall_set_quota) \
      92             :         SMBPROFILE_STATS_BASIC(syscall_get_sd) \
      93             :         SMBPROFILE_STATS_BASIC(syscall_set_sd) \
      94             :         SMBPROFILE_STATS_BASIC(syscall_brl_lock) \
      95             :         SMBPROFILE_STATS_BASIC(syscall_brl_unlock) \
      96             :         SMBPROFILE_STATS_BASIC(syscall_brl_cancel) \
      97             :         SMBPROFILE_STATS_BYTES(syscall_asys_getxattrat) \
      98             :         SMBPROFILE_STATS_SECTION_END \
      99             :         \
     100             :         SMBPROFILE_STATS_SECTION_START(acl, "ACL Calls") \
     101             :         SMBPROFILE_STATS_BASIC(get_nt_acl) \
     102             :         SMBPROFILE_STATS_BASIC(get_nt_acl_at) \
     103             :         SMBPROFILE_STATS_BASIC(fget_nt_acl) \
     104             :         SMBPROFILE_STATS_BASIC(fset_nt_acl) \
     105             :         SMBPROFILE_STATS_SECTION_END \
     106             :         \
     107             :         SMBPROFILE_STATS_SECTION_START(statcache, "Stat Cache") \
     108             :         SMBPROFILE_STATS_COUNT(statcache_lookups) \
     109             :         SMBPROFILE_STATS_COUNT(statcache_misses) \
     110             :         SMBPROFILE_STATS_COUNT(statcache_hits) \
     111             :         SMBPROFILE_STATS_SECTION_END \
     112             :         \
     113             :         SMBPROFILE_STATS_SECTION_START(SMB, "SMB Calls") \
     114             :         SMBPROFILE_STATS_BASIC(SMBmkdir) \
     115             :         SMBPROFILE_STATS_BASIC(SMBrmdir) \
     116             :         SMBPROFILE_STATS_BASIC(SMBopen) \
     117             :         SMBPROFILE_STATS_BASIC(SMBcreate) \
     118             :         SMBPROFILE_STATS_BASIC(SMBclose) \
     119             :         SMBPROFILE_STATS_BASIC(SMBflush) \
     120             :         SMBPROFILE_STATS_BASIC(SMBunlink) \
     121             :         SMBPROFILE_STATS_BASIC(SMBmv) \
     122             :         SMBPROFILE_STATS_BASIC(SMBgetatr) \
     123             :         SMBPROFILE_STATS_BASIC(SMBsetatr) \
     124             :         SMBPROFILE_STATS_BASIC(SMBread) \
     125             :         SMBPROFILE_STATS_BASIC(SMBwrite) \
     126             :         SMBPROFILE_STATS_BASIC(SMBlock) \
     127             :         SMBPROFILE_STATS_BASIC(SMBunlock) \
     128             :         SMBPROFILE_STATS_BASIC(SMBctemp) \
     129             :         SMBPROFILE_STATS_BASIC(SMBmknew) \
     130             :         SMBPROFILE_STATS_BASIC(SMBcheckpath) \
     131             :         SMBPROFILE_STATS_BASIC(SMBexit) \
     132             :         SMBPROFILE_STATS_BASIC(SMBlseek) \
     133             :         SMBPROFILE_STATS_BASIC(SMBlockread) \
     134             :         SMBPROFILE_STATS_BASIC(SMBwriteunlock) \
     135             :         SMBPROFILE_STATS_BASIC(SMBreadbraw) \
     136             :         SMBPROFILE_STATS_BASIC(SMBreadBmpx) \
     137             :         SMBPROFILE_STATS_BASIC(SMBreadBs) \
     138             :         SMBPROFILE_STATS_BASIC(SMBwritebraw) \
     139             :         SMBPROFILE_STATS_BASIC(SMBwriteBmpx) \
     140             :         SMBPROFILE_STATS_BASIC(SMBwriteBs) \
     141             :         SMBPROFILE_STATS_BASIC(SMBwritec) \
     142             :         SMBPROFILE_STATS_BASIC(SMBsetattrE) \
     143             :         SMBPROFILE_STATS_BASIC(SMBgetattrE) \
     144             :         SMBPROFILE_STATS_BASIC(SMBlockingX) \
     145             :         SMBPROFILE_STATS_BASIC(SMBtrans) \
     146             :         SMBPROFILE_STATS_BASIC(SMBtranss) \
     147             :         SMBPROFILE_STATS_BASIC(SMBioctl) \
     148             :         SMBPROFILE_STATS_BASIC(SMBioctls) \
     149             :         SMBPROFILE_STATS_BASIC(SMBcopy) \
     150             :         SMBPROFILE_STATS_BASIC(SMBmove) \
     151             :         SMBPROFILE_STATS_BASIC(SMBecho) \
     152             :         SMBPROFILE_STATS_BASIC(SMBwriteclose) \
     153             :         SMBPROFILE_STATS_BASIC(SMBopenX) \
     154             :         SMBPROFILE_STATS_BASIC(SMBreadX) \
     155             :         SMBPROFILE_STATS_BASIC(SMBwriteX) \
     156             :         SMBPROFILE_STATS_BASIC(SMBtrans2) \
     157             :         SMBPROFILE_STATS_BASIC(SMBtranss2) \
     158             :         SMBPROFILE_STATS_BASIC(SMBfindclose) \
     159             :         SMBPROFILE_STATS_BASIC(SMBfindnclose) \
     160             :         SMBPROFILE_STATS_BASIC(SMBtcon) \
     161             :         SMBPROFILE_STATS_BASIC(SMBtdis) \
     162             :         SMBPROFILE_STATS_BASIC(SMBnegprot) \
     163             :         SMBPROFILE_STATS_BASIC(SMBsesssetupX) \
     164             :         SMBPROFILE_STATS_BASIC(SMBulogoffX) \
     165             :         SMBPROFILE_STATS_BASIC(SMBtconX) \
     166             :         SMBPROFILE_STATS_BASIC(SMBdskattr) \
     167             :         SMBPROFILE_STATS_BASIC(SMBsearch) \
     168             :         SMBPROFILE_STATS_BASIC(SMBffirst) \
     169             :         SMBPROFILE_STATS_BASIC(SMBfunique) \
     170             :         SMBPROFILE_STATS_BASIC(SMBfclose) \
     171             :         SMBPROFILE_STATS_BASIC(SMBnttrans) \
     172             :         SMBPROFILE_STATS_BASIC(SMBnttranss) \
     173             :         SMBPROFILE_STATS_BASIC(SMBntcreateX) \
     174             :         SMBPROFILE_STATS_BASIC(SMBntcancel) \
     175             :         SMBPROFILE_STATS_BASIC(SMBntrename) \
     176             :         SMBPROFILE_STATS_BASIC(SMBsplopen) \
     177             :         SMBPROFILE_STATS_BASIC(SMBsplwr) \
     178             :         SMBPROFILE_STATS_BASIC(SMBsplclose) \
     179             :         SMBPROFILE_STATS_BASIC(SMBsplretq) \
     180             :         SMBPROFILE_STATS_BASIC(SMBsends) \
     181             :         SMBPROFILE_STATS_BASIC(SMBsendb) \
     182             :         SMBPROFILE_STATS_BASIC(SMBfwdname) \
     183             :         SMBPROFILE_STATS_BASIC(SMBcancelf) \
     184             :         SMBPROFILE_STATS_BASIC(SMBgetmac) \
     185             :         SMBPROFILE_STATS_BASIC(SMBsendstrt) \
     186             :         SMBPROFILE_STATS_BASIC(SMBsendend) \
     187             :         SMBPROFILE_STATS_BASIC(SMBsendtxt) \
     188             :         SMBPROFILE_STATS_BASIC(SMBinvalid) \
     189             :         SMBPROFILE_STATS_SECTION_END \
     190             :         \
     191             :         SMBPROFILE_STATS_SECTION_START(Trans2, "Trans2 Calls") \
     192             :         SMBPROFILE_STATS_BASIC(Trans2_open) \
     193             :         SMBPROFILE_STATS_BASIC(Trans2_findfirst) \
     194             :         SMBPROFILE_STATS_BASIC(Trans2_findnext) \
     195             :         SMBPROFILE_STATS_BASIC(Trans2_qfsinfo) \
     196             :         SMBPROFILE_STATS_BASIC(Trans2_setfsinfo) \
     197             :         SMBPROFILE_STATS_BASIC(Trans2_qpathinfo) \
     198             :         SMBPROFILE_STATS_BASIC(Trans2_setpathinfo) \
     199             :         SMBPROFILE_STATS_BASIC(Trans2_qfileinfo) \
     200             :         SMBPROFILE_STATS_BASIC(Trans2_setfileinfo) \
     201             :         SMBPROFILE_STATS_BASIC(Trans2_fsctl) \
     202             :         SMBPROFILE_STATS_BASIC(Trans2_ioctl) \
     203             :         SMBPROFILE_STATS_BASIC(Trans2_findnotifyfirst) \
     204             :         SMBPROFILE_STATS_BASIC(Trans2_findnotifynext) \
     205             :         SMBPROFILE_STATS_BASIC(Trans2_mkdir) \
     206             :         SMBPROFILE_STATS_BASIC(Trans2_session_setup) \
     207             :         SMBPROFILE_STATS_BASIC(Trans2_get_dfs_referral) \
     208             :         SMBPROFILE_STATS_BASIC(Trans2_report_dfs_inconsistancy) \
     209             :         SMBPROFILE_STATS_SECTION_END \
     210             :         \
     211             :         SMBPROFILE_STATS_SECTION_START(NT_transact, "NT Transact Calls") \
     212             :         SMBPROFILE_STATS_BASIC(NT_transact_create) \
     213             :         SMBPROFILE_STATS_BASIC(NT_transact_ioctl) \
     214             :         SMBPROFILE_STATS_BASIC(NT_transact_set_security_desc) \
     215             :         SMBPROFILE_STATS_BASIC(NT_transact_notify_change) \
     216             :         SMBPROFILE_STATS_BASIC(NT_transact_rename) \
     217             :         SMBPROFILE_STATS_BASIC(NT_transact_query_security_desc) \
     218             :         SMBPROFILE_STATS_BASIC(NT_transact_get_user_quota) \
     219             :         SMBPROFILE_STATS_BASIC(NT_transact_set_user_quota) \
     220             :         SMBPROFILE_STATS_SECTION_END \
     221             :         \
     222             :         SMBPROFILE_STATS_SECTION_START(smb2, "SMB2 Calls") \
     223             :         SMBPROFILE_STATS_IOBYTES(smb2_negprot) \
     224             :         SMBPROFILE_STATS_IOBYTES(smb2_sesssetup) \
     225             :         SMBPROFILE_STATS_IOBYTES(smb2_logoff) \
     226             :         SMBPROFILE_STATS_IOBYTES(smb2_tcon) \
     227             :         SMBPROFILE_STATS_IOBYTES(smb2_tdis) \
     228             :         SMBPROFILE_STATS_IOBYTES(smb2_create) \
     229             :         SMBPROFILE_STATS_IOBYTES(smb2_close) \
     230             :         SMBPROFILE_STATS_IOBYTES(smb2_flush) \
     231             :         SMBPROFILE_STATS_IOBYTES(smb2_read) \
     232             :         SMBPROFILE_STATS_IOBYTES(smb2_write) \
     233             :         SMBPROFILE_STATS_IOBYTES(smb2_lock) \
     234             :         SMBPROFILE_STATS_IOBYTES(smb2_ioctl) \
     235             :         SMBPROFILE_STATS_IOBYTES(smb2_cancel) \
     236             :         SMBPROFILE_STATS_IOBYTES(smb2_keepalive) \
     237             :         SMBPROFILE_STATS_IOBYTES(smb2_find) \
     238             :         SMBPROFILE_STATS_IOBYTES(smb2_notify) \
     239             :         SMBPROFILE_STATS_IOBYTES(smb2_getinfo) \
     240             :         SMBPROFILE_STATS_IOBYTES(smb2_setinfo) \
     241             :         SMBPROFILE_STATS_IOBYTES(smb2_break) \
     242             :         SMBPROFILE_STATS_SECTION_END \
     243             :         \
     244             :         SMBPROFILE_STATS_END
     245             : 
     246             : /* this file defines the profile structure in the profile shared
     247             :    memory area */
     248             : 
     249             : /* time values in the following structure are in microseconds */
     250             : 
     251             : struct smbprofile_stats_count {
     252             :         uint64_t count;         /* number of events */
     253             : };
     254             : 
     255             : struct smbprofile_stats_time {
     256             :         uint64_t time;          /* microseconds */
     257             : };
     258             : 
     259             : struct smbprofile_stats_time_async {
     260             :         uint64_t start;
     261             :         struct smbprofile_stats_time *stats;
     262             : };
     263             : 
     264             : struct smbprofile_stats_basic {
     265             :         uint64_t count;         /* number of events */
     266             :         uint64_t time;          /* microseconds */
     267             : };
     268             : 
     269             : struct smbprofile_stats_basic_async {
     270             :         uint64_t start;
     271             :         struct smbprofile_stats_basic *stats;
     272             : };
     273             : 
     274             : struct smbprofile_stats_bytes {
     275             :         uint64_t count;         /* number of events */
     276             :         uint64_t time;          /* microseconds */
     277             :         uint64_t idle;          /* idle time compared to 'time' microseconds */
     278             :         uint64_t bytes;         /* bytes */
     279             : };
     280             : 
     281             : struct smbprofile_stats_bytes_async {
     282             :         uint64_t start;
     283             :         uint64_t idle_start;
     284             :         uint64_t idle_time;
     285             :         struct smbprofile_stats_bytes *stats;
     286             : };
     287             : 
     288             : struct smbprofile_stats_iobytes {
     289             :         uint64_t count;         /* number of events */
     290             :         uint64_t time;          /* microseconds */
     291             :         uint64_t idle;          /* idle time compared to 'time' microseconds */
     292             :         uint64_t inbytes;       /* bytes read */
     293             :         uint64_t outbytes;      /* bytes written */
     294             : };
     295             : 
     296             : struct smbprofile_stats_iobytes_async {
     297             :         uint64_t start;
     298             :         uint64_t idle_start;
     299             :         uint64_t idle_time;
     300             :         struct smbprofile_stats_iobytes *stats;
     301             : };
     302             : 
     303             : struct profile_stats {
     304             :         uint64_t magic;
     305             :         struct {
     306             : #define SMBPROFILE_STATS_START
     307             : #define SMBPROFILE_STATS_SECTION_START(name, display)
     308             : #define SMBPROFILE_STATS_COUNT(name) \
     309             :         struct smbprofile_stats_count name##_stats;
     310             : #define SMBPROFILE_STATS_TIME(name) \
     311             :         struct smbprofile_stats_time name##_stats;
     312             : #define SMBPROFILE_STATS_BASIC(name) \
     313             :         struct smbprofile_stats_basic name##_stats;
     314             : #define SMBPROFILE_STATS_BYTES(name) \
     315             :         struct smbprofile_stats_bytes name##_stats;
     316             : #define SMBPROFILE_STATS_IOBYTES(name) \
     317             :         struct smbprofile_stats_iobytes name##_stats;
     318             : #define SMBPROFILE_STATS_SECTION_END
     319             : #define SMBPROFILE_STATS_END
     320             :         SMBPROFILE_STATS_ALL_SECTIONS
     321             : #undef SMBPROFILE_STATS_START
     322             : #undef SMBPROFILE_STATS_SECTION_START
     323             : #undef SMBPROFILE_STATS_COUNT
     324             : #undef SMBPROFILE_STATS_TIME
     325             : #undef SMBPROFILE_STATS_BASIC
     326             : #undef SMBPROFILE_STATS_BYTES
     327             : #undef SMBPROFILE_STATS_IOBYTES
     328             : #undef SMBPROFILE_STATS_SECTION_END
     329             : #undef SMBPROFILE_STATS_END
     330             :         } values;
     331             : };
     332             : 
     333             : #define _SMBPROFILE_COUNT_INCREMENT(_stats, _area, _v) do { \
     334             :         if (smbprofile_state.config.do_count) { \
     335             :                 (_area)->values._stats.count += (_v); \
     336             :                 smbprofile_dump_schedule(); \
     337             :         } \
     338             : } while(0)
     339             : #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v) \
     340             :         _SMBPROFILE_COUNT_INCREMENT(_name##_stats, _area, _v)
     341             : 
     342             : #define SMBPROFILE_TIME_ASYNC_STATE(_async_name) \
     343             :         struct smbprofile_stats_time_async _async_name;
     344             : #define _SMBPROFILE_TIME_ASYNC_START(_stats, _area, _async) do { \
     345             :         (_async) = (struct smbprofile_stats_time_async) {}; \
     346             :         if (smbprofile_state.config.do_times) { \
     347             :                 (_async).stats = &((_area)->values._stats), \
     348             :                 (_async).start = profile_timestamp(); \
     349             :         } \
     350             : } while(0)
     351             : #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async) \
     352             :         _SMBPROFILE_TIME_ASYNC_START(_name##_stats, _area, _async)
     353             : #define SMBPROFILE_TIME_ASYNC_END(_async) do { \
     354             :         if ((_async).start != 0) { \
     355             :                 (_async).stats->time += profile_timestamp() - (_async).start; \
     356             :                 (_async) = (struct smbprofile_stats_basic_async) {}; \
     357             :                 smbprofile_dump_schedule(); \
     358             :         } \
     359             : } while(0)
     360             : 
     361             : #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name) \
     362             :         struct smbprofile_stats_basic_async _async_name;
     363             : #define _SMBPROFILE_BASIC_ASYNC_START(_stats, _area, _async) do { \
     364             :         (_async) = (struct smbprofile_stats_basic_async) {}; \
     365             :         if (smbprofile_state.config.do_count) { \
     366             :                 if (smbprofile_state.config.do_times) { \
     367             :                         (_async).start = profile_timestamp(); \
     368             :                         (_async).stats = &((_area)->values._stats); \
     369             :                 } \
     370             :                 (_area)->values._stats.count += 1; \
     371             :                 smbprofile_dump_schedule(); \
     372             :         } \
     373             : } while(0)
     374             : #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async) \
     375             :         _SMBPROFILE_BASIC_ASYNC_START(_name##_stats, _area, _async)
     376             : #define SMBPROFILE_BASIC_ASYNC_END(_async) do { \
     377             :         if ((_async).start != 0) { \
     378             :                 (_async).stats->time += profile_timestamp() - (_async).start; \
     379             :                 (_async) = (struct smbprofile_stats_basic_async) {}; \
     380             :                 smbprofile_dump_schedule(); \
     381             :         } \
     382             : } while(0)
     383             : 
     384             : #define _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async) do { \
     385             :         (_async).stats = &((_area)->values._stats); \
     386             :         if (smbprofile_state.config.do_times) { \
     387             :                 (_async).start = profile_timestamp(); \
     388             :         } \
     389             : } while(0)
     390             : #define _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async) do { \
     391             :         if ((_async).start != 0) { \
     392             :                 if ((_async).idle_start == 0) { \
     393             :                         (_async).idle_start = profile_timestamp(); \
     394             :                 } \
     395             :         } \
     396             : } while(0)
     397             : #define _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async) do { \
     398             :         if ((_async).idle_start != 0) { \
     399             :                 (_async).idle_time += \
     400             :                         profile_timestamp() - (_async).idle_start; \
     401             :                 (_async).idle_start = 0; \
     402             :         } \
     403             : } while(0)
     404             : #define _SMBPROFILE_TIMER_ASYNC_END(_async) do { \
     405             :         if ((_async).start != 0) { \
     406             :                 _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async); \
     407             :                 (_async).stats->time += profile_timestamp() - (_async).start; \
     408             :                 (_async).stats->idle += (_async).idle_time; \
     409             :         } \
     410             : } while(0)
     411             : 
     412             : #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name) \
     413             :         struct smbprofile_stats_bytes_async _async_name;
     414             : #define _SMBPROFILE_BYTES_ASYNC_START(_stats, _area, _async, _bytes) do { \
     415             :         (_async) = (struct smbprofile_stats_bytes_async) {}; \
     416             :         if (smbprofile_state.config.do_count) { \
     417             :                 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
     418             :                 (_area)->values._stats.count += 1; \
     419             :                 (_area)->values._stats.bytes += (_bytes); \
     420             :                 smbprofile_dump_schedule(); \
     421             :         } \
     422             : } while(0)
     423             : #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _bytes) \
     424             :         _SMBPROFILE_BYTES_ASYNC_START(_name##_stats, _area, _async, _bytes)
     425             : #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async) \
     426             :         _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
     427             : #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async) \
     428             :         _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
     429             : #define SMBPROFILE_BYTES_ASYNC_END(_async) do { \
     430             :         if ((_async).stats != NULL) { \
     431             :                 _SMBPROFILE_TIMER_ASYNC_END(_async); \
     432             :                 (_async) = (struct smbprofile_stats_bytes_async) {}; \
     433             :                 smbprofile_dump_schedule(); \
     434             :         } \
     435             : } while(0)
     436             : 
     437             : #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name) \
     438             :         struct smbprofile_stats_iobytes_async _async_name;
     439             : #define _SMBPROFILE_IOBYTES_ASYNC_START(_stats, _area, _async, _inbytes) do { \
     440             :         (_async) = (struct smbprofile_stats_iobytes_async) {}; \
     441             :         if (smbprofile_state.config.do_count) { \
     442             :                 _SMBPROFILE_TIMER_ASYNC_START(_stats, _area, _async); \
     443             :                 (_area)->values._stats.count += 1; \
     444             :                 (_area)->values._stats.inbytes += (_inbytes); \
     445             :                 smbprofile_dump_schedule(); \
     446             :         } \
     447             : } while(0)
     448             : #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes) \
     449             :         _SMBPROFILE_IOBYTES_ASYNC_START(_name##_stats, _area, _async, _inbytes)
     450             : #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async) \
     451             :         _SMBPROFILE_TIMER_ASYNC_SET_IDLE(_async)
     452             : #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async) \
     453             :         _SMBPROFILE_TIMER_ASYNC_SET_BUSY(_async)
     454             : #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes) do { \
     455             :         if ((_async).stats != NULL) { \
     456             :                 (_async).stats->outbytes += (_outbytes); \
     457             :                 _SMBPROFILE_TIMER_ASYNC_END(_async); \
     458             :                 (_async) = (struct smbprofile_stats_iobytes_async) {}; \
     459             :                 smbprofile_dump_schedule(); \
     460             :         } \
     461             : } while(0)
     462             : 
     463             : extern struct profile_stats *profile_p;
     464             : 
     465             : struct smbprofile_global_state {
     466             :         struct {
     467             :                 struct tdb_wrap *db;
     468             :                 struct tevent_context *ev;
     469             :                 struct tevent_timer *te;
     470             :         } internal;
     471             : 
     472             :         struct {
     473             :                 bool do_count;
     474             :                 bool do_times;
     475             :         } config;
     476             : 
     477             :         struct {
     478             :                 struct profile_stats global;
     479             :         } stats;
     480             : };
     481             : 
     482             : extern struct smbprofile_global_state smbprofile_state;
     483             : 
     484             : void smbprofile_dump_schedule_timer(void);
     485             : void smbprofile_dump_setup(struct tevent_context *ev);
     486             : 
     487           0 : static inline void smbprofile_dump_schedule(void)
     488             : {
     489           0 :         if (likely(smbprofile_state.internal.te != NULL)) {
     490           0 :                 return;
     491             :         }
     492             : 
     493           0 :         if (unlikely(smbprofile_state.internal.ev == NULL)) {
     494           0 :                 return;
     495             :         }
     496             : 
     497           0 :         smbprofile_dump_schedule_timer();
     498             : }
     499             : 
     500      925998 : static inline bool smbprofile_dump_pending(void)
     501             : {
     502      925998 :         if (smbprofile_state.internal.te == NULL) {
     503      925998 :                 return false;
     504             :         }
     505             : 
     506           0 :         return true;
     507             : }
     508             : 
     509             : void smbprofile_dump(void);
     510             : 
     511             : void smbprofile_cleanup(pid_t pid, pid_t dst);
     512             : void smbprofile_stats_accumulate(struct profile_stats *acc,
     513             :                                  const struct profile_stats *add);
     514             : void smbprofile_collect(struct profile_stats *stats);
     515             : 
     516           0 : static inline uint64_t profile_timestamp(void)
     517             : {
     518             :         struct timespec ts;
     519             : 
     520             :         /* we might prefer to use the _COARSE clock variant of CLOCK_MONOTONIC
     521             :            that one is faster but cached and "just" tick-wise precise */
     522           0 :         clock_gettime_mono(&ts);
     523           0 :         return (ts.tv_sec * 1000000) + (ts.tv_nsec / 1000); /* usec */
     524             : }
     525             : 
     526             : #define DO_PROFILE_INC(x) \
     527             :         _SMBPROFILE_COUNT_INCREMENT(x##_stats, profile_p, 1); \
     528             : 
     529             : #define START_PROFILE(x) \
     530             :         struct smbprofile_stats_basic_async __profasync_##x = {}; \
     531             :         _SMBPROFILE_BASIC_ASYNC_START(x##_stats, profile_p, __profasync_##x);
     532             : 
     533             : #define START_PROFILE_BYTES(x,n) \
     534             :         struct smbprofile_stats_bytes_async __profasync_##x = {}; \
     535             :         _SMBPROFILE_BYTES_ASYNC_START(x##_stats, profile_p, __profasync_##x, n);
     536             : 
     537             : #define END_PROFILE(x) \
     538             :         SMBPROFILE_BASIC_ASYNC_END(__profasync_##x)
     539             : 
     540             : #define END_PROFILE_BYTES(x) \
     541             :         SMBPROFILE_BYTES_ASYNC_END(__profasync_##x)
     542             : 
     543             : #define PROFILE_TIMESTAMP(x) clock_gettime_mono(x)
     544             : 
     545             : #else /* WITH_PROFILE */
     546             : 
     547             : #define SMBPROFILE_COUNT_INCREMENT(_name, _area, _v)
     548             : 
     549             : #define SMBPROFILE_TIME_ASYNC_STATE(_async_name)
     550             : #define SMBPROFILE_TIME_ASYNC_START(_name, _area, _async)
     551             : #define SMBPROFILE_TIME_ASYNC_END(_async)
     552             : 
     553             : #define SMBPROFILE_BASIC_ASYNC_STATE(_async_name)
     554             : #define SMBPROFILE_BASIC_ASYNC_START(_name, _area, _async)
     555             : #define SMBPROFILE_BASIC_ASYNC_END(_async)
     556             : 
     557             : #define SMBPROFILE_BYTES_ASYNC_STATE(_async_name)
     558             : #define SMBPROFILE_BYTES_ASYNC_START(_name, _area, _async, _inbytes)
     559             : #define SMBPROFILE_BYTES_ASYNC_SET_IDLE(_async)
     560             : #define SMBPROFILE_BYTES_ASYNC_SET_BUSY(_async)
     561             : #define SMBPROFILE_BYTES_ASYNC_END(_async)
     562             : 
     563             : #define SMBPROFILE_IOBYTES_ASYNC_STATE(_async_name)
     564             : #define SMBPROFILE_IOBYTES_ASYNC_START(_name, _area, _async, _inbytes)
     565             : #define SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(_async)
     566             : #define SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(_async)
     567             : #define SMBPROFILE_IOBYTES_ASYNC_END(_async, _outbytes)
     568             : 
     569             : #define DO_PROFILE_INC(x)
     570             : #define START_PROFILE(x)
     571             : #define START_PROFILE_BYTES(x,n)
     572             : #define END_PROFILE(x)
     573             : #define END_PROFILE_BYTES(x)
     574             : 
     575             : #define PROFILE_TIMESTAMP(x) (*(x)=(struct timespec){0})
     576             : 
     577             : static inline bool smbprofile_dump_pending(void)
     578             : {
     579             :         return false;
     580             : }
     581             : 
     582             : static inline void smbprofile_dump_setup(struct tevent_context *ev)
     583             : {
     584             :         return;
     585             : }
     586             : 
     587             : static inline void smbprofile_dump(void)
     588             : {
     589             :         return;
     590             : }
     591             : 
     592             : static inline void smbprofile_cleanup(pid_t pid, pid_t dst)
     593             : {
     594             :         return;
     595             : }
     596             : 
     597             : #endif /* WITH_PROFILE */
     598             : 
     599             : /* The following definitions come from profile/profile.c  */
     600             : struct server_id;
     601             : 
     602             : void set_profile_level(int level, const struct server_id *src);
     603             : 
     604             : struct messaging_context;
     605             : bool profile_setup(struct messaging_context *msg_ctx, bool rdonly);
     606             : 
     607             : #endif

Generated by: LCOV version 1.13