Home | History | Annotate | Download | only in rtl
      1 //===-- tsan_stat.cc ------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of ThreadSanitizer (TSan), a race detector.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 #include "tsan_stat.h"
     14 #include "tsan_rtl.h"
     15 
     16 namespace __tsan {
     17 
     18 void StatAggregate(u64 *dst, u64 *src) {
     19   if (!kCollectStats)
     20     return;
     21   for (int i = 0; i < StatCnt; i++)
     22     dst[i] += src[i];
     23 }
     24 
     25 void StatOutput(u64 *stat) {
     26   if (!kCollectStats)
     27     return;
     28 
     29   stat[StatShadowNonZero] = stat[StatShadowProcessed] - stat[StatShadowZero];
     30 
     31   static const char *name[StatCnt] = {};
     32   name[StatMop]                          = "Memory accesses                   ";
     33   name[StatMopRead]                      = "  Including reads                 ";
     34   name[StatMopWrite]                     = "            writes                ";
     35   name[StatMop1]                         = "  Including size 1                ";
     36   name[StatMop2]                         = "            size 2                ";
     37   name[StatMop4]                         = "            size 4                ";
     38   name[StatMop8]                         = "            size 8                ";
     39   name[StatMopSame]                      = "  Including same                  ";
     40   name[StatMopRange]                     = "  Including range                 ";
     41   name[StatShadowProcessed]              = "Shadow processed                  ";
     42   name[StatShadowZero]                   = "  Including empty                 ";
     43   name[StatShadowNonZero]                = "  Including non empty             ";
     44   name[StatShadowSameSize]               = "  Including same size             ";
     45   name[StatShadowIntersect]              = "            intersect             ";
     46   name[StatShadowNotIntersect]           = "            not intersect         ";
     47   name[StatShadowSameThread]             = "  Including same thread           ";
     48   name[StatShadowAnotherThread]          = "            another thread        ";
     49   name[StatShadowReplace]                = "  Including evicted               ";
     50 
     51   name[StatFuncEnter]                    = "Function entries                  ";
     52   name[StatFuncExit]                     = "Function exits                    ";
     53   name[StatEvents]                       = "Events collected                  ";
     54 
     55   name[StatThreadCreate]                 = "Total threads created             ";
     56   name[StatThreadFinish]                 = "  threads finished                ";
     57   name[StatThreadReuse]                  = "  threads reused                  ";
     58   name[StatThreadMaxTid]                 = "  max tid                         ";
     59   name[StatThreadMaxAlive]               = "  max alive threads               ";
     60 
     61   name[StatMutexCreate]                  = "Mutexes created                   ";
     62   name[StatMutexDestroy]                 = "  destroyed                       ";
     63   name[StatMutexLock]                    = "  lock                            ";
     64   name[StatMutexUnlock]                  = "  unlock                          ";
     65   name[StatMutexRecLock]                 = "  recursive lock                  ";
     66   name[StatMutexRecUnlock]               = "  recursive unlock                ";
     67   name[StatMutexReadLock]                = "  read lock                       ";
     68   name[StatMutexReadUnlock]              = "  read unlock                     ";
     69 
     70   name[StatSyncCreated]                  = "Sync objects created              ";
     71   name[StatSyncDestroyed]                = "             destroyed            ";
     72   name[StatSyncAcquire]                  = "             acquired             ";
     73   name[StatSyncRelease]                  = "             released             ";
     74 
     75   name[StatAtomic]                       = "Atomic operations                 ";
     76   name[StatAtomicLoad]                   = "  Including load                  ";
     77   name[StatAtomicStore]                  = "            store                 ";
     78   name[StatAtomicExchange]               = "            exchange              ";
     79   name[StatAtomicFetchAdd]               = "            fetch_add             ";
     80   name[StatAtomicFetchSub]               = "            fetch_sub             ";
     81   name[StatAtomicFetchAnd]               = "            fetch_and             ";
     82   name[StatAtomicFetchOr]                = "            fetch_or              ";
     83   name[StatAtomicFetchXor]               = "            fetch_xor             ";
     84   name[StatAtomicFetchNand]              = "            fetch_nand            ";
     85   name[StatAtomicCAS]                    = "            compare_exchange      ";
     86   name[StatAtomicFence]                  = "            fence                 ";
     87   name[StatAtomicRelaxed]                = "  Including relaxed               ";
     88   name[StatAtomicConsume]                = "            consume               ";
     89   name[StatAtomicAcquire]                = "            acquire               ";
     90   name[StatAtomicRelease]                = "            release               ";
     91   name[StatAtomicAcq_Rel]                = "            acq_rel               ";
     92   name[StatAtomicSeq_Cst]                = "            seq_cst               ";
     93   name[StatAtomic1]                      = "  Including size 1                ";
     94   name[StatAtomic2]                      = "            size 2                ";
     95   name[StatAtomic4]                      = "            size 4                ";
     96   name[StatAtomic8]                      = "            size 8                ";
     97   name[StatAtomic16]                     = "            size 16               ";
     98 
     99   name[StatInterceptor]                  = "Interceptors                      ";
    100   name[StatInt_longjmp]                  = "  longjmp                         ";
    101   name[StatInt_siglongjmp]               = "  siglongjmp                      ";
    102   name[StatInt_malloc]                   = "  malloc                          ";
    103   name[StatInt___libc_memalign]          = "  __libc_memalign                 ";
    104   name[StatInt_calloc]                   = "  calloc                          ";
    105   name[StatInt_realloc]                  = "  realloc                         ";
    106   name[StatInt_free]                     = "  free                            ";
    107   name[StatInt_cfree]                    = "  cfree                           ";
    108   name[StatInt_mmap]                     = "  mmap                            ";
    109   name[StatInt_mmap64]                   = "  mmap64                          ";
    110   name[StatInt_munmap]                   = "  munmap                          ";
    111   name[StatInt_memalign]                 = "  memalign                        ";
    112   name[StatInt_valloc]                   = "  valloc                          ";
    113   name[StatInt_pvalloc]                  = "  pvalloc                         ";
    114   name[StatInt_posix_memalign]           = "  posix_memalign                  ";
    115   name[StatInt__Znwm]                    = "  _Znwm                           ";
    116   name[StatInt__ZnwmRKSt9nothrow_t]      = "  _ZnwmRKSt9nothrow_t             ";
    117   name[StatInt__Znam]                    = "  _Znam                           ";
    118   name[StatInt__ZnamRKSt9nothrow_t]      = "  _ZnamRKSt9nothrow_t             ";
    119   name[StatInt__ZdlPv]                   = "  _ZdlPv                          ";
    120   name[StatInt__ZdlPvRKSt9nothrow_t]     = "  _ZdlPvRKSt9nothrow_t            ";
    121   name[StatInt__ZdaPv]                   = "  _ZdaPv                          ";
    122   name[StatInt__ZdaPvRKSt9nothrow_t]     = "  _ZdaPvRKSt9nothrow_t            ";
    123   name[StatInt_strlen]                   = "  strlen                          ";
    124   name[StatInt_memset]                   = "  memset                          ";
    125   name[StatInt_memcpy]                   = "  memcpy                          ";
    126   name[StatInt_strcmp]                   = "  strcmp                          ";
    127   name[StatInt_memchr]                   = "  memchr                          ";
    128   name[StatInt_memrchr]                  = "  memrchr                         ";
    129   name[StatInt_memmove]                  = "  memmove                         ";
    130   name[StatInt_memcmp]                   = "  memcmp                          ";
    131   name[StatInt_strchr]                   = "  strchr                          ";
    132   name[StatInt_strchrnul]                = "  strchrnul                       ";
    133   name[StatInt_strrchr]                  = "  strrchr                         ";
    134   name[StatInt_strncmp]                  = "  strncmp                         ";
    135   name[StatInt_strcpy]                   = "  strcpy                          ";
    136   name[StatInt_strncpy]                  = "  strncpy                         ";
    137   name[StatInt_strstr]                   = "  strstr                          ";
    138   name[StatInt_atexit]                   = "  atexit                          ";
    139   name[StatInt___cxa_guard_acquire]      = "  __cxa_guard_acquire             ";
    140   name[StatInt___cxa_guard_release]      = "  __cxa_guard_release             ";
    141   name[StatInt___cxa_guard_abort]        = "  __cxa_guard_abort               ";
    142   name[StatInt_pthread_create]           = "  pthread_create                  ";
    143   name[StatInt_pthread_join]             = "  pthread_join                    ";
    144   name[StatInt_pthread_detach]           = "  pthread_detach                  ";
    145   name[StatInt_pthread_mutex_init]       = "  pthread_mutex_init              ";
    146   name[StatInt_pthread_mutex_destroy]    = "  pthread_mutex_destroy           ";
    147   name[StatInt_pthread_mutex_lock]       = "  pthread_mutex_lock              ";
    148   name[StatInt_pthread_mutex_trylock]    = "  pthread_mutex_trylock           ";
    149   name[StatInt_pthread_mutex_timedlock]  = "  pthread_mutex_timedlock         ";
    150   name[StatInt_pthread_mutex_unlock]     = "  pthread_mutex_unlock            ";
    151   name[StatInt_pthread_spin_init]        = "  pthread_spin_init               ";
    152   name[StatInt_pthread_spin_destroy]     = "  pthread_spin_destroy            ";
    153   name[StatInt_pthread_spin_lock]        = "  pthread_spin_lock               ";
    154   name[StatInt_pthread_spin_trylock]     = "  pthread_spin_trylock            ";
    155   name[StatInt_pthread_spin_unlock]      = "  pthread_spin_unlock             ";
    156   name[StatInt_pthread_rwlock_init]      = "  pthread_rwlock_init             ";
    157   name[StatInt_pthread_rwlock_destroy]   = "  pthread_rwlock_destroy          ";
    158   name[StatInt_pthread_rwlock_rdlock]    = "  pthread_rwlock_rdlock           ";
    159   name[StatInt_pthread_rwlock_tryrdlock] = "  pthread_rwlock_tryrdlock        ";
    160   name[StatInt_pthread_rwlock_timedrdlock]
    161                                          = "  pthread_rwlock_timedrdlock      ";
    162   name[StatInt_pthread_rwlock_wrlock]    = "  pthread_rwlock_wrlock           ";
    163   name[StatInt_pthread_rwlock_trywrlock] = "  pthread_rwlock_trywrlock        ";
    164   name[StatInt_pthread_rwlock_timedwrlock]
    165                                          = "  pthread_rwlock_timedwrlock      ";
    166   name[StatInt_pthread_rwlock_unlock]    = "  pthread_rwlock_unlock           ";
    167   name[StatInt_pthread_cond_init]        = "  pthread_cond_init               ";
    168   name[StatInt_pthread_cond_destroy]     = "  pthread_cond_destroy            ";
    169   name[StatInt_pthread_cond_signal]      = "  pthread_cond_signal             ";
    170   name[StatInt_pthread_cond_broadcast]   = "  pthread_cond_broadcast          ";
    171   name[StatInt_pthread_cond_wait]        = "  pthread_cond_wait               ";
    172   name[StatInt_pthread_cond_timedwait]   = "  pthread_cond_timedwait          ";
    173   name[StatInt_pthread_barrier_init]     = "  pthread_barrier_init            ";
    174   name[StatInt_pthread_barrier_destroy]  = "  pthread_barrier_destroy         ";
    175   name[StatInt_pthread_barrier_wait]     = "  pthread_barrier_wait            ";
    176   name[StatInt_pthread_once]             = "  pthread_once                    ";
    177   name[StatInt_sem_init]                 = "  sem_init                        ";
    178   name[StatInt_sem_destroy]              = "  sem_destroy                     ";
    179   name[StatInt_sem_wait]                 = "  sem_wait                        ";
    180   name[StatInt_sem_trywait]              = "  sem_trywait                     ";
    181   name[StatInt_sem_timedwait]            = "  sem_timedwait                   ";
    182   name[StatInt_sem_post]                 = "  sem_post                        ";
    183   name[StatInt_sem_getvalue]             = "  sem_getvalue                    ";
    184   name[StatInt_stat]                     = "  stat                            ";
    185   name[StatInt___xstat]                  = "  __xstat                         ";
    186   name[StatInt_stat64]                   = "  stat64                          ";
    187   name[StatInt___xstat64]                = "  __xstat64                       ";
    188   name[StatInt_lstat]                    = "  lstat                           ";
    189   name[StatInt___lxstat]                 = "  __lxstat                        ";
    190   name[StatInt_lstat64]                  = "  lstat64                         ";
    191   name[StatInt___lxstat64]               = "  __lxstat64                      ";
    192   name[StatInt_fstat]                    = "  fstat                           ";
    193   name[StatInt___fxstat]                 = "  __fxstat                        ";
    194   name[StatInt_fstat64]                  = "  fstat64                         ";
    195   name[StatInt___fxstat64]               = "  __fxstat64                      ";
    196   name[StatInt_open]                     = "  open                            ";
    197   name[StatInt_open64]                   = "  open64                          ";
    198   name[StatInt_creat]                    = "  creat                           ";
    199   name[StatInt_creat64]                  = "  creat64                         ";
    200   name[StatInt_dup]                      = "  dup                             ";
    201   name[StatInt_dup2]                     = "  dup2                            ";
    202   name[StatInt_dup3]                     = "  dup3                            ";
    203   name[StatInt_eventfd]                  = "  eventfd                         ";
    204   name[StatInt_signalfd]                 = "  signalfd                        ";
    205   name[StatInt_inotify_init]             = "  inotify_init                    ";
    206   name[StatInt_inotify_init1]            = "  inotify_init1                   ";
    207   name[StatInt_socket]                   = "  socket                          ";
    208   name[StatInt_socketpair]               = "  socketpair                      ";
    209   name[StatInt_connect]                  = "  connect                         ";
    210   name[StatInt_bind]                     = "  bind                            ";
    211   name[StatInt_listen]                   = "  listen                          ";
    212   name[StatInt_accept]                   = "  accept                          ";
    213   name[StatInt_accept4]                  = "  accept4                         ";
    214   name[StatInt_epoll_create]             = "  epoll_create                    ";
    215   name[StatInt_epoll_create1]            = "  epoll_create1                   ";
    216   name[StatInt_close]                    = "  close                           ";
    217   name[StatInt___close]                  = "  __close                         ";
    218   name[StatInt___res_iclose]             = "  __res_iclose                    ";
    219   name[StatInt_pipe]                     = "  pipe                            ";
    220   name[StatInt_pipe2]                    = "  pipe2                           ";
    221   name[StatInt_read]                     = "  read                            ";
    222   name[StatInt_prctl]                    = "  prctl                           ";
    223   name[StatInt_pread]                    = "  pread                           ";
    224   name[StatInt_pread64]                  = "  pread64                         ";
    225   name[StatInt_readv]                    = "  readv                           ";
    226   name[StatInt_preadv64]                 = "  preadv64                        ";
    227   name[StatInt_write]                    = "  write                           ";
    228   name[StatInt_pwrite]                   = "  pwrite                          ";
    229   name[StatInt_pwrite64]                 = "  pwrite64                        ";
    230   name[StatInt_writev]                   = "  writev                          ";
    231   name[StatInt_pwritev64]                = "  pwritev64                       ";
    232   name[StatInt_send]                     = "  send                            ";
    233   name[StatInt_sendmsg]                  = "  sendmsg                         ";
    234   name[StatInt_recv]                     = "  recv                            ";
    235   name[StatInt_recvmsg]                  = "  recvmsg                         ";
    236   name[StatInt_unlink]                   = "  unlink                          ";
    237   name[StatInt_fopen]                    = "  fopen                           ";
    238   name[StatInt_freopen]                  = "  freopen                         ";
    239   name[StatInt_fclose]                   = "  fclose                          ";
    240   name[StatInt_fread]                    = "  fread                           ";
    241   name[StatInt_fwrite]                   = "  fwrite                          ";
    242   name[StatInt_puts]                     = "  puts                            ";
    243   name[StatInt_rmdir]                    = "  rmdir                           ";
    244   name[StatInt_opendir]                  = "  opendir                         ";
    245   name[StatInt_epoll_ctl]                = "  epoll_ctl                       ";
    246   name[StatInt_epoll_wait]               = "  epoll_wait                      ";
    247   name[StatInt_poll]                     = "  poll                            ";
    248   name[StatInt_sigaction]                = "  sigaction                       ";
    249   name[StatInt_sleep]                    = "  sleep                           ";
    250   name[StatInt_usleep]                   = "  usleep                          ";
    251   name[StatInt_nanosleep]                = "  nanosleep                       ";
    252   name[StatInt_gettimeofday]             = "  gettimeofday                    ";
    253   name[StatInt_fork]                     = "  fork                            ";
    254   name[StatInt_vscanf]                   = "  vscanf                          ";
    255   name[StatInt_vsscanf]                  = "  vsscanf                         ";
    256   name[StatInt_vfscanf]                  = "  vfscanf                         ";
    257   name[StatInt_scanf]                    = "  scanf                           ";
    258   name[StatInt_sscanf]                   = "  sscanf                          ";
    259   name[StatInt_fscanf]                   = "  fscanf                          ";
    260   name[StatInt___isoc99_vscanf]          = "  vscanf                          ";
    261   name[StatInt___isoc99_vsscanf]         = "  vsscanf                         ";
    262   name[StatInt___isoc99_vfscanf]         = "  vfscanf                         ";
    263   name[StatInt___isoc99_scanf]           = "  scanf                           ";
    264   name[StatInt___isoc99_sscanf]          = "  sscanf                          ";
    265   name[StatInt___isoc99_fscanf]          = "  fscanf                          ";
    266   name[StatInt_on_exit]                  = "  on_exit                         ";
    267   name[StatInt___cxa_atexit]             = "  __cxa_atexit                    ";
    268   name[StatInt_localtime]                = "  localtime                       ";
    269   name[StatInt_localtime_r]              = "  localtime_r                     ";
    270   name[StatInt_gmtime]                   = "  gmtime                          ";
    271   name[StatInt_gmtime_r]                 = "  gmtime_r                        ";
    272   name[StatInt_ctime]                    = "  ctime                           ";
    273   name[StatInt_ctime_r]                  = "  ctime_r                         ";
    274   name[StatInt_asctime]                  = "  asctime                         ";
    275   name[StatInt_asctime_r]                = "  asctime_r                       ";
    276   name[StatInt_frexp]                    = "  frexp                           ";
    277   name[StatInt_frexpf]                   = "  frexpf                          ";
    278   name[StatInt_frexpl]                   = "  frexpl                          ";
    279 
    280   name[StatAnnotation]                   = "Dynamic annotations               ";
    281   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";
    282   name[StatAnnotateHappensAfter]         = "  HappensAfter                    ";
    283   name[StatAnnotateCondVarSignal]        = "  CondVarSignal                   ";
    284   name[StatAnnotateCondVarSignalAll]     = "  CondVarSignalAll                ";
    285   name[StatAnnotateMutexIsNotPHB]        = "  MutexIsNotPHB                   ";
    286   name[StatAnnotateCondVarWait]          = "  CondVarWait                     ";
    287   name[StatAnnotateRWLockCreate]         = "  RWLockCreate                    ";
    288   name[StatAnnotateRWLockDestroy]        = "  RWLockDestroy                   ";
    289   name[StatAnnotateRWLockAcquired]       = "  RWLockAcquired                  ";
    290   name[StatAnnotateRWLockReleased]       = "  RWLockReleased                  ";
    291   name[StatAnnotateTraceMemory]          = "  TraceMemory                     ";
    292   name[StatAnnotateFlushState]           = "  FlushState                      ";
    293   name[StatAnnotateNewMemory]            = "  NewMemory                       ";
    294   name[StatAnnotateNoOp]                 = "  NoOp                            ";
    295   name[StatAnnotateFlushExpectedRaces]   = "  FlushExpectedRaces              ";
    296   name[StatAnnotateEnableRaceDetection]  = "  EnableRaceDetection             ";
    297   name[StatAnnotateMutexIsUsedAsCondVar] = "  MutexIsUsedAsCondVar            ";
    298   name[StatAnnotatePCQGet]               = "  PCQGet                          ";
    299   name[StatAnnotatePCQPut]               = "  PCQPut                          ";
    300   name[StatAnnotatePCQDestroy]           = "  PCQDestroy                      ";
    301   name[StatAnnotatePCQCreate]            = "  PCQCreate                       ";
    302   name[StatAnnotateExpectRace]           = "  ExpectRace                      ";
    303   name[StatAnnotateBenignRaceSized]      = "  BenignRaceSized                 ";
    304   name[StatAnnotateBenignRace]           = "  BenignRace                      ";
    305   name[StatAnnotateIgnoreReadsBegin]     = "  IgnoreReadsBegin                ";
    306   name[StatAnnotateIgnoreReadsEnd]       = "  IgnoreReadsEnd                  ";
    307   name[StatAnnotateIgnoreWritesBegin]    = "  IgnoreWritesBegin               ";
    308   name[StatAnnotateIgnoreWritesEnd]      = "  IgnoreWritesEnd                 ";
    309   name[StatAnnotatePublishMemoryRange]   = "  PublishMemoryRange              ";
    310   name[StatAnnotateUnpublishMemoryRange] = "  UnpublishMemoryRange            ";
    311   name[StatAnnotateThreadName]           = "  ThreadName                      ";
    312 
    313   name[StatMtxTotal]                     = "Contentionz                       ";
    314   name[StatMtxTrace]                     = "  Trace                           ";
    315   name[StatMtxThreads]                   = "  Threads                         ";
    316   name[StatMtxReport]                    = "  Report                          ";
    317   name[StatMtxSyncVar]                   = "  SyncVar                         ";
    318   name[StatMtxSyncTab]                   = "  SyncTab                         ";
    319   name[StatMtxSlab]                      = "  Slab                            ";
    320   name[StatMtxAtExit]                    = "  Atexit                          ";
    321   name[StatMtxAnnotations]               = "  Annotations                     ";
    322   name[StatMtxMBlock]                    = "  MBlock                          ";
    323   name[StatMtxJavaMBlock]                = "  JavaMBlock                      ";
    324   name[StatMtxFD]                        = "  FD                              ";
    325 
    326   Printf("Statistics:\n");
    327   for (int i = 0; i < StatCnt; i++)
    328     Printf("%s: %zu\n", name[i], (uptr)stat[i]);
    329 }
    330 
    331 }  // namespace __tsan
    332