Skip to content

Commit

Permalink
wip: working on new parser
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Aug 30, 2023
1 parent 2ac8695 commit 1eecb0c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 131,265 deletions.
80 changes: 34 additions & 46 deletions src/TraceReader/TraceReaderNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ void TraceReaderNew::processTimestamp(std::vector<uint8_t>& chunk)
chunk.clear();
}

void TraceReaderNew::handleTimestamp(uint32_t& idx, int32_t& length)
{
timestamp = 0;
chunk.push_back(buffer[idx]);
remainingFrameType = 0;
while (TRACE_OP_GET_CONTINUATION(buffer[idx]) && !remainingFrameType)
{
if (idx < length - 1)
{
idx++;
chunk.push_back(buffer[idx]);
}
else
{
std::cout << " remaining timestamp " << std::endl;
remainingFrameType = 2;
remainingBytes = 1;
}
}
if (remainingFrameType == 0)
processTimestamp(chunk);
}

void TraceReaderNew::readerThread()
{
while (isRunning.load())
Expand Down Expand Up @@ -208,40 +231,25 @@ void TraceReaderNew::readerThread()

if (remainingFrameType == 2)
{
remainingFrameType = 0;
chunk.push_back(buffer[idx]);
while (TRACE_OP_GET_CONTINUATION(buffer[idx]))
{
if (idx < length - 1)
idx++;
else
{
std::cout << " remaining timestamp REST " << std::endl;
remainingFrameType = 2;
}
chunk.push_back(buffer[idx]);
}
if (remainingFrameType == 0)
{
std::cout << "procesing timestampo" << std::endl;
processTimestamp(chunk);
idx++;
}
handleTimestamp(idx, length);
idx++;
}
else if (remainingFrameType == 1 && remainingBytes)
else if (remainingFrameType == 1)
{
remainingFrameType = 0;
chunk.push_back(buffer[idx]);
remainingBytes--;
while (remainingBytes--)
{
chunk.push_back(buffer[idx]);
if (idx < length - 1)
idx++;
else
remainingFrameType = 1;
chunk.push_back(buffer[idx]);
}
length -= idx;
if (remainingFrameType == 0)
{
std::cout << "procesing sourco" << std::endl;
processSource(chunk);
idx++;
}
Expand All @@ -264,42 +272,22 @@ void TraceReaderNew::readerThread()
for (uint32_t i = 0; i < size; i++)
{
if (idx < length - 1)
{
idx++;
chunk.push_back(buffer[idx]);
}
else
{
remainingFrameType = 1;
remainingBytes = size - i;
std::cout << "remaining: " << (int)remainingBytes << std::endl;
}

chunk.push_back(buffer[idx]);
}
if (remainingFrameType == 0)
processSource(chunk);
}
else if (TRACE_OP_IS_LOCAL_TIME(c))
{
timestamp = 0;

chunk.push_back(buffer[idx]);

while (TRACE_OP_GET_CONTINUATION(buffer[idx]) && !remainingFrameType)
{
if (idx < length - 1)
{
idx++;
chunk.push_back(buffer[idx]);
}
else
{
std::cout << " remaining timestamp " << std::endl;
remainingFrameType = 2;
remainingBytes = 1;
}
}
if (remainingFrameType == 0)
processTimestamp(chunk);
}
handleTimestamp(idx, length);

idx++;

Expand Down
1 change: 1 addition & 0 deletions src/TraceReader/TraceReaderNew.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TraceReaderNew

void processSource(std::vector<uint8_t>& chunk);
void processTimestamp(std::vector<uint8_t>& chunk);
void handleTimestamp(uint32_t& idx, int32_t& length);
void readerThread();

std::shared_ptr<ITraceDevice> traceDevice;
Expand Down
8 changes: 4 additions & 4 deletions test/TraceReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <memory>

#include "ITraceDevice.hpp"
// #include "TraceReader/TraceReader.hpp"
#include "TraceReader/TraceReaderNew.hpp"
#include "TraceReader/TraceReader.hpp"
// #include "TraceReader/TraceReaderNew.hpp"
#include "gmock/gmock.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h"
Expand Down Expand Up @@ -34,7 +34,7 @@ class TraceReaderTest : public ::testing::Test
void SetUp() override
{
traceDevice = std::make_shared<::NiceMock<TraceDeviceMock>>();
traceReader = std::make_shared<TraceReaderNew>(traceDevice, logger);
traceReader = std::make_shared<TraceReader>(traceDevice, logger);

ON_CALL(*traceDevice, startTrace(_, _, _)).WillByDefault(Return(true));
ON_CALL(*traceDevice, stopTrace()).WillByDefault(Return(true));
Expand All @@ -55,7 +55,7 @@ class TraceReaderTest : public ::testing::Test
std::shared_ptr<spdlog::sinks::stdout_color_sink_mt> stdout_sink;
std::shared_ptr<spdlog::logger> logger;

std::shared_ptr<TraceReaderNew> traceReader;
std::shared_ptr<TraceReader> traceReader;
std::shared_ptr<::NiceMock<TraceDeviceMock>> traceDevice;
};

Expand Down
Loading

0 comments on commit 1eecb0c

Please sign in to comment.