1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Summarize index mutations from the existing bounded atproto-bench capture."""
import collections
import hashlib
import json
import struct
import sys
from pathlib import Path
from atproto_core.cbor import decode_dag_multi
path = Path(sys.argv[1])
data = path.read_bytes()
count, = struct.unpack_from(">I", data)
position = 4
seen = set()
frames = collections.Counter()
ops = collections.Counter()
pairs_per_frame = collections.Counter()
novel_per_frame = collections.Counter()
times = []
for _ in range(count):
length, = struct.unpack_from(">I", data, position)
position += 4
raw = data[position:position + length]
assert len(raw) == length
position += length
header, payload = decode_dag_multi(raw)
frames[header.get("t", "other")] += 1
if header.get("t") != "#commit":
continue
if payload.get("time"):
times.append(payload["time"])
pairs, new = set(), set()
for op in payload.get("ops", []):
action = op.get("action")
ops[action] += 1
if action not in ("create", "update"):
continue
collection, slash, _ = op.get("path", "").partition("/")
if not slash or not collection:
continue
pair = (payload["repo"], collection)
pairs.add(pair)
if pair not in seen:
new.add(pair)
seen.add(pair)
pairs_per_frame[len(pairs)] += 1
novel_per_frame[len(new)] += 1
assert position == len(data)
print(json.dumps({
"file": path.name, "bytes": len(data), "sha256": hashlib.sha256(data).hexdigest(),
"frames": dict(frames), "ops": dict(ops), "unique_pairs": len(seen),
"distinct_pairs_per_commit": dict(sorted(pairs_per_frame.items())),
"new_pairs_per_commit_cold": dict(sorted(novel_per_frame.items())),
"first_time": min(times), "last_time": max(times),
}, indent=2))