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[StatMopIgnored]                   = "  Including ignored               ";
     41   name[StatMopRange]                     = "  Including range                 ";
     42   name[StatMopRodata]                    = "  Including .rodata               ";
     43   name[StatMopRangeRodata]               = "  Including .rodata range         ";
     44   name[StatShadowProcessed]              = "Shadow processed                  ";
     45   name[StatShadowZero]                   = "  Including empty                 ";
     46   name[StatShadowNonZero]                = "  Including non empty             ";
     47   name[StatShadowSameSize]               = "  Including same size             ";
     48   name[StatShadowIntersect]              = "            intersect             ";
     49   name[StatShadowNotIntersect]           = "            not intersect         ";
     50   name[StatShadowSameThread]             = "  Including same thread           ";
     51   name[StatShadowAnotherThread]          = "            another thread        ";
     52   name[StatShadowReplace]                = "  Including evicted               ";
     53 
     54   name[StatFuncEnter]                    = "Function entries                  ";
     55   name[StatFuncExit]                     = "Function exits                    ";
     56   name[StatEvents]                       = "Events collected                  ";
     57 
     58   name[StatThreadCreate]                 = "Total threads created             ";
     59   name[StatThreadFinish]                 = "  threads finished                ";
     60   name[StatThreadReuse]                  = "  threads reused                  ";
     61   name[StatThreadMaxTid]                 = "  max tid                         ";
     62   name[StatThreadMaxAlive]               = "  max alive threads               ";
     63 
     64   name[StatMutexCreate]                  = "Mutexes created                   ";
     65   name[StatMutexDestroy]                 = "  destroyed                       ";
     66   name[StatMutexLock]                    = "  lock                            ";
     67   name[StatMutexUnlock]                  = "  unlock                          ";
     68   name[StatMutexRecLock]                 = "  recursive lock                  ";
     69   name[StatMutexRecUnlock]               = "  recursive unlock                ";
     70   name[StatMutexReadLock]                = "  read lock                       ";
     71   name[StatMutexReadUnlock]              = "  read unlock                     ";
     72 
     73   name[StatSyncCreated]                  = "Sync objects created              ";
     74   name[StatSyncDestroyed]                = "             destroyed            ";
     75   name[StatSyncAcquire]                  = "             acquired             ";
     76   name[StatSyncRelease]                  = "             released             ";
     77 
     78   name[StatClockAcquire]                 = "Clock acquire                     ";
     79   name[StatClockAcquireEmpty]            = "  empty clock                     ";
     80   name[StatClockAcquireFastRelease]      = "  fast from release-store         ";
     81   name[StatClockAcquireLarge]            = "  contains my tid                 ";
     82   name[StatClockAcquireRepeat]           = "  repeated (fast)                 ";
     83   name[StatClockAcquireFull]             = "  full (slow)                     ";
     84   name[StatClockAcquiredSomething]       = "  acquired something              ";
     85   name[StatClockRelease]                 = "Clock release                     ";
     86   name[StatClockReleaseResize]           = "  resize                          ";
     87   name[StatClockReleaseFast1]            = "  fast1                           ";
     88   name[StatClockReleaseFast2]            = "  fast2                           ";
     89   name[StatClockReleaseSlow]             = "  dirty overflow (slow)           ";
     90   name[StatClockReleaseFull]             = "  full (slow)                     ";
     91   name[StatClockReleaseAcquired]         = "  was acquired                    ";
     92   name[StatClockReleaseClearTail]        = "  clear tail                      ";
     93   name[StatClockStore]                   = "Clock release store               ";
     94   name[StatClockStoreResize]             = "  resize                          ";
     95   name[StatClockStoreFast]               = "  fast                            ";
     96   name[StatClockStoreFull]               = "  slow                            ";
     97   name[StatClockStoreTail]               = "  clear tail                      ";
     98   name[StatClockAcquireRelease]          = "Clock acquire-release             ";
     99 
    100   name[StatAtomic]                       = "Atomic operations                 ";
    101   name[StatAtomicLoad]                   = "  Including load                  ";
    102   name[StatAtomicStore]                  = "            store                 ";
    103   name[StatAtomicExchange]               = "            exchange              ";
    104   name[StatAtomicFetchAdd]               = "            fetch_add             ";
    105   name[StatAtomicFetchSub]               = "            fetch_sub             ";
    106   name[StatAtomicFetchAnd]               = "            fetch_and             ";
    107   name[StatAtomicFetchOr]                = "            fetch_or              ";
    108   name[StatAtomicFetchXor]               = "            fetch_xor             ";
    109   name[StatAtomicFetchNand]              = "            fetch_nand            ";
    110   name[StatAtomicCAS]                    = "            compare_exchange      ";
    111   name[StatAtomicFence]                  = "            fence                 ";
    112   name[StatAtomicRelaxed]                = "  Including relaxed               ";
    113   name[StatAtomicConsume]                = "            consume               ";
    114   name[StatAtomicAcquire]                = "            acquire               ";
    115   name[StatAtomicRelease]                = "            release               ";
    116   name[StatAtomicAcq_Rel]                = "            acq_rel               ";
    117   name[StatAtomicSeq_Cst]                = "            seq_cst               ";
    118   name[StatAtomic1]                      = "  Including size 1                ";
    119   name[StatAtomic2]                      = "            size 2                ";
    120   name[StatAtomic4]                      = "            size 4                ";
    121   name[StatAtomic8]                      = "            size 8                ";
    122   name[StatAtomic16]                     = "            size 16               ";
    123 
    124   name[StatAnnotation]                   = "Dynamic annotations               ";
    125   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";
    126   name[StatAnnotateHappensAfter]         = "  HappensAfter                    ";
    127   name[StatAnnotateCondVarSignal]        = "  CondVarSignal                   ";
    128   name[StatAnnotateCondVarSignalAll]     = "  CondVarSignalAll                ";
    129   name[StatAnnotateMutexIsNotPHB]        = "  MutexIsNotPHB                   ";
    130   name[StatAnnotateCondVarWait]          = "  CondVarWait                     ";
    131   name[StatAnnotateRWLockCreate]         = "  RWLockCreate                    ";
    132   name[StatAnnotateRWLockCreateStatic]   = "  StatAnnotateRWLockCreateStatic  ";
    133   name[StatAnnotateRWLockDestroy]        = "  RWLockDestroy                   ";
    134   name[StatAnnotateRWLockAcquired]       = "  RWLockAcquired                  ";
    135   name[StatAnnotateRWLockReleased]       = "  RWLockReleased                  ";
    136   name[StatAnnotateTraceMemory]          = "  TraceMemory                     ";
    137   name[StatAnnotateFlushState]           = "  FlushState                      ";
    138   name[StatAnnotateNewMemory]            = "  NewMemory                       ";
    139   name[StatAnnotateNoOp]                 = "  NoOp                            ";
    140   name[StatAnnotateFlushExpectedRaces]   = "  FlushExpectedRaces              ";
    141   name[StatAnnotateEnableRaceDetection]  = "  EnableRaceDetection             ";
    142   name[StatAnnotateMutexIsUsedAsCondVar] = "  MutexIsUsedAsCondVar            ";
    143   name[StatAnnotatePCQGet]               = "  PCQGet                          ";
    144   name[StatAnnotatePCQPut]               = "  PCQPut                          ";
    145   name[StatAnnotatePCQDestroy]           = "  PCQDestroy                      ";
    146   name[StatAnnotatePCQCreate]            = "  PCQCreate                       ";
    147   name[StatAnnotateExpectRace]           = "  ExpectRace                      ";
    148   name[StatAnnotateBenignRaceSized]      = "  BenignRaceSized                 ";
    149   name[StatAnnotateBenignRace]           = "  BenignRace                      ";
    150   name[StatAnnotateIgnoreReadsBegin]     = "  IgnoreReadsBegin                ";
    151   name[StatAnnotateIgnoreReadsEnd]       = "  IgnoreReadsEnd                  ";
    152   name[StatAnnotateIgnoreWritesBegin]    = "  IgnoreWritesBegin               ";
    153   name[StatAnnotateIgnoreWritesEnd]      = "  IgnoreWritesEnd                 ";
    154   name[StatAnnotateIgnoreSyncBegin]      = "  IgnoreSyncBegin                 ";
    155   name[StatAnnotateIgnoreSyncEnd]        = "  IgnoreSyncEnd                   ";
    156   name[StatAnnotatePublishMemoryRange]   = "  PublishMemoryRange              ";
    157   name[StatAnnotateUnpublishMemoryRange] = "  UnpublishMemoryRange            ";
    158   name[StatAnnotateThreadName]           = "  ThreadName                      ";
    159 
    160   name[StatMtxTotal]                     = "Contentionz                       ";
    161   name[StatMtxTrace]                     = "  Trace                           ";
    162   name[StatMtxThreads]                   = "  Threads                         ";
    163   name[StatMtxReport]                    = "  Report                          ";
    164   name[StatMtxSyncVar]                   = "  SyncVar                         ";
    165   name[StatMtxSyncTab]                   = "  SyncTab                         ";
    166   name[StatMtxSlab]                      = "  Slab                            ";
    167   name[StatMtxAtExit]                    = "  Atexit                          ";
    168   name[StatMtxAnnotations]               = "  Annotations                     ";
    169   name[StatMtxMBlock]                    = "  MBlock                          ";
    170   name[StatMtxJavaMBlock]                = "  JavaMBlock                      ";
    171   name[StatMtxDeadlockDetector]          = "  DeadlockDetector                ";
    172   name[StatMtxFD]                        = "  FD                              ";
    173 
    174   Printf("Statistics:\n");
    175   for (int i = 0; i < StatCnt; i++)
    176     Printf("%s: %16zu\n", name[i], (uptr)stat[i]);
    177 }
    178 
    179 }  // namespace __tsan
    180