add memory usage
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Narongpol Kijrangsan 2025-03-01 00:46:58 -05:00
parent c33239ee76
commit 64cc990e19
2 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,28 @@
import React, { useState, useEffect } from "react";
import { Typography } from "@material-ui/core";
export const MemoryUsage = () => {
const [memoryUsage, setMemoryUsage] = useState("Loading...");
useEffect(() => {
function updateMemoryUsage() {
if (performance.memory) {
const memoryInfo = performance.memory;
const usedMB = (memoryInfo.usedJSHeapSize / 1024 / 1024).toFixed(2);
setMemoryUsage(`Used: ${usedMB} MB`);
} else {
setMemoryUsage("Memory info not supported in this browser.");
}
}
const interval = setInterval(updateMemoryUsage, 1000);
return () => clearInterval(interval); // Cleanup on unmount
}, []);
return (
<Typography color="textPrimary" component="div">
<h2>Client-Side Memory Usage</h2>
<p style={{ fontSize: "1.2em", fontWeight: "bold" }}>{memoryUsage}</p>
</Typography>
);
};

View file

@ -3,6 +3,7 @@ import { Grid, Typography } from "@material-ui/core";
import { MenuItem } from "./MenuItem"; import { MenuItem } from "./MenuItem";
import { MenuSection } from "./MenuSection"; import { MenuSection } from "./MenuSection";
import { ThemeToggle } from "./ThemeToggle"; import { ThemeToggle } from "./ThemeToggle";
import { MemoryUsage } from "./MemoryUsage";
export const OtherControls = props => { export const OtherControls = props => {
return ( return (
@ -17,6 +18,7 @@ export const OtherControls = props => {
<ThemeToggle /> <ThemeToggle />
</Grid> </Grid>
</MenuItem> </MenuItem>
<MemoryUsage />
</MenuSection> </MenuSection>
); );
}; };