MCPcopy
hub / github.com/docling-project/docling / main

Function main

perfs/plot_memory_metrics.py:112–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110
111
112def main() -> None:
113 args = parse_args()
114 if not args.input_file.is_file():
115 raise SystemExit(f"Input file does not exist: {args.input_file}")
116
117 try:
118 import matplotlib.pyplot as plt
119 except ImportError as exc:
120 raise SystemExit(
121 "Plotting requires matplotlib. Install it in the environment first."
122 ) from exc
123
124 loaded_runs = []
125 for label, metrics_file in _resolve_metrics_files(args.input_file):
126 if not metrics_file.is_file():
127 raise SystemExit(f"Metrics file does not exist: {metrics_file}")
128 total_pages, loaded_metrics = load_points(metrics_file)
129 if total_pages:
130 loaded_runs.append((label, total_pages, loaded_metrics))
131
132 if not loaded_runs:
133 raise SystemExit(f"No plotable data found in {args.input_file}")
134
135 fig, ax = plt.subplots(1, 1, figsize=(12, 6))
136
137 for label, total_pages, loaded_metrics in loaded_runs:
138 point_count = min(
139 [len(total_pages)] + [len(values) for values in loaded_metrics.values()]
140 )
141 x_values = total_pages[:point_count]
142
143 for key in MEMORY_KEYS:
144 series = loaded_metrics[key][:point_count]
145 if all(value != value for value in series):
146 continue
147 metric_label = key.replace("_mb", "").upper()
148 ax.plot(
149 x_values,
150 series,
151 label=f"{label} {metric_label}",
152 linewidth=1.5,
153 )
154
155 ax.set_xlabel("Total page number")
156 ax.set_ylabel("Memory (MiB)")
157 ax.set_title("Memory at page loaded")
158 ax.grid(True, alpha=0.3)
159 ax.legend()
160 fig.tight_layout()
161
162 args.output.parent.mkdir(parents=True, exist_ok=True)
163 fig.savefig(args.output, dpi=150)
164 print(f"Wrote plot to {args.output}")
165
166
167if __name__ == "__main__":

Callers 1

Calls 4

_resolve_metrics_filesFunction · 0.85
load_pointsFunction · 0.85
replaceMethod · 0.80
parse_argsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…