Compare commits
3 Commits
6b6dd58a0e
...
1c44b770a8
Author | SHA1 | Date |
---|---|---|
|
1c44b770a8 | |
|
04c46e220f | |
|
9e73720525 |
3
log.cpp
3
log.cpp
|
@ -16,8 +16,9 @@ LogEntry::LogEntry(time_t time_, std::string message_) : time(time_), message(st
|
||||||
|
|
||||||
|
|
||||||
std::string format_log(const LogEntry& entry) {
|
std::string format_log(const LogEntry& entry) {
|
||||||
|
struct tm tm;
|
||||||
char time_as_str[128] = {0};
|
char time_as_str[128] = {0};
|
||||||
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&entry.time));
|
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&entry.time, &tm));
|
||||||
return std::string(1, '[') + time_as_str + "] " + entry.message;
|
return std::string(1, '[') + time_as_str + "] " + entry.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,9 +159,6 @@ void LogcatThread::_put_if_not_stopped(LogcatThreadItem item) {
|
||||||
if (this->atomic_ring_buffer.try_put_and_increment_write(item)) {
|
if (this->atomic_ring_buffer.try_put_and_increment_write(item)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifndef NDEBUG
|
|
||||||
printf("spinlocking!!!\n");
|
|
||||||
#endif
|
|
||||||
if (this->_stop_source.stop_requested()) {
|
if (this->_stop_source.stop_requested()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +232,7 @@ void LogcatThread::_run_epoll_round() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogcatThread::_try_reap(bool stop_requested) {
|
void LogcatThread::_try_reap(bool has_request) {
|
||||||
int wstatus;
|
int wstatus;
|
||||||
int res = waitpid(this->_logcat_pid, &wstatus, WNOHANG);
|
int res = waitpid(this->_logcat_pid, &wstatus, WNOHANG);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
|
@ -259,13 +256,13 @@ void LogcatThread::_try_reap(bool stop_requested) {
|
||||||
this->logcat_process_running.clear();
|
this->logcat_process_running.clear();
|
||||||
|
|
||||||
if (WIFEXITED(wstatus)) {
|
if (WIFEXITED(wstatus)) {
|
||||||
if (WEXITSTATUS(wstatus) && !stop_requested) {
|
if (WEXITSTATUS(wstatus) && !has_request) {
|
||||||
LogEntry log_entry = {time(nullptr), std::string("Logcat exited with ") + std::to_string(WEXITSTATUS(wstatus))};
|
LogEntry log_entry = {time(nullptr), std::string("Logcat exited with ") + std::to_string(WEXITSTATUS(wstatus))};
|
||||||
print_log(log_entry);
|
print_log(log_entry);
|
||||||
this->_put_if_not_stopped(std::move(log_entry));
|
this->_put_if_not_stopped(std::move(log_entry));
|
||||||
}
|
}
|
||||||
} else if (WIFSIGNALED(wstatus)) {
|
} else if (WIFSIGNALED(wstatus)) {
|
||||||
if (!stop_requested) {
|
if (!has_request) {
|
||||||
LogEntry log_entry = {time(nullptr), std::string("Logcat exited with -") + std::to_string(WTERMSIG(wstatus))};
|
LogEntry log_entry = {time(nullptr), std::string("Logcat exited with -") + std::to_string(WTERMSIG(wstatus))};
|
||||||
print_log(log_entry);
|
print_log(log_entry);
|
||||||
this->_put_if_not_stopped(std::move(log_entry));
|
this->_put_if_not_stopped(std::move(log_entry));
|
||||||
|
@ -362,7 +359,7 @@ bool LogcatThread::_run_process_round(LogcatProcessRequest request) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this->_logcat_pid != -1) {
|
if (this->_logcat_pid != -1) {
|
||||||
this->_try_reap(request == LogcatProcessRequest::Stop);
|
this->_try_reap(request != LogcatProcessRequest::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
return task_done;
|
return task_done;
|
||||||
|
|
|
@ -22,8 +22,9 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) {
|
||||||
size_t i = static_cast<size_t>(i_u);
|
size_t i = static_cast<size_t>(i_u);
|
||||||
|
|
||||||
const LogEntry* log_entry = &log_entries[i];
|
const LogEntry* log_entry = &log_entries[i];
|
||||||
|
struct tm tm;
|
||||||
char time_as_str[128] = {0};
|
char time_as_str[128] = {0};
|
||||||
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&log_entry->time));
|
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&log_entry->time, &tm));
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);
|
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);
|
||||||
|
|
|
@ -27,8 +27,9 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
|
||||||
while (clipper.Step()) {
|
while (clipper.Step()) {
|
||||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||||
const LogcatEntry* logcat_entry = &logcat_entries[filtered_logcat_entry_offsets[static_cast<size_t>(i)]];
|
const LogcatEntry* logcat_entry = &logcat_entries[filtered_logcat_entry_offsets[static_cast<size_t>(i)]];
|
||||||
|
struct tm tm;
|
||||||
char time_as_str[128] = {0};
|
char time_as_str[128] = {0};
|
||||||
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&logcat_entry->time));
|
strftime(time_as_str, 127 * sizeof(char), "%c", localtime_r(&logcat_entry->time, &tm));
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);
|
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);
|
||||||
|
|
Loading…
Reference in New Issue