Skip to content

Commit b66a87c

Browse files
committed
profile: update related to fluidfft-builder 0.0.3
1 parent 4e2f7db commit b66a87c

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

fluidsim/util/console/profile.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
from time import time
99
from pathlib import Path
10+
from warnings import warn
1011

1112
import pstats
1213
import cProfile
@@ -154,18 +155,15 @@ def _profile(type_fft):
154155

155156
try:
156157
run_profile(sim, nb_dim, path_dir, verbose=verbose)
157-
except Exception as e:
158+
except Exception:
158159
if _is_testing:
159160
raise
160161

161162
else:
162-
print(
163-
"WARNING: Some error occurred while running benchmark"
164-
" / saving results!"
163+
warn(
164+
"Some error occurred while running benchmark / saving results!"
165165
)
166166
raise
167-
168-
print(e)
169167
finally:
170168
tear_down(sim)
171169
gc.collect()
@@ -359,50 +357,53 @@ def analyze_stats(
359357
times = {k: 0.0 for k in kinds}
360358

361359
for key, value in stats.stats.items():
360+
path_src = key[0]
362361
name = key[2]
363362
time = value[2]
363+
category_chosen = None
364+
365+
for category in kinds:
366+
if category in name or category in path_src:
367+
if category == ".py" and (
368+
not path_src.endswith(category)
369+
or os.path.sep + "numpy" in path_src
370+
or "fft_as_arg" in name
371+
):
372+
continue
364373

365-
for k in kinds:
366-
if k in name or k in key[0]:
367-
if k == ".pyx":
368-
if "fft/Sources" in key[0]:
369-
continue
370-
371-
if "fft_as_arg" in name:
374+
if category == ".pyx":
375+
if "fft/Sources" in path_src or "fft_as_arg" in name:
372376
continue
373377

374-
if k == key_fft:
378+
if category == key_fft:
375379
if (
376380
"__pythran__" in name
377-
or "operators.py" in key[0]
381+
or "operators.py" in path_src
378382
or "fft_as_arg" in name
383+
or "fft" not in name
379384
):
380385
continue
381386

382-
callers = value[4]
383-
384-
time = 0
385-
for kcaller, vcaller in callers.items():
386-
if (
387-
"fft_as_arg" not in kcaller[2]
388-
and "fft_as_arg" not in kcaller[0]
389-
):
390-
time += vcaller[2]
391-
392-
if k == "fft_as" and ".pyx" in key[0]:
387+
if category == "built-in" and (
388+
"pythran" in name or "numpy" in name
389+
):
393390
continue
394391

395-
if k == ".py" and "fft_as_arg" in name:
396-
continue
397-
398-
if k == "built-in" and "pythran" in name:
399-
continue
400-
401-
times[k] += time
402-
403392
if time / total_time > threshold_long_function:
404393
long_functions[name] = dict(
405-
time=time, percentage=100 * time / total_time, kind=k
394+
time=time,
395+
percentage=100 * time / total_time,
396+
kind=category,
397+
)
398+
times[category] += time
399+
400+
if category_chosen is None:
401+
category_chosen = category
402+
else:
403+
warn(
404+
f"problem in analysis: function {name} has "
405+
f"previously been chosen as '{category_chosen}'"
406+
f"and is now chosen as '{category}'.\n{key = }\n{value = }"
406407
)
407408

408409
if plot:
@@ -428,10 +429,12 @@ def analyze_stats(
428429
keys = list(times.keys())
429430
keys.sort(key=lambda key: times[key], reverse=True)
430431

431-
for k in keys:
432-
t = times[k]
432+
for category in keys:
433+
t = times[category]
433434
if t > 0:
434-
print(f"time {k:10s}: {t / total_time * 100:7.03f} % ({t:4.02f} s)")
435+
print(
436+
f"time {category:10s}: {t / total_time * 100:7.03f} % ({t:4.02f} s)"
437+
)
435438

436439
print(
437440
"-" * 26

0 commit comments

Comments
 (0)