summaryrefslogtreecommitdiffstats
path: root/source/slang-record-replay/replay/recordFile-processor.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang-record-replay/replay/recordFile-processor.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang-record-replay/replay/recordFile-processor.cpp')
-rw-r--r--source/slang-record-replay/replay/recordFile-processor.cpp220
1 files changed, 115 insertions, 105 deletions
diff --git a/source/slang-record-replay/replay/recordFile-processor.cpp b/source/slang-record-replay/replay/recordFile-processor.cpp
index bf3ea874b..4772a2711 100644
--- a/source/slang-record-replay/replay/recordFile-processor.cpp
+++ b/source/slang-record-replay/replay/recordFile-processor.cpp
@@ -1,146 +1,156 @@
#include "recordFile-processor.h"
+
#include "../util/record-format.h"
#include "parameter-decoder.h"
namespace SlangRecord
{
- RecordFileProcessor::RecordFileProcessor(const Slang::String& filePath)
- {
- Slang::FileMode fileMode = Slang::FileMode::Open;
- Slang::FileAccess fileAccess = Slang::FileAccess::Read;
- Slang::FileShare fileShare = Slang::FileShare::None;
-
- // Open the record file with read-only access
- SlangResult res = m_inputStream.init(filePath, fileMode, fileAccess, fileShare);
-
- if (res != SLANG_OK)
- {
- SlangRecord::slangRecordLog(SlangRecord::LogLevel::Error, "Failed to open file %s\n", filePath.begin());
- std::abort();
- }
+RecordFileProcessor::RecordFileProcessor(const Slang::String& filePath)
+{
+ Slang::FileMode fileMode = Slang::FileMode::Open;
+ Slang::FileAccess fileAccess = Slang::FileAccess::Read;
+ Slang::FileShare fileShare = Slang::FileShare::None;
- // Enable log system
- setLogLevel();
- }
+ // Open the record file with read-only access
+ SlangResult res = m_inputStream.init(filePath, fileMode, fileAccess, fileShare);
- bool RecordFileProcessor::processNextBlock()
+ if (res != SLANG_OK)
{
- FunctionHeader header {};
- if (!processHeader(header))
- {
- return false;
- }
-
- ApiClassId classId = static_cast<ApiClassId>(getClassId(header.callId));
-
- // capacity comparison will be performed in the reserve call, so we can safely call reserve
- m_parameterBuffer.reserve(header.dataSizeInBytes);
-
- size_t readBytes = 0;
- SlangResult res = SLANG_OK;
+ SlangRecord::slangRecordLog(
+ SlangRecord::LogLevel::Error,
+ "Failed to open file %s\n",
+ filePath.begin());
+ std::abort();
+ }
- if (header.dataSizeInBytes)
- {
- res = m_inputStream.read(m_parameterBuffer.getBuffer(), header.dataSizeInBytes, readBytes);
- }
+ // Enable log system
+ setLogLevel();
+}
- if (res != SLANG_OK || readBytes != header.dataSizeInBytes)
- {
- return false;
- }
+bool RecordFileProcessor::processNextBlock()
+{
+ FunctionHeader header{};
+ if (!processHeader(header))
+ {
+ return false;
+ }
- FunctionTailer tailer {};
- if (processTailer(tailer) == ERROR_BLOCK)
- {
- return false;
- }
+ ApiClassId classId = static_cast<ApiClassId>(getClassId(header.callId));
- if (tailer.dataSizeInBytes)
- {
- m_outputBuffer.reserve(tailer.dataSizeInBytes);
- res = m_inputStream.read(m_outputBuffer.getBuffer(), tailer.dataSizeInBytes, readBytes);
+ // capacity comparison will be performed in the reserve call, so we can safely call reserve
+ m_parameterBuffer.reserve(header.dataSizeInBytes);
- if (res != SLANG_OK || readBytes != tailer.dataSizeInBytes)
- {
- return false;
- }
- }
+ size_t readBytes = 0;
+ SlangResult res = SLANG_OK;
- bool ret = false;
- SlangDecoder::ParameterBlock paramBlock {};
- paramBlock.parameterBuffer = m_parameterBuffer.getBuffer();
- paramBlock.parameterBufferSize = header.dataSizeInBytes;
- paramBlock.outputBuffer = m_outputBuffer.getBuffer();
- paramBlock.outputBufferSize = tailer.dataSizeInBytes;
+ if (header.dataSizeInBytes)
+ {
+ res = m_inputStream.read(m_parameterBuffer.getBuffer(), header.dataSizeInBytes, readBytes);
+ }
- if (classId == ApiClassId::GlobalFunction)
- {
- ret = m_decoder->processFunctionCall(header, paramBlock);
- }
- else
- {
- ret = m_decoder->processMethodCall(header, paramBlock);
- }
+ if (res != SLANG_OK || readBytes != header.dataSizeInBytes)
+ {
+ return false;
+ }
- m_parameterBuffer.clear();
- m_outputBuffer.clear();
- return ret;
+ FunctionTailer tailer{};
+ if (processTailer(tailer) == ERROR_BLOCK)
+ {
+ return false;
}
- bool RecordFileProcessor::processHeader(FunctionHeader& header)
+ if (tailer.dataSizeInBytes)
{
- size_t readBytes = 0;
- SlangResult res = m_inputStream.read(&header, sizeof(FunctionHeader), readBytes);
+ m_outputBuffer.reserve(tailer.dataSizeInBytes);
+ res = m_inputStream.read(m_outputBuffer.getBuffer(), tailer.dataSizeInBytes, readBytes);
- if (res != SLANG_OK || readBytes != sizeof(FunctionHeader))
+ if (res != SLANG_OK || readBytes != tailer.dataSizeInBytes)
{
return false;
}
+ }
- if (header.magic != MAGIC_HEADER || header.callId == ApiCallId::InvalidCallId)
- {
- return false;
- }
+ bool ret = false;
+ SlangDecoder::ParameterBlock paramBlock{};
+ paramBlock.parameterBuffer = m_parameterBuffer.getBuffer();
+ paramBlock.parameterBufferSize = header.dataSizeInBytes;
+ paramBlock.outputBuffer = m_outputBuffer.getBuffer();
+ paramBlock.outputBufferSize = tailer.dataSizeInBytes;
- return true;
+ if (classId == ApiClassId::GlobalFunction)
+ {
+ ret = m_decoder->processFunctionCall(header, paramBlock);
+ }
+ else
+ {
+ ret = m_decoder->processMethodCall(header, paramBlock);
}
- RecordFileResultCode RecordFileProcessor::processTailer(FunctionTailer& tailer)
+ m_parameterBuffer.clear();
+ m_outputBuffer.clear();
+ return ret;
+}
+
+bool RecordFileProcessor::processHeader(FunctionHeader& header)
+{
+ size_t readBytes = 0;
+ SlangResult res = m_inputStream.read(&header, sizeof(FunctionHeader), readBytes);
+
+ if (res != SLANG_OK || readBytes != sizeof(FunctionHeader))
{
- size_t readBytes = 0;
- SlangResult res = m_inputStream.read(&tailer, sizeof(FunctionTailer), readBytes);
+ return false;
+ }
- if (res != SLANG_OK || readBytes != sizeof(FunctionTailer))
- {
- return ERROR_BLOCK;
- }
+ if (header.magic != MAGIC_HEADER || header.callId == ApiCallId::InvalidCallId)
+ {
+ return false;
+ }
- // If we don't read a valid tailer, but the magic is bit is a header, it indicates that
- // there is no tailer for this block, but it's still a valid block.
- if (tailer.magic == MAGIC_HEADER)
- {
- // revert back to last read position, and clear tailer
- int64_t offset = -(int64_t)sizeof(FunctionTailer);
- m_inputStream.seek(Slang::SeekOrigin::Current, offset);
- memset(&tailer, 0, sizeof(FunctionTailer));
- return NOT_EXSIT;
- }
+ return true;
+}
- if (tailer.magic != MAGIC_TAILER)
- {
- return ERROR_BLOCK;
- }
+RecordFileResultCode RecordFileProcessor::processTailer(FunctionTailer& tailer)
+{
+ size_t readBytes = 0;
+ SlangResult res = m_inputStream.read(&tailer, sizeof(FunctionTailer), readBytes);
- return RESULT_OK;
+ if (res != SLANG_OK || readBytes != sizeof(FunctionTailer))
+ {
+ return ERROR_BLOCK;
}
- bool RecordFileProcessor::processMethod(FunctionHeader const& header, const uint8_t* parameterBuffer, int64_t bufferSize)
+ // If we don't read a valid tailer, but the magic is bit is a header, it indicates that
+ // there is no tailer for this block, but it's still a valid block.
+ if (tailer.magic == MAGIC_HEADER)
{
- return false;
+ // revert back to last read position, and clear tailer
+ int64_t offset = -(int64_t)sizeof(FunctionTailer);
+ m_inputStream.seek(Slang::SeekOrigin::Current, offset);
+ memset(&tailer, 0, sizeof(FunctionTailer));
+ return NOT_EXSIT;
}
- bool RecordFileProcessor::processFunction(FunctionHeader const& header, const uint8_t* parameterBuffer, int64_t bufferSize)
+ if (tailer.magic != MAGIC_TAILER)
{
- return false;
+ return ERROR_BLOCK;
}
+
+ return RESULT_OK;
+}
+
+bool RecordFileProcessor::processMethod(
+ FunctionHeader const& header,
+ const uint8_t* parameterBuffer,
+ int64_t bufferSize)
+{
+ return false;
+}
+
+bool RecordFileProcessor::processFunction(
+ FunctionHeader const& header,
+ const uint8_t* parameterBuffer,
+ int64_t bufferSize)
+{
+ return false;
+}
}; // namespace SlangRecord