Skip to content

Commit 41f825f

Browse files
committed
frontend/qmd+rmd: tweak build log output and show peak memory usage
1 parent 882d19d commit 41f825f

File tree

2 files changed

+94
-12
lines changed

2 files changed

+94
-12
lines changed

src/packages/frontend/frame-editors/qmd-editor/build-log.tsx

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
STYLE_PRE,
2020
} from "../rmd-editor/styles";
2121
import { getResourceUsage } from "../rmd-editor/utils";
22+
import { COLORS } from "@cocalc/util/theme";
2223

2324
interface BuildLogProps {
2425
name: string;
@@ -59,7 +60,8 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo((props) => {
5960
if (status && build_log !== shownLog) {
6061
setShownLog(build_log);
6162
if (logContainerRef.current) {
62-
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight;
63+
logContainerRef.current.scrollTop =
64+
logContainerRef.current.scrollHeight;
6365
}
6466
}
6567
}, [build_log, status, shownLog]);
@@ -169,12 +171,20 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo((props) => {
169171

170172
if (status) {
171173
return (
172-
<div ref={logContainerRef} style={STYLE_OUTER}>
174+
<div
175+
style={{
176+
...STYLE_OUTER,
177+
display: "flex",
178+
flexDirection: "column",
179+
height: "100%",
180+
}}
181+
>
173182
<div
174183
style={{
175184
margin: "10px",
176185
fontWeight: "bold",
177186
fontSize: `${font_size}px`,
187+
flexShrink: 0,
178188
}}
179189
>
180190
Running Quarto ...
@@ -184,7 +194,16 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo((props) => {
184194
"last",
185195
)}
186196
</div>
187-
{body()}
197+
<div
198+
ref={logContainerRef}
199+
style={{
200+
flex: 1,
201+
overflow: "auto",
202+
minHeight: 0,
203+
}}
204+
>
205+
{body()}
206+
</div>
188207
</div>
189208
);
190209
} else if (!build_log && !build_err) {
@@ -198,7 +217,31 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo((props) => {
198217
</div>
199218
);
200219
} else {
201-
return <div style={STYLE_OUTER}>{body()}</div>;
220+
// Execution completed - show peak resource usage if available
221+
const peakResourceUsage = job_info_raw
222+
? getResourceUsage(
223+
(job_info_raw?.toJS ? job_info_raw.toJS() : job_info_raw).stats,
224+
"peak",
225+
)
226+
: "";
227+
228+
return (
229+
<div style={STYLE_OUTER}>
230+
{peakResourceUsage && (
231+
<div
232+
style={{
233+
margin: "10px",
234+
fontWeight: "bold",
235+
fontSize: `${font_size}px`,
236+
color: COLORS.GRAY_M,
237+
}}
238+
>
239+
Build completed.{peakResourceUsage}
240+
</div>
241+
)}
242+
{body()}
243+
</div>
244+
);
202245
}
203246
});
204247

src/packages/frontend/frame-editors/rmd-editor/build-log.tsx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo(
5454
if (status && build_log !== shownLog) {
5555
setShownLog(build_log);
5656
if (logContainerRef.current) {
57-
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight;
57+
logContainerRef.current.scrollTop =
58+
logContainerRef.current.scrollHeight;
5859
}
5960
}
6061
}, [build_log, status, shownLog]);
@@ -173,24 +174,62 @@ export const BuildLog: React.FC<BuildLogProps> = React.memo(
173174
</div>
174175
);
175176
} else {
176-
return (
177-
<div ref={status ? logContainerRef : undefined} style={STYLE_OUTER}>
178-
{status && (
177+
if (status) {
178+
return (
179+
<div
180+
style={{
181+
...STYLE_OUTER,
182+
display: "flex",
183+
flexDirection: "column",
184+
height: "100%",
185+
}}
186+
>
179187
<div
180188
style={{
181189
margin: "10px",
182190
fontWeight: "bold",
183191
fontSize: `${font_size}px`,
192+
flexShrink: 0,
184193
}}
185194
>
186195
Running rmarkdown::render ...
187196
<br />
188197
{stats && getResourceUsage(stats, "last")}
189198
</div>
190-
)}
191-
{body()}
192-
</div>
193-
);
199+
<div
200+
ref={logContainerRef}
201+
style={{
202+
flex: 1,
203+
overflow: "auto",
204+
minHeight: 0,
205+
}}
206+
>
207+
{body()}
208+
</div>
209+
</div>
210+
);
211+
} else {
212+
// Execution completed - show peak resource usage if available
213+
const peakResourceUsage = stats ? getResourceUsage(stats, "peak") : "";
214+
215+
return (
216+
<div style={STYLE_OUTER}>
217+
{peakResourceUsage && (
218+
<div
219+
style={{
220+
margin: "10px",
221+
fontWeight: "bold",
222+
fontSize: `${font_size}px`,
223+
color: "#666",
224+
}}
225+
>
226+
Build completed.{peakResourceUsage}
227+
</div>
228+
)}
229+
{body()}
230+
</div>
231+
);
232+
}
194233
}
195234
},
196235
);

0 commit comments

Comments
 (0)