forked from defunkt/toes
Consolidate perfTiming state into a single perf object
Removes the separate variable and setter in favor of a plain object, making the mutable state easier to track and eliminating a needless abstraction.
This commit is contained in:
parent
b9f94a6c98
commit
9a19c0a861
|
|
@ -1,5 +1,5 @@
|
||||||
import { allApps, APPS_DIR, onChange } from '$apps'
|
import { allApps, APPS_DIR, onChange } from '$apps'
|
||||||
import { perfTiming, setPerfTiming } from '../proxy'
|
import { perf } from '../proxy'
|
||||||
import { onHostLog } from '../tui'
|
import { onHostLog } from '../tui'
|
||||||
import { Hype } from '@because/hype'
|
import { Hype } from '@because/hype'
|
||||||
import { cpus, freemem, platform, totalmem } from 'os'
|
import { cpus, freemem, platform, totalmem } from 'os'
|
||||||
|
|
@ -278,22 +278,22 @@ function pushHostLog(text: string) {
|
||||||
for (const listener of unifiedLogListeners) listener(line)
|
for (const listener of unifiedLogListeners) listener(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perf timing toggle
|
||||||
|
router.get('/perf', c => c.json({ perfTiming: perf.timing }))
|
||||||
|
router.post('/perf', async c => {
|
||||||
|
const body = await c.req.json<{ on?: boolean }>().catch(() => ({}))
|
||||||
|
const on = body.on ?? !perf.timing
|
||||||
|
perf.timing = on
|
||||||
|
console.log(`[perf] timing ${on ? 'enabled' : 'disabled'}`)
|
||||||
|
return c.json({ perfTiming: on })
|
||||||
|
})
|
||||||
|
|
||||||
// Subscribe to app changes to collect logs
|
// Subscribe to app changes to collect logs
|
||||||
onChange(collectLogs)
|
onChange(collectLogs)
|
||||||
|
|
||||||
// Subscribe to host-level log messages
|
// Subscribe to host-level log messages
|
||||||
onHostLog(pushHostLog)
|
onHostLog(pushHostLog)
|
||||||
|
|
||||||
// Perf timing toggle
|
|
||||||
router.get('/perf', c => c.json({ perfTiming }))
|
|
||||||
router.post('/perf', async c => {
|
|
||||||
const body = await c.req.json<{ on?: boolean }>().catch(() => ({}))
|
|
||||||
const on = body.on ?? !perfTiming
|
|
||||||
setPerfTiming(on)
|
|
||||||
console.log(`[perf] timing ${on ? 'enabled' : 'disabled'}`)
|
|
||||||
return c.json({ perfTiming: on })
|
|
||||||
})
|
|
||||||
|
|
||||||
// Restart server (systemd brings it back)
|
// Restart server (systemd brings it back)
|
||||||
router.post('/restart', c => {
|
router.post('/restart', c => {
|
||||||
setTimeout(() => process.exit(0), 100)
|
setTimeout(() => process.exit(0), 100)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@ import { getAppBySubdomain } from '$apps'
|
||||||
|
|
||||||
export type { WsData }
|
export type { WsData }
|
||||||
|
|
||||||
export let perfTiming = false
|
export const perf = { timing: false }
|
||||||
|
|
||||||
export const setPerfTiming = (on: boolean) => { perfTiming = on }
|
|
||||||
|
|
||||||
const pendingMessages = new Map<ServerWebSocket<WsData>, (string | ArrayBuffer | Uint8Array)[]>()
|
const pendingMessages = new Map<ServerWebSocket<WsData>, (string | ArrayBuffer | Uint8Array)[]>()
|
||||||
const upstreams = new Map<ServerWebSocket<WsData>, WebSocket>()
|
const upstreams = new Map<ServerWebSocket<WsData>, WebSocket>()
|
||||||
|
|
@ -64,7 +62,7 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise<R
|
||||||
body,
|
body,
|
||||||
redirect: 'manual',
|
redirect: 'manual',
|
||||||
})
|
})
|
||||||
if (perfTiming) {
|
if (perf.timing) {
|
||||||
const ms = (performance.now() - start).toFixed(1)
|
const ms = (performance.now() - start).toFixed(1)
|
||||||
console.log(`[perf] ${req.method} ${subdomain}${url.pathname} → ${res.status} in ${ms}ms`)
|
console.log(`[perf] ${req.method} ${subdomain}${url.pathname} → ${res.status} in ${ms}ms`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user