2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Upload attachment memory-json.py

Petr Špaček
2023-09-14 13:59:04 +00:00
parent 2d9f01af2f
commit bbf111c12f

@@ -0,0 +1,82 @@
#!/usr/bin/env python3
import sys
import json
with open(sys.argv[1], "r") as f:
data = json.load(f)
totals = {}
# support for XML transcoding using xq < stats.xml > stats.json
if "statistics" in data:
data = data["statistics"]
data["memory"]["contexts"] = data["memory"]["contexts"]["context"]
for key in data["memory"]["summary"]:
data["memory"][key] = data["memory"]["summary"][key]
for context in data["memory"]["contexts"]:
if "name" in context:
name = context["name"]
else:
name = "<unknown>"
inuse = int(context["inuse"])
malloced = int(context["malloced"])
if name[0:3] == "res":
name = "res"
if name[0:4] == "loop":
name = "loop"
if name in totals:
totals[name]["inuse"] += inuse
totals[name]["malloced"] += malloced
else:
totals[name] = {"inuse": inuse, "malloced": malloced}
sum = {"inuse": 0, "malloced": 0}
def human_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
def fmt(num):
o = None
s = f"{num}"
while len(s) > 3:
if o is None:
o = f"{s[-3:]}"
else:
o = f"{s[-3:]}.{o}"
s = s[:-3]
if len(s) > 0:
if o is None:
o = f"{s[-3:]}"
else:
o = f"{s[-3:]}.{o}"
return o
for name in totals:
inuse = totals[name]["inuse"]
malloced = totals[name]["malloced"]
sum["inuse"] += inuse
sum["malloced"] += malloced
print(f"{name}: {human_fmt(inuse)} {human_fmt(malloced)}")
inuse = int(data["memory"]["InUse"])
malloced = int(data["memory"]["Malloced"])
print("SUMMARY")
print(f"INUSE: {human_fmt(sum['inuse'])} == {human_fmt(inuse)}")
print(f"MALLOCED: {human_fmt(sum['malloced'])} == {human_fmt(malloced)}")