Skip to content

Commit 0ac8b7d

Browse files
authored
Merge pull request #495 from pythonspeed/492-fil-profiler-fails-for-fairly-large-dataset
Disable OOM on macOS
2 parents edfb9f3 + 704259f commit 0ac8b7d

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Release notes
2+
## 2023.3.0 (2023-3-1)
3+
4+
### Changes
5+
6+
* Out-of-memory detection is disabled for now on macOS, since it is prone to false positives.
27

38
## 2023.1.0 (2023-1-20)
49

docs/src/oom.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Debugging out-of-memory crashes using Fil
22

3+
> **Note:** Out-of-memory detection is currently disabled on macOS.
4+
> This [may change in a future release](https://github.com/pythonspeed/filprofiler/issues/494).
5+
36
Typically when your program runs out of memory, it will crash, or get killed mysteriously by the operating system, or [other unfortunate side-effects](https://pythonspeed.com/articles/python-out-of-memory/).
47

58
To help you debug these problems, Fil will heuristically try to catch out-of-memory conditions, and dump a report if thinks your program is out of memory.
69
It will then exit with exit code 53.
710

811
```console
9-
$ fil-profile run oom.py
12+
$ fil-profile run oom.py
1013
...
1114
=fil-profile= Wrote memory usage flamegraph to fil-result/2020-06-15T12:37:13.033/out-of-memory.svg
1215
```

filprofiler/_ipython.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tempfile import mkdtemp
99

1010
from IPython.core.magic import Magics, magics_class, cell_magic
11-
from IPython.display import IFrame, display
11+
from IPython.display import IFrame, display, HTML
1212

1313
from .api import profile
1414

@@ -66,4 +66,7 @@ def run_with_profile(code_to_profile):
6666
return profile(code_to_profile, tempdir)
6767
finally:
6868
svg_path = tempdir / "peak-memory.svg"
69-
display(IFrame(svg_path, width="100%", height="600"))
69+
if svg_path.exists():
70+
display(IFrame(svg_path, width="100%", height="600"))
71+
else:
72+
display(HTML("No report generated, perhaps zero memory was allocated."))

filprofiler/_script.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@
8787
PARSER.add_argument(
8888
"--disable-oom-detection",
8989
action="store_true",
90-
default=False,
91-
help="Disable the heuristic that tries to catch out-of-memory situations before they occur",
90+
default=True if sys.platform == "darwin" else False,
91+
help=(
92+
"Disable the heuristic that tries to catch out-of-memory situations before"
93+
"they occur. OOM detection is always disabled on macOS at the moment, see "
94+
"https://github.com/pythonspeed/filprofiler/issues/494"
95+
),
9296
)
9397
PARSER.add_argument(
9498
"--no-browser",
@@ -258,12 +262,18 @@ def stage_2():
258262
),
259263
)
260264

261-
msg_browser = ", and opened automatically in a browser" if not arguments.no_browser else ", and stored in {}.".format(arguments.output_path)
262-
msg_fil_plan = "=fil-profile= Memory usage will be written out at exit{}.\n".format(msg_browser)
265+
msg_browser = (
266+
", and opened automatically in a browser"
267+
if not arguments.no_browser
268+
else ", and stored in {}.".format(arguments.output_path)
269+
)
270+
msg_fil_plan = "=fil-profile= Memory usage will be written out at exit{}.\n".format(
271+
msg_browser
272+
)
263273
print(
264-
msg_fil_plan +
265-
"=fil-profile= You can also run the following command while the program is still running to write out peak memory usage up to that point: " +
266-
"kill -s SIGUSR2 {}".format(getpid()),
274+
msg_fil_plan
275+
+ "=fil-profile= You can also run the following command while the program is still running to write out peak memory usage up to that point: "
276+
+ "kill -s SIGUSR2 {}".format(getpid()),
267277
file=sys.stderr,
268278
)
269279
if not exists(arguments.output_path):

tests/test_endtoend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ def test_out_of_memory():
280280
)
281281

282282

283+
@pytest.mark.skipif(
284+
sys.platform.startswith("darwin"),
285+
reason="macOS doesn't have OOM detection at the moment",
286+
)
283287
def test_out_of_memory_slow_leak():
284288
"""
285289
If an allocation is run that runs out of memory slowly, current allocations are

0 commit comments

Comments
 (0)