Created
November 9, 2020 18:24
-
-
Save smowton/fda08630673e82ac47baef764cc0d4c8 to your computer and use it in GitHub Desktop.
extcalls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import collections | |
import json | |
import sys | |
if len(sys.argv) < 2 or sys.argv[1] not in ["projects", "calls"]: | |
print("Usage: extcalls.py projects|calls [limit]", file = sys.stderr) | |
sys.exit(1) | |
limit = int(sys.argv[2]) if len(sys.argv) >= 3 else None | |
data = json.load(sys.stdin) | |
rows = [] | |
for projectblock in data: | |
project = projectblock["name"] | |
results = projectblock["results"] | |
for result in results: | |
callee_report = result[3]["value"] | |
callee = callee_report[len("Call to ") : callee_report.find(" with untrusted")] | |
rows.append((project, callee)) | |
def count_dups(l, unique): | |
result = collections.defaultdict(int) | |
seen = set() | |
for rec in l: | |
if unique: | |
if rec in seen: | |
continue | |
seen.add(rec) | |
result[rec[1]] += 1 | |
return sorted(result.items(), key = lambda keyval: keyval[1], reverse = True) | |
aggregated = count_dups(rows, sys.argv[1] == "projects") | |
if limit is not None: | |
aggregated = aggregated[:limit] | |
for (fname, num) in aggregated: | |
print("%s,%d" % (fname, num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment