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"
@@ -47,7 +48,9 @@ namespace {
4748void UpdateFileAndWatch (const SharedFD& inotify_fd, const std::string& path,
4849 SharedFD& fd, int & watch) {
4950 if (!fd->IsOpen ()) {
50- fd = SharedFD::Open (path, O_RDONLY );
51+ if (FileExists (path)) {
52+ fd = SharedFD::Open (path, O_RDONLY );
53+ }
5154 }
5255 if (fd->IsOpen () && watch == -1 ) {
5356 watch = inotify_fd->InotifyAddWatch (path, IN_MODIFY );
@@ -75,6 +78,9 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
7578 absl::StrCat (instance.InstanceDirectory (), " /logs/" , kLogNameLauncher );
7679 const std::string logcat =
7780 absl::StrCat (instance.InstanceDirectory (), " /logs/" , kLogNameLogcat );
81+ const std::string assemble_log =
82+ absl::StrCat (instance.AssemblyDirectory (), " /" , kLogNameAssembleCvd );
83+ bool using_assemble_log = true ;
7884
7985 SharedFD kernel_fd;
8086 SharedFD launcher_fd;
@@ -97,8 +103,33 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
97103 std::chrono::steady_clock::time_point ();
98104
99105 while (true ) {
106+ if (using_assemble_log) {
107+ if (FileExists (launcher_log)) {
108+ if (launcher_watch != -1 ) {
109+ inotify_fd->InotifyRmWatch (launcher_watch);
110+ launcher_watch = -1 ;
111+ }
112+ launcher_fd = SharedFD::Open (launcher_log, O_RDONLY );
113+ if (launcher_fd->IsOpen ()) {
114+ launcher_watch = inotify_fd->InotifyAddWatch (launcher_log, IN_MODIFY );
115+ using_assemble_log = false ;
116+ }
117+ } else if (!launcher_fd->IsOpen ()) {
118+ if (FileExists (assemble_log)) {
119+ launcher_fd = SharedFD::Open (assemble_log, O_RDONLY );
120+ if (launcher_fd->IsOpen ()) {
121+ if (launcher_watch == -1 ) {
122+ launcher_watch =
123+ inotify_fd->InotifyAddWatch (assemble_log, IN_MODIFY );
124+ }
125+ }
126+ }
127+ }
128+ } else {
129+ UpdateFileAndWatch (inotify_fd, launcher_log, launcher_fd, launcher_watch);
130+ }
131+
100132 UpdateFileAndWatch (inotify_fd, kernel_log, kernel_fd, kernel_watch);
101- UpdateFileAndWatch (inotify_fd, launcher_log, launcher_fd, launcher_watch);
102133 UpdateFileAndWatch (inotify_fd, logcat, logcat_fd, logcat_watch);
103134
104135 const Result<TerminalSize> term_size_result = GetTerminalSize ();
@@ -108,7 +139,8 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
108139 }
109140 LogMonitorDisplay display (width);
110141
111- display.DrawFile (launcher_fd, kLogNameLauncher );
142+ display.DrawFile (launcher_fd, using_assemble_log ? kLogNameAssembleCvd
143+ : kLogNameLauncher );
112144 display.DrawFile (kernel_fd, kLogNameKernel );
113145 display.DrawFile (logcat_fd, kLogNameLogcat );
114146
@@ -136,11 +168,11 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
136168 }
137169
138170 // Block until file changes occur. If any watch failed or is missing, use
139- // a 1-second fallback timeout to awake and retry.
171+ // a fallback timeout to awake and retry.
140172 int timeout_ms = -1 ;
141173 if (dir_watch == -1 || kernel_watch == -1 || launcher_watch == -1 ||
142- logcat_watch == -1 ) {
143- timeout_ms = 1000 ;
174+ logcat_watch == -1 || using_assemble_log ) {
175+ timeout_ms = 200 ;
144176 }
145177
146178 int poll_res = SharedFD::Poll (poll_fds, timeout_ms);
0 commit comments