Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
# #region FullFlow.FinanceBrowserMemory [C:3] [TYPE Module] [SEMANTICS fixture,diagnostic,memory,readonly]
|
|
# @BRIEF Sample numeric browser heap/DOM and owned process RSS without inspecting objects or credentials.
|
|
# @INVARIANT CDP is observation-only with1s bounds; process inspection excludes argv/environment.
|
|
import asyncio
|
|
import os
|
|
import subprocess
|
|
|
|
|
|
# #region FullFlow.FinanceBrowserMemory.Processes [C:3] [TYPE Function]
|
|
# @POST Only this diagnostic process's descendant PID/PPID/RSS/CPU/comm statistics are returned.
|
|
def processes():
|
|
result = subprocess.run(['ps','-eo','pid,ppid,rss,pcpu,comm','--no-headers'],capture_output=True,text=True,timeout=1)
|
|
records = {}
|
|
for line in result.stdout.splitlines():
|
|
fields = line.split(maxsplit=4)
|
|
if len(fields)==5:
|
|
records[int(fields[0])] = {'pid':int(fields[0]),'ppid':int(fields[1]),'rss_kib':int(fields[2]),
|
|
'cpu_percent':float(fields[3]),'comm':fields[4]}
|
|
owned = {os.getpid()}
|
|
while True:
|
|
added = {pid for pid,row in records.items() if row['ppid'] in owned}-owned
|
|
if not added:
|
|
break
|
|
owned |= added
|
|
return [row for pid,row in records.items() if pid in owned][:512]
|
|
# #endregion FullFlow.FinanceBrowserMemory.Processes
|
|
|
|
|
|
# #region FullFlow.FinanceBrowserMemory.Rpc [C:2] [TYPE Function]
|
|
# @POST A renderer that cannot answer yields unavailable; no probing deadline is extended.
|
|
async def rpc(cdp, method):
|
|
try:
|
|
return await asyncio.wait_for(cdp.send(method),timeout=1)
|
|
except Exception:
|
|
return {'unavailable':True}
|
|
# #endregion FullFlow.FinanceBrowserMemory.Rpc
|
|
|
|
|
|
# #region FullFlow.FinanceBrowserMemory.Sample [C:2] [TYPE Function]
|
|
# @POST Numeric heap usage and DOM/listener counts accompany local RSS even if one renderer RPC fails.
|
|
async def sample(cdp):
|
|
heap,dom = await asyncio.gather(rpc(cdp,'Runtime.getHeapUsage'),rpc(cdp,'Memory.getDOMCounters'))
|
|
try:
|
|
owned = processes()
|
|
except (ValueError,subprocess.SubprocessError):
|
|
owned = []
|
|
return {'heap':heap,'dom':dom,'processes':owned,'total_rss_kib':sum(row['rss_kib'] for row in owned)}
|
|
# #endregion FullFlow.FinanceBrowserMemory.Sample
|
|
# #endregion FullFlow.FinanceBrowserMemory
|