Skip to content

⚡ (LogKit): Process fifo by chuncks of 64 bytes #1116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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