| 701 | } |
| 702 | |
| 703 | void LogcatThread::Tick() |
| 704 | { |
| 705 | // adb is extremely unreliable, so although it supposedly contains functionality to filter for |
| 706 | // everything after a certain timestamp, this can actually drop messages. Instead we just always |
| 707 | // grab the last 750 lines and hope that the device doesn't ever peak over 1 line per millisecond |
| 708 | // such that we'd miss something. Note another joy of adb - the line count is applied *before* |
| 709 | // the filter, so if something else spams 1000 lines we won't see our own. |
| 710 | const uint32_t lineBacklog = 750; |
| 711 | |
| 712 | // logcat |
| 713 | // -t N // always the last N messages, and (implied -d) stop after doing so |
| 714 | // -v brief // print the 'brief' format |
| 715 | // -s // silence everything as a default |
| 716 | // renderdoc:* // print logcats from our tag. |
| 717 | // libc:* // or from libc (prints crash messages) |
| 718 | // DEBUG:* // or from DEBUG (prints crash messages) |
| 719 | // |
| 720 | // This gives us all messages from renderdoc since the last timestamp. |
| 721 | rdcstr command = |
| 722 | StringFormat::Fmt("logcat -t %u -v brief -s renderdoc:* libc:* DEBUG:*", lineBacklog); |
| 723 | |
| 724 | rdcstr logcat = Android::adbExecCommand(deviceID, command, ".", true).strStdout.trimmed(); |
| 725 | |
| 726 | rdcarray<rdcstr> lines; |
| 727 | split(logcat, lines, '\n'); |
| 728 | |
| 729 | // remove \n from any lines right now to prevent it breaking further processing |
| 730 | for(rdcstr &line : lines) |
| 731 | if(!line.empty() && line.back() == '\r') |
| 732 | line.pop_back(); |
| 733 | |
| 734 | // only do any processing if we had a line last time that we know to start from. |
| 735 | if(!lastLogcatLine.empty()) |
| 736 | { |
| 737 | int idx = lines.indexOf(lastLogcatLine); |
| 738 | |
| 739 | if(idx >= 0) |
| 740 | { |
| 741 | // remove everything up to and including that line |
| 742 | lines.erase(0, idx + 1); |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | RDCWARN("Couldn't find last line. Potentially missed logcat messages."); |
| 747 | } |
| 748 | |
| 749 | for(const rdcstr &line : lines) |
| 750 | { |
| 751 | LogLine logline; |
| 752 | |
| 753 | if(logline.parse(line)) |
| 754 | { |
| 755 | rdclog_direct(logline.timestamp, logline.pid, logline.logtype, "ADRD", |
| 756 | logline.filename.c_str(), logline.line_number, "%s", logline.message.c_str()); |
| 757 | rdclog_flush(); |
| 758 | } |
| 759 | } |
| 760 | } |
no test coverage detected