3434#include " absl/strings/str_cat.h"
3535
3636#include " cuttlefish/common/libs/fs/shared_fd.h"
37+ #include " cuttlefish/common/libs/utils/files.h"
3738#include " cuttlefish/host/commands/cvd/cli/commands/monitor/ansi_codes.h"
3839#include " cuttlefish/host/commands/cvd/cli/commands/monitor/display.h"
3940#include " cuttlefish/host/commands/cvd/cli/utils.h"
@@ -75,6 +76,9 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
7576 absl::StrCat (instance.InstanceDirectory (), " /logs/" , kLogNameLauncher );
7677 const std::string logcat =
7778 absl::StrCat (instance.InstanceDirectory (), " /logs/" , kLogNameLogcat );
79+ const std::string assemble_log =
80+ absl::StrCat (instance.AssemblyDirectory (), " /" , kLogNameAssembleCvd );
81+ bool using_assemble_log = true ;
7882
7983 SharedFD kernel_fd;
8084 SharedFD launcher_fd;
@@ -97,8 +101,28 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
97101 std::chrono::steady_clock::time_point ();
98102
99103 while (true ) {
104+ if (using_assemble_log) {
105+ if (FileExists (launcher_log)) {
106+ if (launcher_watch != -1 ) {
107+ inotify_fd->InotifyRmWatch (launcher_watch);
108+ launcher_watch = -1 ;
109+ }
110+ launcher_fd = SharedFD::Open (launcher_log, O_RDONLY );
111+ if (launcher_fd->IsOpen ()) {
112+ launcher_watch = inotify_fd->InotifyAddWatch (launcher_log, IN_MODIFY );
113+ using_assemble_log = false ;
114+ }
115+ } else if (!launcher_fd->IsOpen ()) {
116+ launcher_fd = SharedFD::Open (assemble_log, O_RDONLY );
117+ if (launcher_fd->IsOpen () && launcher_watch == -1 ) {
118+ launcher_watch = inotify_fd->InotifyAddWatch (assemble_log, IN_MODIFY );
119+ }
120+ }
121+ } else {
122+ UpdateFileAndWatch (inotify_fd, launcher_log, launcher_fd, launcher_watch);
123+ }
124+
100125 UpdateFileAndWatch (inotify_fd, kernel_log, kernel_fd, kernel_watch);
101- UpdateFileAndWatch (inotify_fd, launcher_log, launcher_fd, launcher_watch);
102126 UpdateFileAndWatch (inotify_fd, logcat, logcat_fd, logcat_watch);
103127
104128 const Result<TerminalSize> term_size_result = GetTerminalSize ();
@@ -108,7 +132,9 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
108132 }
109133 LogMonitorDisplay display (width);
110134
111- display.DrawFile (launcher_fd, kLogNameLauncher );
135+ display.DrawFile (launcher_fd,
136+ using_assemble_log ? kLogNameAssembleCvd
137+ : kLogNameLauncher );
112138 display.DrawFile (kernel_fd, kLogNameKernel );
113139 display.DrawFile (logcat_fd, kLogNameLogcat );
114140
@@ -136,11 +162,11 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
136162 }
137163
138164 // Block until file changes occur. If any watch failed or is missing, use
139- // a 1-second fallback timeout to awake and retry.
165+ // a fallback timeout to awake and retry.
140166 int timeout_ms = -1 ;
141167 if (dir_watch == -1 || kernel_watch == -1 || launcher_watch == -1 ||
142- logcat_watch == -1 ) {
143- timeout_ms = 1000 ;
168+ logcat_watch == -1 || using_assemble_log ) {
169+ timeout_ms = 200 ;
144170 }
145171
146172 int poll_res = SharedFD::Poll (poll_fds, timeout_ms);
0 commit comments