This commit is contained in:
parent
c33239ee76
commit
64cc990e19
2 changed files with 31 additions and 1 deletions
28
src/components/MemoryUsage.jsx
Normal file
28
src/components/MemoryUsage.jsx
Normal 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>
|
||||||
|
);
|
||||||
|
};
|
|
@ -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>
|
||||||
);
|
);
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue