MCPcopy Index your code
hub / github.com/python/cpython / load_raw_data

Function load_raw_data

Tools/scripts/summarize_stats.py:81–117  ·  view source on GitHub ↗
(input: Path)

Source from the content-addressed store, hash-verified

79
80
81def load_raw_data(input: Path) -> RawData:
82 if input.is_file():
83 with open(input, "r") as fd:
84 data = json.load(fd)
85
86 data["_stats_defines"] = {int(k): v for k, v in data["_stats_defines"].items()}
87 data["_defines"] = {int(k): v for k, v in data["_defines"].items()}
88
89 return data
90
91 elif input.is_dir():
92 stats = collections.Counter[str]()
93
94 for filename in input.iterdir():
95 with open(filename) as fd:
96 for line in fd:
97 try:
98 key, value = line.split(":")
99 except ValueError:
100 print(
101 f"Unparsable line: '{line.strip()}' in {filename}",
102 file=sys.stderr,
103 )
104 continue
105 # Hack to handle older data files where some uops
106 # are missing an underscore prefix in their name
107 if key.startswith("uops[") and key[5:6] != "_":
108 key = "uops[_" + key[5:]
109 stats[key.strip()] += int(value)
110 stats["__nfiles__"] += 1
111
112 data = dict(stats)
113 data.update(_load_metadata_from_source())
114 return data
115
116 else:
117 raise ValueError(f"{input} is not a file or directory path")
118
119
120def save_raw_data(data: RawData, json_output: TextIO):

Callers 1

output_statsFunction · 0.85

Calls 11

openFunction · 0.50
is_fileMethod · 0.45
loadMethod · 0.45
itemsMethod · 0.45
is_dirMethod · 0.45
iterdirMethod · 0.45
splitMethod · 0.45
stripMethod · 0.45
startswithMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…