Add debug button to request a log entry from the logcat thread

This commit is contained in:
blankie 2023-01-18 23:43:30 +07:00
parent be07a6b3aa
commit d9c7184b0e
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 15 additions and 2 deletions

View File

@ -109,7 +109,7 @@ static inline void main_window(bool latest_log_entries_read, bool* show_settings
} }
#ifndef NDEBUG #ifndef NDEBUG
static inline void debug_window() { static inline void debug_window(LogcatThread& logcat_thread) {
static bool show_demo_window = false; static bool show_demo_window = false;
static size_t add_log_entry_presses = 1; static size_t add_log_entry_presses = 1;
static bool log_entry_every_second = false; static bool log_entry_every_second = false;
@ -138,6 +138,9 @@ static inline void debug_window() {
if (ImGui::Button("Add Log Entry with Newlines")) { if (ImGui::Button("Add Log Entry with Newlines")) {
log("The following should have five spaces: \"\n\n\n\n\n\""); log("The following should have five spaces: \"\n\n\n\n\n\"");
} }
if (ImGui::Button("Request log entry from Logcat thread")) {
logcat_thread.debug_log_request.test_and_set();
}
if (log_entry_every_second) { if (log_entry_every_second) {
log_entry_every_second_delta += ImGui::GetIO().DeltaTime; log_entry_every_second_delta += ImGui::GetIO().DeltaTime;
@ -159,7 +162,7 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time
check_for_logcat_items(logcat_thread); check_for_logcat_items(logcat_thread);
#ifndef NDEBUG #ifndef NDEBUG
debug_window(); debug_window(logcat_thread);
#endif #endif
if (show_settings_window) { if (show_settings_window) {

View File

@ -106,6 +106,12 @@ void LogcatThread::_run(std::stop_token stoken) {
while (!stoken.stop_requested()) { while (!stoken.stop_requested()) {
printf("(boop)\n"); printf("(boop)\n");
#ifndef NDEBUG
if (this->debug_log_request.test()) {
this->atomic_ring_buffer.put_and_increment_write(format_log("A log entry from the logcat thread :D"));
this->debug_log_request.clear();
}
#endif
int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000); int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000);
if (ready_fds == -1) { if (ready_fds == -1) {

View File

@ -19,6 +19,10 @@ public:
AtomicRingBuffer<LogcatThreadItem> atomic_ring_buffer; AtomicRingBuffer<LogcatThreadItem> atomic_ring_buffer;
#ifndef NDEBUG
std::atomic_flag debug_log_request;
#endif
private: private:
void _run(std::stop_token stoken); void _run(std::stop_token stoken);