Skip to content

Commit 7c8ce0c

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 89ed59c commit 7c8ce0c

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ 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) {
103104
std::vector<std::string> lines;
104105
if (fd->IsOpen()) {
105-
Result<std::vector<std::string>> lines_result = GetLastNLines(fd, 10);
106+
Result<std::vector<std::string>> lines_result =
107+
GetLastNLines(fd, max_lines);
106108
if (lines_result.ok()) {
107109
lines = *lines_result;
108110
} else {
@@ -120,7 +122,10 @@ void LogMonitorDisplay::DrawFile(SharedFD fd, const std::string& title) {
120122
lines.push_back(absl::StrCat("Error: ", fd->StrError()));
121123
}
122124

123-
while (lines.size() < 10) {
125+
if (lines.size() > max_lines) {
126+
lines.resize(max_lines);
127+
}
128+
while (lines.size() < max_lines) {
124129
lines.push_back("");
125130
}
126131

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: 26 additions & 6 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>
@@ -132,11 +133,30 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
132133
}
133134
LogMonitorDisplay display(width);
134135

135-
display.DrawFile(launcher_fd,
136-
using_assemble_log ? kLogNameAssembleCvd
137-
: kLogNameLauncher);
138-
display.DrawFile(kernel_fd, kLogNameKernel);
139-
display.DrawFile(logcat_fd, kLogNameLogcat);
136+
bool logcat_ready = false;
137+
if (logcat_fd->IsOpen() && logcat_fd->LSeek(0, SEEK_END) > 0) {
138+
logcat_ready = true;
139+
}
140+
141+
size_t total_content = 30;
142+
143+
if (using_assemble_log) {
144+
display.DrawFile(launcher_fd, kLogNameAssembleCvd, total_content);
145+
} else if (!kernel_fd->IsOpen()) {
146+
display.DrawFile(launcher_fd, kLogNameLauncher, total_content);
147+
} else if (!logcat_ready) {
148+
size_t launcher_lines = total_content / 3;
149+
size_t kernel_lines = total_content - launcher_lines;
150+
display.DrawFile(launcher_fd, kLogNameLauncher, launcher_lines);
151+
display.DrawFile(kernel_fd, kLogNameKernel, kernel_lines);
152+
} else {
153+
size_t launcher_lines = total_content / 3;
154+
size_t kernel_lines = total_content / 3;
155+
size_t logcat_lines = total_content - launcher_lines - kernel_lines;
156+
display.DrawFile(launcher_fd, kLogNameLauncher, launcher_lines);
157+
display.DrawFile(kernel_fd, kLogNameKernel, kernel_lines);
158+
display.DrawFile(logcat_fd, kLogNameLogcat, logcat_lines);
159+
}
140160

141161
const auto [output, total_lines_drawn] = display.Finalize();
142162
std::cout << output << std::flush;
@@ -165,7 +185,7 @@ Result<void> MonitorLogs(const LocalInstance& instance, SharedFD stop_eventfd) {
165185
// a fallback timeout to awake and retry.
166186
int timeout_ms = -1;
167187
if (dir_watch == -1 || kernel_watch == -1 || launcher_watch == -1 ||
168-
logcat_watch == -1 || using_assemble_log) {
188+
logcat_watch == -1 || !logcat_ready || using_assemble_log) {
169189
timeout_ms = 200;
170190
}
171191

0 commit comments

Comments
 (0)