From f0d40ad5e1d0a0dec39fe8a141d3f81d88fc576a Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:02:12 -0700 Subject: capture/replay: implement infrastructure for capture (#4372) * Define api call ID for each being captured methods * Add parameter encoder interface * Add outputStream and capture manager Add infrastructure for output stream This is the interface to record the method and parameter, and also provide functionality to write all the serialized data into file. Add capture manager: Capture manager is associated to global session object, it will provide the functionality to actual record all the APIs. Implement some of parameter encoder functions. * Fix some Windows & cmake build error * remove unused headers --- source/slang-capture-replay/capture-manager.cpp | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 source/slang-capture-replay/capture-manager.cpp (limited to 'source/slang-capture-replay/capture-manager.cpp') diff --git a/source/slang-capture-replay/capture-manager.cpp b/source/slang-capture-replay/capture-manager.cpp new file mode 100644 index 000000000..be5615e00 --- /dev/null +++ b/source/slang-capture-replay/capture-manager.cpp @@ -0,0 +1,53 @@ + +#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(); + } +} -- cgit v1.2.3