mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Compare commits
2 Commits
v0.1
...
mh-experim
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93e7c79752 | ||
|
|
9d20cd6304 |
36
bin/sarif-size
Executable file
36
bin/sarif-size
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python
|
||||
import orjson
|
||||
import sys
|
||||
|
||||
def sizeof(x):
|
||||
t = type(x)
|
||||
if t is dict:
|
||||
return sum(len(k) + sizeof(v) for k, v in x.items())
|
||||
if t is list:
|
||||
return sum(sizeof(v) for v in x)
|
||||
if t is str:
|
||||
return len(x)
|
||||
return 8 # numbers, bools, null
|
||||
|
||||
def walk(x, path="root"):
|
||||
if isinstance(x, dict):
|
||||
yield path, sizeof(x)
|
||||
for k,v in x.items():
|
||||
yield from walk(v, f"{path}.{k}")
|
||||
elif isinstance(x, list):
|
||||
yield path, sizeof(x)
|
||||
for i,v in enumerate(x):
|
||||
yield from walk(v, f"{path}[{i}]")
|
||||
|
||||
# with open(sys.stdin, 'rb') as f:
|
||||
# data_bytes = f.read()
|
||||
|
||||
data_bytes = sys.stdin.buffer.read()
|
||||
|
||||
parsed_data = orjson.loads(data_bytes)
|
||||
|
||||
sizes = sorted(walk(parsed_data), key=lambda kv: kv[1], reverse=True)
|
||||
for p, s in sizes[:50]:
|
||||
print(f"{s:10d} {p}")
|
||||
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
appnope==0.1.2
|
||||
argon2-cffi==21.3.0
|
||||
argon2-cffi-bindings==21.2.0
|
||||
asttokens==2.0.5
|
||||
attrs==21.4.0
|
||||
backcall==0.2.0
|
||||
beautifulsoup4==4.10.0
|
||||
bleach==4.1.0
|
||||
cffi==1.15.0
|
||||
debugpy==1.5.1
|
||||
decorator==5.1.1
|
||||
defusedxml==0.7.1
|
||||
@@ -51,7 +48,7 @@ pyparsing==3.0.7
|
||||
pyrsistent==0.18.1
|
||||
python-dateutil==2.8.2
|
||||
pytz==2021.3
|
||||
PyYAML==6.0
|
||||
PyYAML
|
||||
pyzmq
|
||||
qtconsole==5.2.2
|
||||
QtPy==2.0.1
|
||||
|
||||
Reference in New Issue
Block a user