• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if TSAN_COLLECT_STATS
19 
StatAggregate(u64 * dst,u64 * src)20 void StatAggregate(u64 *dst, u64 *src) {
21   for (int i = 0; i < StatCnt; i++)
22     dst[i] += src[i];
23 }
24 
StatOutput(u64 * stat)25 void StatOutput(u64 *stat) {
26   stat[StatShadowNonZero] = stat[StatShadowProcessed] - stat[StatShadowZero];
27 
28   static const char *name[StatCnt] = {};
29   name[StatMop]                          = "Memory accesses                   ";
30   name[StatMopRead]                      = "  Including reads                 ";
31   name[StatMopWrite]                     = "            writes                ";
32   name[StatMop1]                         = "  Including size 1                ";
33   name[StatMop2]                         = "            size 2                ";
34   name[StatMop4]                         = "            size 4                ";
35   name[StatMop8]                         = "            size 8                ";
36   name[StatMopSame]                      = "  Including same                  ";
37   name[StatMopIgnored]                   = "  Including ignored               ";
38   name[StatMopRange]                     = "  Including range                 ";
39   name[StatMopRodata]                    = "  Including .rodata               ";
40   name[StatMopRangeRodata]               = "  Including .rodata 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[StatClockAcquire]                 = "Clock acquire                     ";
76   name[StatClockAcquireEmpty]            = "  empty clock                     ";
77   name[StatClockAcquireFastRelease]      = "  fast from release-store         ";
78   name[StatClockAcquireLarge]            = "  contains my tid                 ";
79   name[StatClockAcquireRepeat]           = "  repeated (fast)                 ";
80   name[StatClockAcquireFull]             = "  full (slow)                     ";
81   name[StatClockAcquiredSomething]       = "  acquired something              ";
82   name[StatClockRelease]                 = "Clock release                     ";
83   name[StatClockReleaseResize]           = "  resize                          ";
84   name[StatClockReleaseFast1]            = "  fast1                           ";
85   name[StatClockReleaseFast2]            = "  fast2                           ";
86   name[StatClockReleaseSlow]             = "  dirty overflow (slow)           ";
87   name[StatClockReleaseFull]             = "  full (slow)                     ";
88   name[StatClockReleaseAcquired]         = "  was acquired                    ";
89   name[StatClockReleaseClearTail]        = "  clear tail                      ";
90   name[StatClockStore]                   = "Clock release store               ";
91   name[StatClockStoreResize]             = "  resize                          ";
92   name[StatClockStoreFast]               = "  fast                            ";
93   name[StatClockStoreFull]               = "  slow                            ";
94   name[StatClockStoreTail]               = "  clear tail                      ";
95   name[StatClockAcquireRelease]          = "Clock acquire-release             ";
96 
97   name[StatAtomic]                       = "Atomic operations                 ";
98   name[StatAtomicLoad]                   = "  Including load                  ";
99   name[StatAtomicStore]                  = "            store                 ";
100   name[StatAtomicExchange]               = "            exchange              ";
101   name[StatAtomicFetchAdd]               = "            fetch_add             ";
102   name[StatAtomicFetchSub]               = "            fetch_sub             ";
103   name[StatAtomicFetchAnd]               = "            fetch_and             ";
104   name[StatAtomicFetchOr]                = "            fetch_or              ";
105   name[StatAtomicFetchXor]               = "            fetch_xor             ";
106   name[StatAtomicFetchNand]              = "            fetch_nand            ";
107   name[StatAtomicCAS]                    = "            compare_exchange      ";
108   name[StatAtomicFence]                  = "            fence                 ";
109   name[StatAtomicRelaxed]                = "  Including relaxed               ";
110   name[StatAtomicConsume]                = "            consume               ";
111   name[StatAtomicAcquire]                = "            acquire               ";
112   name[StatAtomicRelease]                = "            release               ";
113   name[StatAtomicAcq_Rel]                = "            acq_rel               ";
114   name[StatAtomicSeq_Cst]                = "            seq_cst               ";
115   name[StatAtomic1]                      = "  Including size 1                ";
116   name[StatAtomic2]                      = "            size 2                ";
117   name[StatAtomic4]                      = "            size 4                ";
118   name[StatAtomic8]                      = "            size 8                ";
119   name[StatAtomic16]                     = "            size 16               ";
120 
121   name[StatAnnotation]                   = "Dynamic annotations               ";
122   name[StatAnnotateHappensBefore]        = "  HappensBefore                   ";
123   name[StatAnnotateHappensAfter]         = "  HappensAfter                    ";
124   name[StatAnnotateCondVarSignal]        = "  CondVarSignal                   ";
125   name[StatAnnotateCondVarSignalAll]     = "  CondVarSignalAll                ";
126   name[StatAnnotateMutexIsNotPHB]        = "  MutexIsNotPHB                   ";
127   name[StatAnnotateCondVarWait]          = "  CondVarWait                     ";
128   name[StatAnnotateRWLockCreate]         = "  RWLockCreate                    ";
129   name[StatAnnotateRWLockCreateStatic]   = "  StatAnnotateRWLockCreateStatic  ";
130   name[StatAnnotateRWLockDestroy]        = "  RWLockDestroy                   ";
131   name[StatAnnotateRWLockAcquired]       = "  RWLockAcquired                  ";
132   name[StatAnnotateRWLockReleased]       = "  RWLockReleased                  ";
133   name[StatAnnotateTraceMemory]          = "  TraceMemory                     ";
134   name[StatAnnotateFlushState]           = "  FlushState                      ";
135   name[StatAnnotateNewMemory]            = "  NewMemory                       ";
136   name[StatAnnotateNoOp]                 = "  NoOp                            ";
137   name[StatAnnotateFlushExpectedRaces]   = "  FlushExpectedRaces              ";
138   name[StatAnnotateEnableRaceDetection]  = "  EnableRaceDetection             ";
139   name[StatAnnotateMutexIsUsedAsCondVar] = "  MutexIsUsedAsCondVar            ";
140   name[StatAnnotatePCQGet]               = "  PCQGet                          ";
141   name[StatAnnotatePCQPut]               = "  PCQPut                          ";
142   name[StatAnnotatePCQDestroy]           = "  PCQDestroy                      ";
143   name[StatAnnotatePCQCreate]            = "  PCQCreate                       ";
144   name[StatAnnotateExpectRace]           = "  ExpectRace                      ";
145   name[StatAnnotateBenignRaceSized]      = "  BenignRaceSized                 ";
146   name[StatAnnotateBenignRace]           = "  BenignRace                      ";
147   name[StatAnnotateIgnoreReadsBegin]     = "  IgnoreReadsBegin                ";
148   name[StatAnnotateIgnoreReadsEnd]       = "  IgnoreReadsEnd                  ";
149   name[StatAnnotateIgnoreWritesBegin]    = "  IgnoreWritesBegin               ";
150   name[StatAnnotateIgnoreWritesEnd]      = "  IgnoreWritesEnd                 ";
151   name[StatAnnotateIgnoreSyncBegin]      = "  IgnoreSyncBegin                 ";
152   name[StatAnnotateIgnoreSyncEnd]        = "  IgnoreSyncEnd                   ";
153   name[StatAnnotatePublishMemoryRange]   = "  PublishMemoryRange              ";
154   name[StatAnnotateUnpublishMemoryRange] = "  UnpublishMemoryRange            ";
155   name[StatAnnotateThreadName]           = "  ThreadName                      ";
156 
157   name[StatMtxTotal]                     = "Contentionz                       ";
158   name[StatMtxTrace]                     = "  Trace                           ";
159   name[StatMtxThreads]                   = "  Threads                         ";
160   name[StatMtxReport]                    = "  Report                          ";
161   name[StatMtxSyncVar]                   = "  SyncVar                         ";
162   name[StatMtxSyncTab]                   = "  SyncTab                         ";
163   name[StatMtxSlab]                      = "  Slab                            ";
164   name[StatMtxAtExit]                    = "  Atexit                          ";
165   name[StatMtxAnnotations]               = "  Annotations                     ";
166   name[StatMtxMBlock]                    = "  MBlock                          ";
167   name[StatMtxDeadlockDetector]          = "  DeadlockDetector                ";
168   name[StatMtxFired]                     = "  FiredSuppressions               ";
169   name[StatMtxRacy]                      = "  RacyStacks                      ";
170   name[StatMtxFD]                        = "  FD                              ";
171   name[StatMtxGlobalProc]                = "  GlobalProc                      ";
172 
173   Printf("Statistics:\n");
174   for (int i = 0; i < StatCnt; i++)
175     Printf("%s: %16zu\n", name[i], (uptr)stat[i]);
176 }
177 
178 #endif
179 
180 }  // namespace __tsan
181