From 986256ffb92ab7c8fc7cf9f2c424919a439a824f Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:45:26 -0500 Subject: Feature/capture (#4625) * Add decoder * Add a replay executable to consume the decoded content Add file-processor.cpp/h where we implement the logic to process the captured file block by block. Each block is: function header + parameter buffer + function tailer + function output[optional]. After reading one block, the block of data is sent to decoder module to dispatch the corresponding API. Add slang-decoder.cpp/h where we implement the logic to dispatch the slang API according to the input block data. - Rename api_callId.h to capture-format.h - Renmae capture_utility.cpp to capture-utility.cpp - Renmae capture_utility.h to capture-utility.h - Change the #include file name accordingly. * Reorganize source files structure Move all the capture logic code into `capture` directory. - the capture code will be build with slang dll. Move all the replay logic code into `relay` directoy. - the replay code is not part of slang dll, it will be built as a stand alone binary and link against slang dll. Change the #include file names accordingly. Add tools/slang-replay/main.cpp for the slang-replay stand alone binary place holder. Will implement it later. Update premake5.lua accordingly. * Update cmake files Update cmake files to change the build process for capture and relay system. - capture component should be build with slang dll, so we should not include replay component. - replay component should be a separate executable tool, which should not include capture component. - In order to easy use our current cmake infrastructure, move the shared files to a `util` folder - change the header include path * Redesgin the interfaces of consumers Fix some issues in capture Finish implementing all slang-decoder functions * Fix the AppleClang build issue * Address few comments - Fix the weird indent issues. - Correct the function name for CreateGlobalSession() - Rename file-processor to captureFile-processor to be more specific. - Use Slang::List instead of std::vector * record/replay: name refactor change Refactor the naming. Change the name "encoder/capture" to "record". --- .../slang-record-replay/record/record-manager.cpp | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 source/slang-record-replay/record/record-manager.cpp (limited to 'source/slang-record-replay/record/record-manager.cpp') diff --git a/source/slang-record-replay/record/record-manager.cpp b/source/slang-record-replay/record/record-manager.cpp new file mode 100644 index 000000000..f10d2c704 --- /dev/null +++ b/source/slang-record-replay/record/record-manager.cpp @@ -0,0 +1,97 @@ + +#include +#include +#include +#include "../util/record-utility.h" +#include "record-manager.h" + +namespace SlangRecord +{ + RecordManager::RecordManager(uint64_t globalSessionHandle) + : m_recorder(&m_memoryStream) + { + std::stringstream ss; + ss << "gs-"<< globalSessionHandle <<"-t-"<(recordFilePath.string()); + } + + void RecordManager::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)); + } + + void RecordManager::clearWithTailer() + { + m_memoryStream.flush(); + FunctionTailer tailer; + + // write header to memory stream + m_memoryStream.write(&tailer, sizeof(FunctionTailer)); + } + + ParameterRecorder* RecordManager::beginMethodRecord(const ApiCallId& callId, uint64_t handleId) + { + clearWithHeader(callId, handleId); + return &m_recorder; + } + + ParameterRecorder* RecordManager::endMethodRecord() + { + 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 record 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(); + + clearWithTailer(); + return &m_recorder; + } + + void RecordManager::endMethodRecordAppendOutput() + { + FunctionTailer* pTailer = const_cast( + reinterpret_cast(m_memoryStream.getData())); + + pTailer->dataSizeInBytes = (uint32_t)(m_memoryStream.getSizeInBytes() - sizeof(FunctionTailer)); + + // write record 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