gitoria
All repositories: gitoria
1.9 KB
// lib/heap.hl — TEMPORARY gitoria#25 diagnostic helper for GET /__heap (see project.hl): the keyed hl:heap snapshot of the long-lived state.import { Response } from 'hl:http1'import { readFile, tryReadFile } from 'hl:fs'import { timingSafeEqual } from 'hl:crypto'import { now } from 'hl:time'import { snapshot } from 'hl:heap'import { storageDir, NL } from './util.hl'import { hpCache, hpSize, hpOrder } from './homepage.hl'import { mdCache, mdSize, mdOrder } from './markdown.hl'import { counts as limitCounts } from './limits.hl'static notFound = () => {return new Response('not found', { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'Cache-Control' = 'no-store' } })}// the number in a /proc status line such as "VmRSS:\t 182340 kB" (digits only: the tab after the colon is not blank space for trim)static kbOf = (String name, String status) => {for (l of status.split(NL)) {if (l.startsWith(name + ':')) {let digits = ''for (c of l.substring(name.length + 1).split('')) { if (c >= '0' && c <= '9') { digits = digits + c } }return toNumber(digits)}}return null}static heapReply = (routes, req, server) => {keyFile = tryReadFile(storageDir + '/../heap-key')if (keyFile == null) { return notFound() }key = keyFile.trim()given = req.headers['x-heap-key']if (key.length == 0 || given == null || !timingSafeEqual(key, given)) { return notFound() }roots = { hpCache = hlShared(hpCache) hpSize = hlShared(hpSize) hpOrder = hlShared(hpOrder) mdCache = hlShared(mdCache) mdSize = hlShared(mdSize) mdOrder = hlShared(mdOrder) limitCounts = hlShared(limitCounts) sessions = hlShared(server.sessions) routes = hlShared(routes) }rep = snapshot(&roots, 30)st = readFile('/proc/self/status')return new Response(JSON.stringify({ time = now() rssKb = kbOf('VmRSS', st) hwmKb = kbOf('VmHWM', st) heap = rep }), { status = 200 headers = { 'Content-Type' = 'application/json' 'Cache-Control' = 'no-store' } })}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre
- 01b71c2edocs: neutral wording in missions, reports and logmre
- 3eeea733log: 2026-11-09 PR flow plan and membersmre
- e7c2ff1fdocs: neutral name for the apps-api reviewmre
- 120b7abdlog: step 3 queuedmre
- 358474bflog: P50 livemre
- 477d7bdcMerge branch 'p50'mre
- 00efc06fP50 reportmre