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/output-stream.cpp | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 source/slang-capture-replay/output-stream.cpp (limited to 'source/slang-capture-replay/output-stream.cpp') diff --git a/source/slang-capture-replay/output-stream.cpp b/source/slang-capture-replay/output-stream.cpp new file mode 100644 index 000000000..acde6fbf1 --- /dev/null +++ b/source/slang-capture-replay/output-stream.cpp @@ -0,0 +1,52 @@ +#include "output-stream.h" +#include "capture_utility.h" + +namespace SlangCapture +{ + FileOutputStream::FileOutputStream(const std::string& filename, bool append) + { + Slang::String path(filename.c_str()); + Slang::FileMode fileMode = append ? Slang::FileMode::Append : Slang::FileMode::Create; + Slang::FileAccess fileAccess = Slang::FileAccess::Write; + Slang::FileShare fileShare = Slang::FileShare::None; + + SlangResult res = m_fileStream.init(path, fileMode, fileAccess, fileShare); + + if (res != SLANG_OK) + { + SlangCapture::slangCaptureLog(SlangCapture::LogLevel::Error, "Failed to open file %s\n", filename.c_str()); + std::abort(); + } + } + + FileOutputStream::~FileOutputStream() + { + m_fileStream.close(); + } + + void FileOutputStream::write(const void* data, size_t len) + { + SLANG_CAPTURE_ASSERT(m_fileStream.write(data, len)); + } + + MemoryStream::MemoryStream() + : m_memoryStream(Slang::FileAccess::Write) + { } + + void FileOutputStream::flush() + { + SLANG_CAPTURE_ASSERT(m_fileStream.flush()); + } + + void MemoryStream::write(const void* data, size_t len) + { + SLANG_CAPTURE_ASSERT(m_memoryStream.write(data, len)); + } + + void MemoryStream::flush() + { + // This call will reset the underlying buffer to size 0, + // and reset the write position to 0. + m_memoryStream.setContent(nullptr, 0); + } +} -- cgit v1.2.3