From 93fcb83c34c932c82deeb8a8cd626f0dc990716c Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Mon, 17 Jun 2024 08:41:34 -0700 Subject: Feature/capture (#4397) * Add the function tailer for appending the output - The basic format for the capture encode is as follow: Header: 4 bytes: magic number ('H' 'E' 'A' 'D' ) 4 bytes: call id - specify the method name 8 bytes: handle id - specify 'this' pointer 8 bytes: payload size in bytes - specify the data size of parameters 8 bytes: thread id Payload: Encode for all the parameters. Tailer (optional): Tailer is an optional, it only used when the output of the method is also stored in the method. Usually it just the opaque handle allocated by slang. 4 bytes: magic number ('T' 'A' 'I' 'L') 4 bytes: payload size in bytes. - Fix some issues in checking the result of write of output stream. * Encoding methods of IGlobalSession Add encoding logic for all the member functions of IGlobalSession, except those query functions that do not impact the internal state of slang. Because some get functions will invoke allocations by slang, these functions are account for the "query functions". Therefore those functions are still captured. All the allocations are stored by using their address, because those allocations are opaque and will finally be used as inputs for other APIs, there is no need to store the data. We just need to track those address and know which APIs will consume them. * Add SLANG_CAPTURE_CHECK macro Add SLANG_CAPTURE_CHECK macro to check SLANG_OK is returned. * Fix build error --- source/slang-capture-replay/capture-manager.cpp | 35 ++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (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 index be5615e00..2d04b077a 100644 --- a/source/slang-capture-replay/capture-manager.cpp +++ b/source/slang-capture-replay/capture-manager.cpp @@ -10,14 +10,14 @@ namespace SlangCapture : 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 {}; + FunctionHeader header; header.callId = callId; header.handleId = handleId; @@ -25,13 +25,22 @@ namespace SlangCapture m_memoryStream.write(&header, sizeof(FunctionHeader)); } + void CaptureManager::clearWithTailer() + { + m_memoryStream.flush(); + FunctionTailer tailer; + + // write header to memory stream + m_memoryStream.write(&tailer, sizeof(FunctionTailer)); + } + ParameterEncoder* CaptureManager::beginMethodCapture(const ApiCallId& callId, uint64_t handleId) { clearWithHeader(callId, handleId); return &m_encoder; } - void CaptureManager::endMethodCapture() + ParameterEncoder* CaptureManager::endMethodCapture() { FunctionHeader* pHeader = const_cast( reinterpret_cast(m_memoryStream.getData())); @@ -49,5 +58,25 @@ namespace SlangCapture // clear the memory stream m_memoryStream.flush(); + + clearWithTailer(); + return &m_encoder; + } + + void CaptureManager::endMethodCaptureAppendOutput() + { + FunctionTailer* pTailer = const_cast( + reinterpret_cast(m_memoryStream.getData())); + + pTailer->dataSizeInBytes = (uint32_t)(m_memoryStream.getSizeInBytes() - sizeof(FunctionTailer)); + + // 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