#include #include #include #include "capture-manager.h" namespace SlangCapture { CaptureManager::CaptureManager(uint64_t globalSessionHandle) : m_encoder(&m_memoryStream) { std::stringstream ss; ss << "gs-"<< globalSessionHandle <<"t-"<(ss.str()); } void CaptureManager::clearWithHeader(const ApiCallId& callId, uint64_t handleId) { m_memoryStream.flush(); FunctionHeader header {}; header.callId = callId; header.handleId = handleId; // write header to memory stream m_memoryStream.write(&header, sizeof(FunctionHeader)); } ParameterEncoder* CaptureManager::beginMethodCapture(const ApiCallId& callId, uint64_t handleId) { clearWithHeader(callId, handleId); return &m_encoder; } void CaptureManager::endMethodCapture() { FunctionHeader* pHeader = const_cast( reinterpret_cast(m_memoryStream.getData())); pHeader->dataSizeInBytes = m_memoryStream.getSizeInBytes() - sizeof(FunctionHeader); std::hash hasher; pHeader->threadId = hasher(std::this_thread::get_id()); // write capture data to file m_fileStream->write(m_memoryStream.getData(), m_memoryStream.getSizeInBytes()); // take effect of the write m_fileStream->flush(); // clear the memory stream m_memoryStream.flush(); } }