diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-06-13 13:02:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 13:02:12 -0700 |
| commit | f0d40ad5e1d0a0dec39fe8a141d3f81d88fc576a (patch) | |
| tree | 210a0a9b5bb2aea0e64776527c4ce04266709a43 /source/slang-capture-replay/capture-manager.cpp | |
| parent | ecc6ecb3a25a28eb5e85cfdb2bf170448ab9a4e7 (diff) | |
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
Diffstat (limited to 'source/slang-capture-replay/capture-manager.cpp')
| -rw-r--r-- | source/slang-capture-replay/capture-manager.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
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 <string> +#include <sstream> +#include <thread> +#include "capture-manager.h" + +namespace SlangCapture +{ + CaptureManager::CaptureManager(uint64_t globalSessionHandle) + : m_encoder(&m_memoryStream) + { + std::stringstream ss; + ss << "gs-"<< globalSessionHandle <<"t-"<<std::this_thread::get_id() << ".cap"; + m_fileStream = std::make_unique<FileOutputStream>(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<FunctionHeader*>( + reinterpret_cast<const FunctionHeader*>(m_memoryStream.getData())); + + pHeader->dataSizeInBytes = m_memoryStream.getSizeInBytes() - sizeof(FunctionHeader); + + std::hash<std::thread::id> 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(); + } +} |
