Skip to content

Commit adc9eb7

Browse files
committed
fixup! pythongh-100403: Collect GC statistics when --enable-pystats is provided
1 parent bfbf366 commit adc9eb7

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

Tools/scripts/generate_gc_stats_plots.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,43 @@ def get_obj_percentage_data(df):
88
gen_data = []
99
for generation in range(3):
1010
vals = df[df["generation_number"] == generation]
11-
gen_data.append((vals["collected_cycles"] / vals["total_objects"]).values)
11+
item = vals["collected_cycles"] / vals["total_objects"].values
12+
if item.size == 0:
13+
item = np.array([0])
14+
gen_data.append(item)
1215
return gen_data
1316

1417

1518
def get_gen_time_data(df):
1619
gen_data = []
1720
for generation in range(3):
1821
vals = df[df["generation_number"] == generation]
19-
gen_data.append(vals["collection_time"])
22+
item = vals["collection_time"].values
23+
if item.size == 0:
24+
item = np.array([0])
25+
gen_data.append(item)
2026
return gen_data
2127

2228

2329
def get_gen_time_data_per_obj(df):
2430
gen_data = []
2531
for generation in range(3):
2632
vals = df[df["generation_number"] == generation]
27-
gen_data.append(vals["collection_time"] / vals["total_objects"])
33+
item = vals["collection_time"] / vals["total_objects"].values
34+
if item.size == 0:
35+
item = np.array([0])
36+
gen_data.append(item)
2837
return gen_data
2938

39+
def get_gen_freq_per_us(df):
40+
gen_data = []
41+
for generation in range(3):
42+
vals = df[df["generation_number"] == generation]
43+
item = 1.0 / (vals["collection_time"] / vals["total_objects"]).values / 1.0e6
44+
if item.size == 0:
45+
item = np.array([0])
46+
gen_data.append(item)
47+
return gen_data
3048

3149
def gen_plot(df, output_filename):
3250
def violinplot_with_custom_formatting(
@@ -49,8 +67,8 @@ def violinplot_with_custom_formatting(
4967
ax.set_title(title)
5068

5169
names = ["First generation", "Second generation", "Third generation"]
52-
fig, (ax1, ax2, ax3) = plt.subplots(
53-
3, 1, figsize=(8, (2 + len(names) * 0.3) * 3), layout="constrained"
70+
fig, (ax1, ax2, ax3, ax4) = plt.subplots(
71+
4, 1, figsize=(8, (2 + len(names) * 0.3) * 4), layout="constrained"
5472
)
5573

5674
obj_percentage_data = get_obj_percentage_data(df)
@@ -89,6 +107,18 @@ def violinplot_with_custom_formatting(
89107
formatter=formatter,
90108
)
91109

110+
formatter = lambda val, pos: f"{int(val)}obj/us"
111+
gen_freq_per_us = get_gen_freq_per_us(df)
112+
violinplot_with_custom_formatting(
113+
ax4,
114+
gen_freq_per_us,
115+
names,
116+
(0, len(names) + 1),
117+
"time",
118+
"Objects collected per us stats",
119+
formatter=formatter,
120+
)
121+
92122
plt.savefig(output_filename)
93123
plt.close()
94124

0 commit comments

Comments
 (0)