Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop built-in code showing as 'None' in traces #254

Merged
merged 2 commits into from
Jul 22, 2023
Merged

Stop built-in code showing as 'None' in traces #254

merged 2 commits into from
Jul 22, 2023

Conversation

joerick
Copy link
Owner

@joerick joerick commented Jul 12, 2023

Fixes #252.

The issue here was a simple coding error, self.line_no was 0 so it was falling back as you said @mattip. I decided to keep the if as it was, though, since a line_no of 0 is still invalid, line numbers start at 1, but it will fallback to just the file_path_short, if it's available.

@mattip
Copy link
Contributor

mattip commented Jul 13, 2023

Profiling the code from the issue now shows this, which is better but still has ../<builtin> which is strange

1.020 <module>  profile.py:1
└─ 1.020 A  profile.py:16
   ├─ 0.704 D  profile.py:3
   │  └─ 0.704 sleep  ../<built-in>
   │        [2 frames hidden]  ..
   └─ 0.316 sleep  ../<built-in>
         [2 frames hidden]  ..

@mattip
Copy link
Contributor

mattip commented Jul 13, 2023

I think ../<built-in> is coming from the logic in frame.file_path_short. It should have a fast-path for self.file_path == "<built-in>".

@joerick
Copy link
Owner Author

joerick commented Jul 13, 2023

Weirdly I don't see this .. issue, how do you invoke pyinstrument to get this?

Though I think your solution sounds right.

@mattip
Copy link
Contributor

mattip commented Jul 13, 2023

Using this python on macOS

%  python
Python 3.10.10 (v3.10.10:aad5f6a891, Feb  7 2023, 08:47:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin

I create a venv

python -m venv /tmp/venv3

then install pyinstrument with pip install -e .. I put the script in /tmp/profile.py then run

% python -m pyinstrument /tmp/profile.py

If I stop inside frame.file_path_short, I don't see '' in sys.path, so the shortest relpath does not start with '', rather with '..'

@joerick
Copy link
Owner Author

joerick commented Jul 13, 2023

Weird.... I get

$ python -m pyinstrument /tmp/profile.py

  _     ._   __/__   _ _  _  _ _/_   Recorded: 19:13:42  Samples:  5
 /_//_/// /_\ / //_// / //_'/ //     Duration: 1.020     CPU time: 0.003
/   _/                      v4.5.0

Program: /tmp/profile.py

1.018 <module>  profile.py:1
└─ 1.018 A  profile.py:16
   ├─ 0.704 D  profile.py:3
   │  └─ 0.704 sleep  <built-in>
   │        [2 frames hidden]  <built-in>
   └─ 0.314 sleep  <built-in>
         [2 frames hidden]  <built-in>

To view this report with different options, run:
    pyinstrument --load-prev 2023-07-13T19-13-42 [options]

I'm on python 3.10.7, on mac.

@joerick
Copy link
Owner Author

joerick commented Jul 13, 2023

Are you on homebrew python? could that be the difference?

@joerick
Copy link
Owner Author

joerick commented Jul 13, 2023

Ah, I managed to recreate it, by using a venv in a different directory

$ python -m pyinstrument /tmp/profile.py 

  _     ._   __/__   _ _  _  _ _/_   Recorded: 19:18:10  Samples:  4
 /_//_/// /_\ / //_// / //_'/ //     Duration: 1.019     CPU time: 0.001
/   _/                      v4.5.0

Program: /tmp/profile.py

1.019 <module>  profile.py:1
└─ 1.019 A  profile.py:16
   ├─ 0.703 D  profile.py:3
   │  └─ 0.703 sleep  ../Users/joerick/Projects/pyinstrument/<built-in>
   │        [2 frames hidden]  ..
   └─ 0.315 sleep  ../Users/joerick/Projects/pyinstrument/<built-in>
         [2 frames hidden]  ..

To view this report with different options, run:
    pyinstrument --load-prev 2023-07-13T19-18-10 [options]

@joerick joerick merged commit 6c60d1a into main Jul 22, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

functions like time.sleep are reported as "sleep None"
2 participants