Skip to content

Commit f39a2e7

Browse files
committed
Implement phased dynamic screen layout sizing in cvd monitor
When running cvd monitor (or cvd start --daemon=false), the UI layout dynamically apportions a constant 30-line content budget based on exactly which runtime logs are actively open and populated: - Phase 1 (Only assemble log ready): Takes 100% of vertical content space. - Phase 2 (Only launcher log ready): Takes 100% of vertical content space. - Phase 3 (launcher and kernel logs ready): launcher log takes the top 1/3, and kernel log takes the bottom 2/3 of vertical content space. - Phase 4 (All 3 logs fully populated): When logcat starts writing messages, all three logs are displayed equally (10 lines each) across the screen. Assisted-by: Jetski:gemini-2.5-pro Bug: b/519304405 TAG=agy CONV=34ddc7b8-a695-4937-be99-b796087dd987
1 parent d83a7e8 commit f39a2e7

3 files changed

Lines changed: 37 additions & 9 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/display.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ LogMonitorDisplay::LogMonitorDisplay(size_t width)
9999
total_lines_drawn_(0),
100100
colorize_(ShouldColorizeOutput(1)) {}
101101

102-
void LogMonitorDisplay::DrawFile(SharedFD fd, const std::string& title) {
102+
void LogMonitorDisplay::DrawFile(SharedFD fd, const std::string& title,
103+
size_t max_lines) {
104+
if (max_lines == 0) {
105+
return;
106+
}
103107
std::vector<std::string> lines;
104108
if (fd->IsOpen()) {
105-
Result<std::vector<std::string>> lines_result = GetLastNLines(fd, 10);
109+
Result<std::vector<std::string>> lines_result =
110+
GetLastNLines(fd, max_lines);
106111
if (lines_result.ok()) {
107112
lines = *lines_result;
108113
} else {
@@ -120,7 +125,10 @@ void LogMonitorDisplay::DrawFile(SharedFD fd, const std::string& title) {
120125
lines.push_back(absl::StrCat("Error: ", fd->StrError()));
121126
}
122127

123-
while (lines.size() < 10) {
128+
if (lines.size() > max_lines) {
129+
lines.resize(max_lines);
130+
}
131+
while (lines.size() < max_lines) {
124132
lines.push_back("");
125133
}
126134

base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class LogMonitorDisplay {
6666
* within a bordered box titled with the provided name.
6767
* If the file cannot be read, an error box is drawn instead.
6868
*/
69-
void DrawFile(SharedFD fd, const std::string& title);
69+
void DrawFile(SharedFD fd, const std::string& title, size_t max_lines = 10);
7070

7171
/**
7272
* Appends the final bottom border to the display and returns the

base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/monitor.cc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <errno.h>
2020
#include <fcntl.h>
21+
#include <stdio.h>
2122
#include <sys/eventfd.h>
2223
#include <sys/inotify.h>
2324
#include <sys/poll.h>
@@ -139,10 +140,29 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
139140
}
140141
LogMonitorDisplay display(width);
141142

142-
display.DrawFile(launcher_fd, using_assemble_log ? kLogNameAssembleCvd
143-
: kLogNameLauncher);
144-
display.DrawFile(kernel_fd, kLogNameKernel);
145-
display.DrawFile(logcat_fd, kLogNameLogcat);
143+
bool logcat_ready = false;
144+
if (logcat_fd->IsOpen() && logcat_fd->LSeek(0, SEEK_END) > 0) {
145+
logcat_ready = true;
146+
}
147+
148+
size_t total_content = 30;
149+
150+
const std::string launcher_name =
151+
using_assemble_log ? kLogNameAssembleCvd : kLogNameLauncher;
152+
size_t launcher_lines = total_content;
153+
size_t kernel_lines = 0;
154+
size_t logcat_lines = 0;
155+
if (kernel_fd->IsOpen()) {
156+
launcher_lines = total_content / 3;
157+
kernel_lines = total_content - launcher_lines;
158+
}
159+
if (logcat_ready) {
160+
kernel_lines = total_content / 3;
161+
logcat_lines = total_content - launcher_lines - kernel_lines;
162+
}
163+
display.DrawFile(launcher_fd, launcher_name, launcher_lines);
164+
display.DrawFile(kernel_fd, kLogNameKernel, kernel_lines);
165+
display.DrawFile(logcat_fd, kLogNameLogcat, logcat_lines);
146166

147167
const auto [output, total_lines_drawn] = display.Finalize();
148168
std::cout << output << std::flush;
@@ -171,7 +191,7 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
171191
// a fallback timeout to awake and retry.
172192
int timeout_ms = -1;
173193
if (dir_watch == -1 || kernel_watch == -1 || launcher_watch == -1 ||
174-
logcat_watch == -1 || using_assemble_log) {
194+
logcat_watch == -1 || !logcat_ready || using_assemble_log) {
175195
timeout_ms = 200;
176196
}
177197

0 commit comments

Comments
 (0)