logmeow/windows/debug.cpp

89 lines
3.1 KiB
C++

#include <imgui/imgui.cpp>
#include "../myimconfig.h"
#include "../log.h"
#include "../config.h"
#include "../filters.h"
#include "../logcat_entry.h"
#include "../logcat_thread.h"
#include "debug.h"
void debug_window(LogcatThread& logcat_thread, const Config& active_config,
std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets) {
static bool show_demo_window = false;
static size_t add_log_entry_presses = 1;
static bool log_entry_every_second = false;
static float log_entry_every_second_delta;
if (show_demo_window) {
ImGui::ShowDemoWindow(&show_demo_window);
}
if (!ImGui::Begin("LogMeow Debug")) {
ImGui::End();
return;
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Checkbox("Show Dear ImGui Demo Window", &show_demo_window);
ImGui::Separator();
if (ImGui::Button("Add Log Entry")) {
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated via manual button press)");
}
ImGui::SameLine();
// returns true when it's pressed
if (ImGui::Checkbox("Add log entry every second", &log_entry_every_second)) {
log_entry_every_second_delta = 0.0f;
}
if (ImGui::Button("Add Log Entry with Newlines")) {
log("The following should have five spaces: \"\n\n\n\n\n\"");
}
if (ImGui::Button("Test user assert")) {
IM_ASSERT_USER_ERROR(0, "User assert tested");
}
if (ImGui::Button("Request log entry from Logcat thread")) {
logcat_thread.debug_log_request.test_and_set();
}
if (log_entry_every_second) {
log_entry_every_second_delta += ImGui::GetIO().DeltaTime;
if (log_entry_every_second_delta >= 1.0f) {
log_entry_every_second_delta = 0.0f;
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated by add log entry every second)");
}
}
ImGui::Separator();
auto add_logcat_entry = [&](LogcatEntry logcat_entry) {
logcat_entries.push_back(std::move(logcat_entry));
if (matches(logcat_entries.back(), active_config.filters, active_config.exclusions)) {
filtered_logcat_entry_offsets.push_back(logcat_entries.size() - 1);
}
};
if (ImGui::Button("Add test entry (w/ user)")) {
add_logcat_entry({
.buffer = Buffer::Main,
.time = time(nullptr),
.user = "blankie",
.pid = 69,
.tid = 420,
.priority = Priority::Error,
.tag = "blanket, inc.",
.message = "Failed to make blanket",
});
}
if (ImGui::Button("Add test entry (w/o user)")) {
add_logcat_entry({
.buffer = Buffer::Crash,
.time = time(nullptr),
.pid = 420,
.tid = 69,
.priority = Priority::Fatal,
.tag = "blanket, inc.",
.message = "Failed to invent blankets",
});
}
ImGui::End();
}