pcdshub / pcdshub/pcdsutils

pcdsutils.profile add_function call can be noisy

Open
#72 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2
Forks
6
Avg merge
7d 11h
Merged PRs (30d)
1

Description

Issue

This line:
https://github.com/pcdshub/pcdsutils/blob/57a863002cfa7799d09056b3eebdaa8e02203f09/pcdsutils/profile.py#L156

Can result in hundreds of warnings when used with wrapped functions/methods:

happi/tests/test_cli.py: 48 warnings
  /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/pcdsutils/profile.py:156: UserWarning: Adding a function with a __wrapped__ attribute. You may want to profile the wrapped function by adding happi_cfg_abs.__wrapped__ instead.
    profiler_to_setup.add_function(function)

We should probably use warning capturing to ignore this specific warning (memory is probably faulty regarding UserWarning and the ability to ignore it so I won't suggest a full fix here)

Alternatively, we can heed the warning and profile the inner function by default. I'm not sold that it's the correct way of doing things, though.

Reference

The warning comes from here: https://github.com/pyutils/line_profiler/blob/c48f643e0fd44335705bfb48fe78995c72ecd858/line_profiler/_line_profiler.pyx#L211-L217

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect pcdsutils/profile.py around line 156 and the warning source referenced in line_profiler. Reproduce the noisy warning using the scenario shown from happi/tests/test_cli.py, then verify that profiling wrapped functions no longer emits repeated instances of this specific warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.