THREAD UINT tlsThreadId = 0;
+BucketManager::~BucketManager()
+{
+}
+
void BucketManager::RegisterThread(const std::string& name)
{
// lazy evaluate threadviz knob
mThreadVizDir = str.str();
CreateDirectory(mThreadVizDir.c_str(), NULL);
- mThreadViz = true;
+ mThreadViz = KNOB_BUCKETS_ENABLE_THREADVIZ;
}
BUCKET_THREAD newThread;
PrintThread(f, thread);
fprintf(f, "\n");
}
+
mThreadMutex.unlock();
fclose(f);
}
}
+
+void BucketManager::StartCapture()
+{
+
+ printf("Capture Starting\n");
+
+ mCapturing = true;
+}
+
void BucketManager_StartBucket(BucketManager* pBucketMgr, uint32_t id)
{
pBucketMgr->StartBucket(id);
#include "rdtsc_buckets_shared.h"
+
// unique thread id stored in thread local storage
extern THREAD UINT tlsThreadId;
{
public:
BucketManager() { }
+ ~BucketManager();
// removes all registered thread data
void ClearThreads()
// print report
void PrintReport(const std::string& filename);
+
// start capturing
- INLINE void StartCapture()
- {
- mCapturing = true;
- }
+ void StartCapture();
// stop capturing
INLINE void StopCapture()
}
}
}
+
+ mDoneCapturing = true;
+ printf("Capture Stopped\n");
}
// start a bucket
BUCKET_THREAD& bt = mThreads[tlsThreadId];
+ uint64_t tsc = __rdtsc();
+
// if threadviz is enabled, only need to dump start info to threads viz file
if (mThreadViz)
{
SWR_ASSERT(bt.vizFile != nullptr);
if (mBuckets[id].enableThreadViz)
{
- VIZ_START_DATA data{ VIZ_START, id, __rdtsc() };
+ VIZ_START_DATA data{ VIZ_START, id, tsc };
Serialize(bt.vizFile, data);
}
}
BUCKET &child = bt.pCurrent->children[id];
child.pParent = bt.pCurrent;
child.id = id;
- child.start = __rdtsc();
+ child.start = tsc;
// update thread's currently executing bucket
bt.pCurrent = &child;
}
+
bt.level++;
}
SWR_ASSERT(tlsThreadId < mThreads.size());
BUCKET_THREAD &bt = mThreads[tlsThreadId];
- if (bt.level == 0) return;
+ if (bt.level == 0)
+ {
+ return;
+ }
+
+ uint64_t tsc = __rdtsc();
if (mThreadViz)
{
SWR_ASSERT(bt.vizFile != nullptr);
if (mBuckets[id].enableThreadViz)
{
- VIZ_STOP_DATA data{ VIZ_STOP, __rdtsc() };
+ VIZ_STOP_DATA data{ VIZ_STOP, tsc };
Serialize(bt.vizFile, data);
}
}
if (bt.pCurrent->start == 0) return;
SWR_ASSERT(bt.pCurrent->id == id, "Mismatched buckets detected");
- bt.pCurrent->elapsed += (__rdtsc() - bt.pCurrent->start);
+ bt.pCurrent->elapsed += (tsc - bt.pCurrent->start);
bt.pCurrent->count++;
// pop to parent
// is capturing currently enabled
volatile bool mCapturing{ false };
+ // has capturing completed
+ volatile bool mDoneCapturing{ false };
+
std::mutex mThreadMutex;
// enable threadviz
bool mThreadViz{ false };
std::string mThreadVizDir;
+
};