fix sleeve memory bug

This commit is contained in:
Olivier Gagnon
2021-09-08 23:47:34 -04:00
parent bada8a5f39
commit 2a13db39c7
360 changed files with 5424 additions and 15764 deletions
+3 -4
View File
@@ -24,10 +24,9 @@ export class ActiveScriptsRoot extends React.Component<IProps> {
return (
<>
<p>
This page displays a list of all of your scripts that are currently
running across every machine. It also provides information about each
script's production. The scripts are categorized by the hostname of
the servers on which they are running.
This page displays a list of all of your scripts that are currently running across every machine. It also
provides information about each script's production. The scripts are categorized by the hostname of the
servers on which they are running.
</p>
<ScriptProduction {...this.props} />
+2 -4
View File
@@ -14,13 +14,11 @@ type IProps = {
};
export function ScriptProduction(props: IProps): React.ReactElement {
const prodRateSinceLastAug =
props.p.scriptProdSinceLastAug / (props.p.playtimeSinceLastAug / 1000);
const prodRateSinceLastAug = props.p.scriptProdSinceLastAug / (props.p.playtimeSinceLastAug / 1000);
let onlineProduction = 0;
for (const ws of props.workerScripts.values()) {
onlineProduction +=
ws.scriptRef.onlineMoneyMade / ws.scriptRef.onlineRunningTime;
onlineProduction += ws.scriptRef.onlineMoneyMade / ws.scriptRef.onlineRunningTime;
}
return (
+5 -6
View File
@@ -23,9 +23,10 @@ export function ServerAccordion(props: IProps): React.ReactElement {
// Accordion's header text
// TODO: calculate the longest hostname length rather than hard coding it
const longestHostnameLength = 18;
const paddedName = `${server.hostname}${" ".repeat(
longestHostnameLength,
)}`.slice(0, Math.max(server.hostname.length, longestHostnameLength));
const paddedName = `${server.hostname}${" ".repeat(longestHostnameLength)}`.slice(
0,
Math.max(server.hostname.length, longestHostnameLength),
);
const barOptions = {
progress: server.ramUsed / server.maxRam,
totalTicks: 30,
@@ -35,9 +36,7 @@ export function ServerAccordion(props: IProps): React.ReactElement {
return (
<Accordion
headerContent={<pre>{headerTxt}</pre>}
panelContent={
<ServerAccordionContent workerScripts={props.workerScripts} />
}
panelContent={<ServerAccordionContent workerScripts={props.workerScripts} />}
/>
);
}
@@ -11,32 +11,24 @@ interface IProps {
export function ServerAccordionContent(props: IProps): React.ReactElement {
if (props.workerScripts.length > pageSize) {
return (
<ServerAccordionContentPaginated workerScripts={props.workerScripts} />
);
return <ServerAccordionContentPaginated workerScripts={props.workerScripts} />;
}
const scripts = props.workerScripts.map((ws) => {
return (
<WorkerScriptAccordion key={`${ws.name}_${ws.args}`} workerScript={ws} />
);
return <WorkerScriptAccordion key={`${ws.name}_${ws.args}`} workerScript={ws} />;
});
return <ul>{scripts}</ul>;
}
export function ServerAccordionContentPaginated(
props: IProps,
): React.ReactElement {
export function ServerAccordionContentPaginated(props: IProps): React.ReactElement {
const [page, setPage] = useState(0);
const scripts: React.ReactElement[] = [];
const maxPage = Math.ceil(props.workerScripts.length / pageSize);
const maxScript = Math.min((page + 1) * pageSize, props.workerScripts.length);
for (let i = page * pageSize; i < maxScript; i++) {
const ws = props.workerScripts[i];
scripts.push(
<WorkerScriptAccordion key={`${ws.name}_${ws.args}`} workerScript={ws} />,
);
scripts.push(<WorkerScriptAccordion key={`${ws.name}_${ws.args}`} workerScript={ws} />);
}
function capPage(page: number): number {
+1 -7
View File
@@ -90,13 +90,7 @@ export class ServerAccordions extends React.Component<IProps, IState> {
render(): React.ReactNode {
const elems = Object.keys(this.serverToScriptMap).map((serverName) => {
const data = this.serverToScriptMap[serverName];
return (
<ServerAccordion
key={serverName}
server={data.server}
workerScripts={data.workerScripts}
/>
);
return <ServerAccordion key={serverName} server={data.server} workerScripts={data.workerScripts} />;
});
return (
+10 -47
View File
@@ -27,11 +27,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
const scriptRef = workerScript.scriptRef;
const logClickHandler = logBoxCreate.bind(null, scriptRef);
const killScript = killWorkerScript.bind(
null,
scriptRef as any,
scriptRef.server,
);
const killScript = killWorkerScript.bind(null, scriptRef as any, scriptRef.server);
function killScriptClickHandler(): void {
killScript();
@@ -51,62 +47,29 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
panelClass="active-scripts-script-panel"
panelContent={
<>
<pre>
Threads:{" "}
{numeralWrapper.formatThreads(props.workerScript.scriptRef.threads)}
</pre>
<pre>Threads: {numeralWrapper.formatThreads(props.workerScript.scriptRef.threads)}</pre>
<pre>Args: {arrayToString(props.workerScript.args)}</pre>
<pre>
Online Time:{" "}
{convertTimeMsToTimeElapsedString(
scriptRef.onlineRunningTime * 1e3,
)}
</pre>
<pre>
Offline Time:{" "}
{convertTimeMsToTimeElapsedString(
scriptRef.offlineRunningTime * 1e3,
)}
</pre>
<pre>Online Time: {convertTimeMsToTimeElapsedString(scriptRef.onlineRunningTime * 1e3)}</pre>
<pre>Offline Time: {convertTimeMsToTimeElapsedString(scriptRef.offlineRunningTime * 1e3)}</pre>
<pre>
Total online production: <Money money={scriptRef.onlineMoneyMade} />
</pre>
<pre>
{Array(26).join(" ") +
numeralWrapper.formatExp(scriptRef.onlineExpGained) +
" hacking exp"}
</pre>
<pre>{Array(26).join(" ") + numeralWrapper.formatExp(scriptRef.onlineExpGained) + " hacking exp"}</pre>
<pre>
Online production rate: <Money money={onlineMps} /> / second
</pre>
<pre>{Array(25).join(" ") + numeralWrapper.formatExp(onlineEps) + " hacking exp / second"}</pre>
<pre>
{Array(25).join(" ") +
numeralWrapper.formatExp(onlineEps) +
" hacking exp / second"}
</pre>
<pre>
Total offline production:{" "}
<Money money={scriptRef.offlineMoneyMade} />
</pre>
<pre>
{Array(27).join(" ") +
numeralWrapper.formatExp(scriptRef.offlineExpGained) +
" hacking exp"}
Total offline production: <Money money={scriptRef.offlineMoneyMade} />
</pre>
<pre>{Array(27).join(" ") + numeralWrapper.formatExp(scriptRef.offlineExpGained) + " hacking exp"}</pre>
<pre>
Offline production rate: <Money money={offlineMps} /> / second
</pre>
<pre>
{Array(26).join(" ") +
numeralWrapper.formatExp(offlineEps) +
" hacking exp / second"}
</pre>
<pre>{Array(26).join(" ") + numeralWrapper.formatExp(offlineEps) + " hacking exp / second"}</pre>
<AccordionButton onClick={logClickHandler} text="Log" />
<AccordionButton
onClick={killScriptClickHandler}
text="Kill Script"
/>
<AccordionButton onClick={killScriptClickHandler} text="Kill Script" />
</>
}
/>