}
// Construct an event manager and associate a handler with it.
- HANDLE CreateThreadContext()
+ HANDLE CreateThreadContext(AR_THREAD type)
{
// Can we assume single threaded here?
static std::atomic<uint32_t> counter(0);
uint32_t id = counter.fetch_add(1);
EventManager* pManager = new EventManager();
- EventHandler* pHandler = new EventHandlerStatsFile(id);
+ EventHandlerFile* pHandler = new EventHandlerStatsFile(id);
if (pManager && pHandler)
{
pManager->Attach(pHandler);
+ if (type == AR_THREAD::API)
+ {
+ ThreadStartApiEvent e;
+ pManager->Dispatch(e);
+ }
+ else
+ {
+ ThreadStartWorkerEvent e;
+ pManager->Dispatch(e);
+ }
+ pHandler->MarkHeader();
+
return pManager;
}
namespace ArchRast
{
- HANDLE CreateThreadContext();
+ enum class AR_THREAD
+ {
+ API = 0,
+ WORKER = 1
+ };
+
+ HANDLE CreateThreadContext(AR_THREAD type);
void DestroyThreadContext(HANDLE hThreadContext);
// Dispatch event for this thread.
#if defined(KNOB_ENABLE_AR)
// Setup ArchRast thread contexts which includes +1 for API thread.
pContext->pArContext = new HANDLE[pContext->NumWorkerThreads+1];
- pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext();
- _AR_EVENT(pContext->pArContext[pContext->NumWorkerThreads], ThreadStartApiEvent());
+ pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::API);
#endif
// Allocate scratch space for workers.
#if defined(KNOB_ENABLE_AR)
// Initialize worker thread context for ArchRast.
- pContext->pArContext[i] = ArchRast::CreateThreadContext();
- _AR_EVENT(pContext->pArContext[i], ThreadStartWorkerEvent());
+ pContext->pArContext[i] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::WORKER);
#endif
}
{
if (mBufOffset > 0)
{
+ if (mBufOffset == mHeaderBufOffset)
+ {
+ // Nothing to flush. Only header has been generated.
+ return false;
+ }
+
std::ofstream file;
file.open(mFilename, std::ios::out | std::ios::app | std::ios::binary);
file.close();
mBufOffset = 0;
+ mHeaderBufOffset = 0; // Reset header offset so its no longer considered.
}
return true;
}
% for name in protos['event_names']:
//////////////////////////////////////////////////////////////////////////
/// @brief Handle ${name} event
- virtual void Handle(${name}& event)
+ virtual void Handle(${name}&& event)
{
% if protos['events'][name]['num_fields'] == 0:
Write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
}
% endfor
+ //////////////////////////////////////////////////////////////////////////
+ /// @brief Everything written to buffer this point is the header.
+ virtual void MarkHeader()
+ {
+ mHeaderBufOffset = mBufOffset;
+ }
+
std::string mFilename;
static const uint32_t mBufferSize = 1024;
uint8_t mBuffer[mBufferSize];
uint32_t mBufOffset{0};
+ uint32_t mHeaderBufOffset{0};
};
}