tsan: use StackDepot in sync object to store creation stacks

llvm-svn: 177258
This commit is contained in:
Dmitry Vyukov 2013-03-18 08:27:47 +00:00
parent 3e7005f1c1
commit a221620b2e
4 changed files with 11 additions and 34 deletions

View File

@ -95,23 +95,14 @@ ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
}
static void WriteMemoryProfile(char *buf, uptr buf_size, int num) {
uptr shadow = GetShadowMemoryConsumption();
uptr n_threads;
uptr n_running_threads;
ctx->thread_registry->GetNumberOfThreads(&n_threads, &n_running_threads);
uptr threadmem = n_threads * sizeof(ThreadContext) +
n_running_threads * sizeof(ThreadState);
uptr nsync = 0;
uptr syncmem = CTX()->synctab.GetMemoryConsumption(&nsync);
internal_snprintf(buf, buf_size, "%d: shadow=%zuMB"
" thread=%zuMB(total=%d/live=%d)"
" sync=%zuMB(cnt=%zu)\n",
num,
shadow >> 20,
threadmem >> 20, n_threads, n_running_threads,
syncmem >> 20, nsync);
internal_snprintf(buf, buf_size, "%d: thread=%zuMB(total=%d/live=%d)\n",
num, threadmem >> 20, n_threads, n_running_threads);
}
static void MemoryProfileThread(void *arg) {

View File

@ -241,7 +241,13 @@ void ScopedReport::AddMutex(const SyncVar *s) {
rep_->mutexes.PushBack(rm);
rm->id = s->uid;
rm->destroyed = false;
rm->stack = SymbolizeStack(s->creation_stack);
uptr ssz = 0;
const uptr *stack = StackDepotGet(s->creation_stack_id, &ssz);
if (stack) {
StackTrace trace;
trace.Init(stack, ssz);
rm->stack = SymbolizeStack(trace);
}
}
void ScopedReport::AddMutex(u64 id) {

View File

@ -63,7 +63,7 @@ SyncVar* SyncTab::Create(ThreadState *thr, uptr pc, uptr addr) {
const u64 uid = atomic_fetch_add(&uid_gen_, 1, memory_order_relaxed);
SyncVar *res = new(mem) SyncVar(addr, uid);
#ifndef TSAN_GO
res->creation_stack.ObtainCurrent(thr, pc);
res->creation_stack_id = CurrentStackId(thr, pc);
#endif
return res;
}
@ -197,26 +197,6 @@ SyncVar* SyncTab::GetAndRemove(ThreadState *thr, uptr pc, uptr addr) {
return res;
}
uptr SyncVar::GetMemoryConsumption() {
return sizeof(*this)
+ clock.size() * sizeof(u64)
+ read_clock.size() * sizeof(u64)
+ creation_stack.Size() * sizeof(uptr);
}
uptr SyncTab::GetMemoryConsumption(uptr *nsync) {
uptr mem = 0;
for (int i = 0; i < kPartCount; i++) {
Part *p = &tab_[i];
Lock l(&p->mtx);
for (SyncVar *s = p->val; s; s = s->next) {
*nsync += 1;
mem += s->GetMemoryConsumption();
}
}
return mem;
}
int SyncTab::PartIdx(uptr addr) {
return (addr >> 3) % kPartCount;
}

View File

@ -59,7 +59,7 @@ struct SyncVar {
const u64 uid; // Globally unique id.
SyncClock clock;
SyncClock read_clock; // Used for rw mutexes only.
StackTrace creation_stack;
u32 creation_stack_id;
int owner_tid; // Set only by exclusive owners.
u64 last_lock;
int recursion;