gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita002ecb7a002ecb7|||PR records: HL25 report, heap helper, logmrea002ecb7/lib/heap.hl

1.9 KB

  1. // lib/heap.hl — TEMPORARY gitoria#25 diagnostic helper for GET /__heap (see project.hl): the keyed hl:heap snapshot of the long-lived state.
  2. import { Response } from 'hl:http1'
  3. import { readFile, tryReadFile } from 'hl:fs'
  4. import { timingSafeEqual } from 'hl:crypto'
  5. import { now } from 'hl:time'
  6. import { snapshot } from 'hl:heap'
  7. import { storageDir, NL } from './util.hl'
  8. import { hpCache, hpSize, hpOrder } from './homepage.hl'
  9. import { mdCache, mdSize, mdOrder } from './markdown.hl'
  10. import { counts as limitCounts } from './limits.hl'
  11. static notFound = () => {
  12. return new Response('not found', { status = 404 headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'Cache-Control' = 'no-store' } })
  13. }
  14. // 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)
  15. static kbOf = (String name, String status) => {
  16. for (l of status.split(NL)) {
  17. if (l.startsWith(name + ':')) {
  18. let digits = ''
  19. for (c of l.substring(name.length + 1).split('')) { if (c >= '0' && c <= '9') { digits = digits + c } }
  20. return toNumber(digits)
  21. }
  22. }
  23. return null
  24. }
  25. static heapReply = (routes, req, server) => {
  26. keyFile = tryReadFile(storageDir + '/../heap-key')
  27. if (keyFile == null) { return notFound() }
  28. key = keyFile.trim()
  29. given = req.headers['x-heap-key']
  30. if (key.length == 0 || given == null || !timingSafeEqual(key, given)) { return notFound() }
  31. 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) }
  32. rep = snapshot(&roots, 30)
  33. st = readFile('/proc/self/status')
  34. 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' } })
  35. }

Branches

Latest commits

  • 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
  • e3f85afblog: commit mention slipmre