|
37 | 37 | ]
|
38 | 38 |
|
39 | 39 | # TODO: Make this list an option
|
40 |
| -OF_INTEREST_NAMES = [x for x in opcode.opname if not x.startswith("<")] |
41 |
| -OF_INTEREST_NAMES = ["BINARY_ADD", "BINARY_SUBTRACT", |
42 |
| - "INPLACE_ADD", "INPLACE_SUBTRACT"] |
| 40 | +CACHE_ENTRIES = { |
| 41 | + "LOAD_GLOBAL": 2, |
| 42 | + "LOAD_ATTR": 2, |
| 43 | + "CALL_FUNCTION": 2, |
| 44 | + "CALL_FUNCTION_KW": 2, |
| 45 | + "CALL_FUNCTION_EX": 2, # Unsure |
| 46 | + "CALL_METHOD": 2, |
| 47 | + "CALL_METHOD_KW": 2, |
| 48 | +} |
| 49 | +OF_INTEREST_NAMES = CACHE_ENTRIES.keys() |
43 | 50 |
|
44 |
| -of_interest = set(opcode.opmap[x] for x in OF_INTEREST_NAMES) |
| 51 | +of_interest = set(opcode.opmap[x] for x in OF_INTEREST_NAMES if x in opcode.opmap) |
45 | 52 |
|
46 | 53 |
|
47 | 54 | def all_code_objects(code):
|
@@ -165,6 +172,8 @@ def expand_globs(filenames):
|
165 | 172 | help="show N most common opcode pairs")
|
166 | 173 | argparser.add_argument("--bias", type=int,
|
167 | 174 | help="Add bias for opcodes inside for-loops")
|
| 175 | +argparser.add_argument("--cache-needs", action="store_true", |
| 176 | + help="Show fraction of cache entries needed per opcode ") |
168 | 177 | argparser.add_argument("filenames", nargs="*", metavar="FILE",
|
169 | 178 | help="files, directories or tarballs to count")
|
170 | 179 |
|
@@ -223,6 +232,21 @@ def main():
|
223 | 232 | npairs = counter[NPAIRS]
|
224 | 233 | print(f"Total: {showstats(counter)}")
|
225 | 234 |
|
| 235 | + if args.cache_needs: |
| 236 | + print() |
| 237 | + print("Future cache needs") |
| 238 | + ncache = 0 |
| 239 | + for key in counter: |
| 240 | + if key in of_interest: |
| 241 | + name = opcode.opname[key] |
| 242 | + need = CACHE_ENTRIES[name] * counter[key] |
| 243 | + ncache += need |
| 244 | + print(name, need) |
| 245 | + nops = counter[NOPCODES] |
| 246 | + print(f"{nops} opcodes, {2*nops} bytes,", |
| 247 | + f"{ncache} cache entries, {8*ncache} bytes,", |
| 248 | + f"{ncache/nops:.2f} ncache/nops") |
| 249 | + |
226 | 250 | if args.singles:
|
227 | 251 | singles = []
|
228 | 252 | for key in counter:
|
|
0 commit comments