1 //===-- tsan_stat.cc ------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
12 //===----------------------------------------------------------------------===//
13 #include "tsan_stat.h"
18 #if TSAN_COLLECT_STATS
20 void StatAggregate(u64 *dst, u64 *src) {
21 for (int i = 0; i < StatCnt; i++)
25 void StatOutput(u64 *stat) {
26 stat[StatShadowNonZero] = stat[StatShadowProcessed] - stat[StatShadowZero];
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 ";
51 name[StatFuncEnter] = "Function entries ";
52 name[StatFuncExit] = "Function exits ";
53 name[StatEvents] = "Events collected ";
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 ";
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 ";
70 name[StatSyncCreated] = "Sync objects created ";
71 name[StatSyncDestroyed] = " destroyed ";
72 name[StatSyncAcquire] = " acquired ";
73 name[StatSyncRelease] = " released ";
75 name[StatClockAcquire] = "Clock acquire ";
76 name[StatClockAcquireEmpty] = " empty clock ";
77 name[StatClockAcquireFastRelease] = " fast from release-store ";
78 name[StatClockAcquireFull] = " full (slow) ";
79 name[StatClockAcquiredSomething] = " acquired something ";
80 name[StatClockRelease] = "Clock release ";
81 name[StatClockReleaseResize] = " resize ";
82 name[StatClockReleaseFast] = " fast ";
83 name[StatClockReleaseSlow] = " dirty overflow (slow) ";
84 name[StatClockReleaseFull] = " full (slow) ";
85 name[StatClockReleaseAcquired] = " was acquired ";
86 name[StatClockReleaseClearTail] = " clear tail ";
87 name[StatClockStore] = "Clock release store ";
88 name[StatClockStoreResize] = " resize ";
89 name[StatClockStoreFast] = " fast ";
90 name[StatClockStoreFull] = " slow ";
91 name[StatClockStoreTail] = " clear tail ";
92 name[StatClockAcquireRelease] = "Clock acquire-release ";
94 name[StatAtomic] = "Atomic operations ";
95 name[StatAtomicLoad] = " Including load ";
96 name[StatAtomicStore] = " store ";
97 name[StatAtomicExchange] = " exchange ";
98 name[StatAtomicFetchAdd] = " fetch_add ";
99 name[StatAtomicFetchSub] = " fetch_sub ";
100 name[StatAtomicFetchAnd] = " fetch_and ";
101 name[StatAtomicFetchOr] = " fetch_or ";
102 name[StatAtomicFetchXor] = " fetch_xor ";
103 name[StatAtomicFetchNand] = " fetch_nand ";
104 name[StatAtomicCAS] = " compare_exchange ";
105 name[StatAtomicFence] = " fence ";
106 name[StatAtomicRelaxed] = " Including relaxed ";
107 name[StatAtomicConsume] = " consume ";
108 name[StatAtomicAcquire] = " acquire ";
109 name[StatAtomicRelease] = " release ";
110 name[StatAtomicAcq_Rel] = " acq_rel ";
111 name[StatAtomicSeq_Cst] = " seq_cst ";
112 name[StatAtomic1] = " Including size 1 ";
113 name[StatAtomic2] = " size 2 ";
114 name[StatAtomic4] = " size 4 ";
115 name[StatAtomic8] = " size 8 ";
116 name[StatAtomic16] = " size 16 ";
118 name[StatAnnotation] = "Dynamic annotations ";
119 name[StatAnnotateHappensBefore] = " HappensBefore ";
120 name[StatAnnotateHappensAfter] = " HappensAfter ";
121 name[StatAnnotateCondVarSignal] = " CondVarSignal ";
122 name[StatAnnotateCondVarSignalAll] = " CondVarSignalAll ";
123 name[StatAnnotateMutexIsNotPHB] = " MutexIsNotPHB ";
124 name[StatAnnotateCondVarWait] = " CondVarWait ";
125 name[StatAnnotateRWLockCreate] = " RWLockCreate ";
126 name[StatAnnotateRWLockCreateStatic] = " StatAnnotateRWLockCreateStatic ";
127 name[StatAnnotateRWLockDestroy] = " RWLockDestroy ";
128 name[StatAnnotateRWLockAcquired] = " RWLockAcquired ";
129 name[StatAnnotateRWLockReleased] = " RWLockReleased ";
130 name[StatAnnotateTraceMemory] = " TraceMemory ";
131 name[StatAnnotateFlushState] = " FlushState ";
132 name[StatAnnotateNewMemory] = " NewMemory ";
133 name[StatAnnotateNoOp] = " NoOp ";
134 name[StatAnnotateFlushExpectedRaces] = " FlushExpectedRaces ";
135 name[StatAnnotateEnableRaceDetection] = " EnableRaceDetection ";
136 name[StatAnnotateMutexIsUsedAsCondVar] = " MutexIsUsedAsCondVar ";
137 name[StatAnnotatePCQGet] = " PCQGet ";
138 name[StatAnnotatePCQPut] = " PCQPut ";
139 name[StatAnnotatePCQDestroy] = " PCQDestroy ";
140 name[StatAnnotatePCQCreate] = " PCQCreate ";
141 name[StatAnnotateExpectRace] = " ExpectRace ";
142 name[StatAnnotateBenignRaceSized] = " BenignRaceSized ";
143 name[StatAnnotateBenignRace] = " BenignRace ";
144 name[StatAnnotateIgnoreReadsBegin] = " IgnoreReadsBegin ";
145 name[StatAnnotateIgnoreReadsEnd] = " IgnoreReadsEnd ";
146 name[StatAnnotateIgnoreWritesBegin] = " IgnoreWritesBegin ";
147 name[StatAnnotateIgnoreWritesEnd] = " IgnoreWritesEnd ";
148 name[StatAnnotateIgnoreSyncBegin] = " IgnoreSyncBegin ";
149 name[StatAnnotateIgnoreSyncEnd] = " IgnoreSyncEnd ";
150 name[StatAnnotatePublishMemoryRange] = " PublishMemoryRange ";
151 name[StatAnnotateUnpublishMemoryRange] = " UnpublishMemoryRange ";
152 name[StatAnnotateThreadName] = " ThreadName ";
153 name[Stat__tsan_mutex_create] = " __tsan_mutex_create ";
154 name[Stat__tsan_mutex_destroy] = " __tsan_mutex_destroy ";
155 name[Stat__tsan_mutex_pre_lock] = " __tsan_mutex_pre_lock ";
156 name[Stat__tsan_mutex_post_lock] = " __tsan_mutex_post_lock ";
157 name[Stat__tsan_mutex_pre_unlock] = " __tsan_mutex_pre_unlock ";
158 name[Stat__tsan_mutex_post_unlock] = " __tsan_mutex_post_unlock ";
159 name[Stat__tsan_mutex_pre_signal] = " __tsan_mutex_pre_signal ";
160 name[Stat__tsan_mutex_post_signal] = " __tsan_mutex_post_signal ";
161 name[Stat__tsan_mutex_pre_divert] = " __tsan_mutex_pre_divert ";
162 name[Stat__tsan_mutex_post_divert] = " __tsan_mutex_post_divert ";
164 name[StatMtxTotal] = "Contentionz ";
165 name[StatMtxTrace] = " Trace ";
166 name[StatMtxThreads] = " Threads ";
167 name[StatMtxReport] = " Report ";
168 name[StatMtxSyncVar] = " SyncVar ";
169 name[StatMtxSyncTab] = " SyncTab ";
170 name[StatMtxSlab] = " Slab ";
171 name[StatMtxAtExit] = " Atexit ";
172 name[StatMtxAnnotations] = " Annotations ";
173 name[StatMtxMBlock] = " MBlock ";
174 name[StatMtxDeadlockDetector] = " DeadlockDetector ";
175 name[StatMtxFired] = " FiredSuppressions ";
176 name[StatMtxRacy] = " RacyStacks ";
177 name[StatMtxFD] = " FD ";
178 name[StatMtxGlobalProc] = " GlobalProc ";
180 Printf("Statistics:\n");
181 for (int i = 0; i < StatCnt; i++)
182 Printf("%s: %16zu\n", name[i], (uptr)stat[i]);
187 } // namespace __tsan