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