Skip to content

Commit

Permalink
🔀 Merge branch 'ladislas/feature/log-kit-optimize-process-fifo' into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
ladislas committed Nov 16, 2022
2 parents d7b6fb5 + 882952e commit bbd431e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions libs/LogKit/include/LogKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace buffer {
inline auto message = std::array<char, 256> {};
inline auto output = std::array<char, 512> {};

inline auto fifo = CircularQueue<char, 4096> {};
inline auto fifo = CircularQueue<char, 4096> {};
inline auto process_buffer = std::array<char, 64> {};

}; // namespace buffer

Expand Down Expand Up @@ -104,9 +105,8 @@ namespace internal {
inline void process_fifo()
{
while (!buffer::fifo.empty()) {
auto c = char {};
buffer::fifo.pop(c);
internal::filehandle->write(&c, 1);
auto length = buffer::fifo.pop(buffer::process_buffer.data(), std::size(buffer::process_buffer));
internal::filehandle->write(buffer::process_buffer.data(), length);
}
}

Expand Down
8 changes: 4 additions & 4 deletions libs/LogKit/tests/LogKit_test_fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ TEST_F(LogKitFifoTest, processEmpty)

TEST_F(LogKitFifoTest, processNotEmpty)
{
EXPECT_CALL(mockfh, write).Times(128);
EXPECT_CALL(mockfh, write).Times(128 / std::size(logger::buffer::process_buffer));

for (auto i = 0; i < 128; ++i) {
logger::buffer::fifo.push(i);
logger::buffer::fifo.push(static_cast<char>(i));
}

logger::process_fifo();
}

TEST_F(LogKitFifoTest, processFull)
{
EXPECT_CALL(mockfh, write).Times(4096);
EXPECT_CALL(mockfh, write).Times(4096 / std::size(logger::buffer::process_buffer));

for (auto i = 0; i < 4096; ++i) {
logger::buffer::fifo.push(i);
logger::buffer::fifo.push(static_cast<char>(i));
}

logger::process_fifo();
Expand Down
4 changes: 2 additions & 2 deletions spikes/lk_log_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ auto main() -> int
// log_from_isr();
};

// ticker_log_from_isr.attach(log_isr_lambda, 2s);
// ticker_log_from_isr.attach(log_isr_lambda, 5s);

while (true) {
auto start = rtos::Kernel::Clock::now();
Expand All @@ -65,6 +65,6 @@ auto main() -> int

log_info("log_debug took %i ms to complete... that's fast!\n", int((stop - start).count()));

rtos::ThisThread::sleep_for(1000ms);
rtos::ThisThread::sleep_for(3333ms);
}
}
2 changes: 1 addition & 1 deletion spikes/lk_log_kit/source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace std::chrono;

log_info("Total time to LOG the for loop --> %ims\n", static_cast<int>((stop - start).count()));

rtos::ThisThread::sleep_for(3s);
rtos::ThisThread::sleep_for(5s);
}
}

Expand Down

0 comments on commit bbd431e

Please sign in to comment.