summaryrefslogtreecommitdiff
path: root/source/slang-record-replay/record/record-manager.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/record/record-manager.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang-record-replay/record/record-manager.cpp')
-rw-r--r--source/slang-record-replay/record/record-manager.cpp139
1 files changed, 72 insertions, 67 deletions
diff --git a/source/slang-record-replay/record/record-manager.cpp b/source/slang-record-replay/record/record-manager.cpp
index 03abffcce..3be120c43 100644
--- a/source/slang-record-replay/record/record-manager.cpp
+++ b/source/slang-record-replay/record/record-manager.cpp
@@ -1,94 +1,99 @@
-#include <sstream>
-#include <thread>
-#include "../util/record-utility.h"
#include "record-manager.h"
+
#include "../../core/slang-io.h"
+#include "../util/record-utility.h"
+
+#include <sstream>
+#include <thread>
namespace SlangRecord
{
- RecordManager::RecordManager(uint64_t globalSessionHandle)
- : m_recorder(&m_memoryStream)
- {
- std::stringstream ss;
- ss << "gs-"<< globalSessionHandle <<"-t-"<<std::this_thread::get_id() << ".cap";
+RecordManager::RecordManager(uint64_t globalSessionHandle)
+ : m_recorder(&m_memoryStream)
+{
+ std::stringstream ss;
+ ss << "gs-" << globalSessionHandle << "-t-" << std::this_thread::get_id() << ".cap";
- m_recordFileDirectory = Slang::Path::combine(m_recordFileDirectory, "slang-record");
- if (!Slang::File::exists(m_recordFileDirectory))
+ m_recordFileDirectory = Slang::Path::combine(m_recordFileDirectory, "slang-record");
+ if (!Slang::File::exists(m_recordFileDirectory))
+ {
+ if (!Slang::Path::createDirectoryRecursive(m_recordFileDirectory))
{
- if (!Slang::Path::createDirectoryRecursive(m_recordFileDirectory))
- {
- slangRecordLog(LogLevel::Error, "Fail to create directory: %s\n",
- m_recordFileDirectory.getBuffer());
- }
+ slangRecordLog(
+ LogLevel::Error,
+ "Fail to create directory: %s\n",
+ m_recordFileDirectory.getBuffer());
}
-
- Slang::String recordFilePath = Slang::Path::combine(m_recordFileDirectory, Slang::String(ss.str().c_str()));
- m_fileStream = new FileOutputStream(recordFilePath);
}
- void RecordManager::clearWithHeader(const ApiCallId& callId, uint64_t handleId)
- {
- m_memoryStream.flush();
- FunctionHeader header;
- header.callId = callId;
- header.handleId = handleId;
+ Slang::String recordFilePath =
+ Slang::Path::combine(m_recordFileDirectory, Slang::String(ss.str().c_str()));
+ m_fileStream = new FileOutputStream(recordFilePath);
+}
- // write header to memory stream
- m_memoryStream.write(&header, sizeof(FunctionHeader));
- }
+void RecordManager::clearWithHeader(const ApiCallId& callId, uint64_t handleId)
+{
+ m_memoryStream.flush();
+ FunctionHeader header;
+ header.callId = callId;
+ header.handleId = handleId;
- void RecordManager::clearWithTailer()
- {
- m_memoryStream.flush();
- FunctionTailer tailer;
+ // write header to memory stream
+ m_memoryStream.write(&header, sizeof(FunctionHeader));
+}
- // write header to memory stream
- m_memoryStream.write(&tailer, sizeof(FunctionTailer));
- }
+void RecordManager::clearWithTailer()
+{
+ m_memoryStream.flush();
+ FunctionTailer tailer;
- ParameterRecorder* RecordManager::beginMethodRecord(const ApiCallId& callId, uint64_t handleId)
- {
- clearWithHeader(callId, handleId);
- return &m_recorder;
- }
+ // write header to memory stream
+ m_memoryStream.write(&tailer, sizeof(FunctionTailer));
+}
- ParameterRecorder* RecordManager::endMethodRecord()
- {
- FunctionHeader* pHeader = const_cast<FunctionHeader*>(
- reinterpret_cast<const FunctionHeader*>(m_memoryStream.getData()));
+ParameterRecorder* RecordManager::beginMethodRecord(const ApiCallId& callId, uint64_t handleId)
+{
+ clearWithHeader(callId, handleId);
+ return &m_recorder;
+}
- pHeader->dataSizeInBytes = m_memoryStream.getSizeInBytes() - sizeof(FunctionHeader);
+ParameterRecorder* RecordManager::endMethodRecord()
+{
+ FunctionHeader* pHeader = const_cast<FunctionHeader*>(
+ reinterpret_cast<const FunctionHeader*>(m_memoryStream.getData()));
- std::hash<std::thread::id> hasher;
- pHeader->threadId = hasher(std::this_thread::get_id());
+ pHeader->dataSizeInBytes = m_memoryStream.getSizeInBytes() - sizeof(FunctionHeader);
- // write record data to file
- m_fileStream->write(m_memoryStream.getData(), m_memoryStream.getSizeInBytes());
+ std::hash<std::thread::id> hasher;
+ pHeader->threadId = hasher(std::this_thread::get_id());
- // take effect of the write
- m_fileStream->flush();
+ // write record data to file
+ m_fileStream->write(m_memoryStream.getData(), m_memoryStream.getSizeInBytes());
- // clear the memory stream
- m_memoryStream.flush();
+ // take effect of the write
+ m_fileStream->flush();
- clearWithTailer();
- return &m_recorder;
- }
+ // clear the memory stream
+ m_memoryStream.flush();
- void RecordManager::apendOutput()
- {
- FunctionTailer* pTailer = const_cast<FunctionTailer*>(
- reinterpret_cast<const FunctionTailer*>(m_memoryStream.getData()));
+ clearWithTailer();
+ return &m_recorder;
+}
+
+void RecordManager::apendOutput()
+{
+ FunctionTailer* pTailer = const_cast<FunctionTailer*>(
+ reinterpret_cast<const FunctionTailer*>(m_memoryStream.getData()));
- pTailer->dataSizeInBytes = (uint32_t)(m_memoryStream.getSizeInBytes() - sizeof(FunctionTailer));
+ pTailer->dataSizeInBytes = (uint32_t)(m_memoryStream.getSizeInBytes() - sizeof(FunctionTailer));
- // write record data to file
- m_fileStream->write(m_memoryStream.getData(), m_memoryStream.getSizeInBytes());
+ // write record data to file
+ m_fileStream->write(m_memoryStream.getData(), m_memoryStream.getSizeInBytes());
- // take effect of the write
- m_fileStream->flush();
+ // take effect of the write
+ m_fileStream->flush();
- // clear the memory stream
- m_memoryStream.flush();
- }
+ // clear the memory stream
+ m_memoryStream.flush();
}
+} // namespace SlangRecord