Compare commits

...

3 Commits

Author SHA1 Message Date
blankie 1c44b770a8
Don't show logcat exit code if there's any request 2023-02-03 12:01:19 +07:00
blankie 04c46e220f
Use localtime_r 2023-02-03 11:59:51 +07:00
blankie 9e73720525
Remove debug print 2023-02-03 11:57:12 +07:00
4 changed files with 10 additions and 10 deletions

View File

@ -16,8 +16,9 @@ LogEntry::LogEntry(time_t time_, std::string message_) : time(time_), message(st
std::string format_log(const LogEntry& entry) {
struct tm tm;
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;
}

View File

@ -159,9 +159,6 @@ void LogcatThread::_put_if_not_stopped(LogcatThreadItem item) {
if (this->atomic_ring_buffer.try_put_and_increment_write(item)) {
break;
}
#ifndef NDEBUG
printf("spinlocking!!!\n");
#endif
if (this->_stop_source.stop_requested()) {
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 res = waitpid(this->_logcat_pid, &wstatus, WNOHANG);
if (res == -1) {
@ -259,13 +256,13 @@ void LogcatThread::_try_reap(bool stop_requested) {
this->logcat_process_running.clear();
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))};
print_log(log_entry);
this->_put_if_not_stopped(std::move(log_entry));
}
} 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))};
print_log(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) {
this->_try_reap(request == LogcatProcessRequest::Stop);
this->_try_reap(request != LogcatProcessRequest::None);
}
return task_done;

View File

@ -22,8 +22,9 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) {
size_t i = static_cast<size_t>(i_u);
const LogEntry* log_entry = &log_entries[i];
struct tm tm;
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();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);

View File

@ -27,8 +27,9 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
while (clipper.Step()) {
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; 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};
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();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted(time_as_str);