summaryrefslogtreecommitdiff
path: root/source/slang-capture-replay/output-stream.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-06-13 13:02:12 -0700
committerGitHub <noreply@github.com>2024-06-13 13:02:12 -0700
commitf0d40ad5e1d0a0dec39fe8a141d3f81d88fc576a (patch)
tree210a0a9b5bb2aea0e64776527c4ce04266709a43 /source/slang-capture-replay/output-stream.cpp
parentecc6ecb3a25a28eb5e85cfdb2bf170448ab9a4e7 (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/output-stream.cpp')
-rw-r--r--source/slang-capture-replay/output-stream.cpp52
1 files changed, 52 insertions, 0 deletions
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);
+ }
+}