feat(lab4): private S3 attachments and safe storage reconciliation
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""20 ms cgroup-v2 memory sampler; stop by EOF on stdin. No privileged access."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import threading
|
||||
import time
|
||||
|
||||
done = threading.Event()
|
||||
def wait():
|
||||
import sys
|
||||
sys.stdin.read()
|
||||
done.set()
|
||||
threading.Thread(target=wait,daemon=True).start()
|
||||
root = Path('/sys/fs/cgroup')
|
||||
def read(name):
|
||||
path = root/name
|
||||
return int(path.read_text()) if path.exists() else None
|
||||
def rss():
|
||||
lines = Path('/proc/1/status').read_text().splitlines()
|
||||
return int(next(x.split()[1] for x in lines if x.startswith('VmRSS:')))*1024
|
||||
baseline = read('memory.current')
|
||||
peak_before = read('memory.peak')
|
||||
peak = baseline
|
||||
rss_peak = rss()
|
||||
samples = 0
|
||||
start = time.monotonic()
|
||||
while not done.is_set():
|
||||
peak = max(peak,read('memory.current'))
|
||||
rss_peak = max(rss_peak,rss())
|
||||
samples += 1
|
||||
done.wait(0.02)
|
||||
print(json.dumps(dict(baseline_bytes=baseline,sampled_peak_bytes=peak,
|
||||
kernel_lifetime_peak_before_bytes=peak_before,kernel_lifetime_peak_after_bytes=read('memory.peak'),
|
||||
api_rss_peak_bytes=rss_peak,sample_count=samples,interval_seconds=0.02,
|
||||
elapsed_seconds=time.monotonic()-start)))
|
||||
Reference in New Issue
Block a user