joerick/pyinstrument

`FileNotFoundError` when calling profile.output_text

gerrymanoim opened this issue · 2 comments

Apologies - I'm having trouble making a minimal reproducible example for this issue, but here's what I'm seeing:

In certain situations, when trying to render pyinstrument output as text I get a FileNotFoundError. In post mortem debugging the stack looks like:

-> ] = profile.output_text(unicode=True, color=True)
  <python path>/pyinstrument/profiler.py(295)output_text()
-> return self.output(
  <python path>/pyinstrument/profiler.py(323)output()
-> return renderer.render(session)
  <python path>/pyinstrument/renderers/console.py(51)render()
-> result += self.render_frame(self.root_frame)
  <python path>/pyinstrument/renderers/console.py(137)render_frame()
-> result += self.render_frame(child, indent=c_indent, child_indent=cc_indent)
  <python path>/pyinstrument/renderers/console.py(137)render_frame()
-> result += self.render_frame(child, indent=c_indent, child_indent=cc_indent)
  <python path>/pyinstrument/renderers/console.py(137)render_frame()
-> result += self.render_frame(child, indent=c_indent, child_indent=cc_indent)
  <python path>/pyinstrument/renderers/console.py(118)render_frame()
-> libraries=truncate(", ".join(frame.group.libraries), 40),
> <python path>/pyinstrument/frame.py(349)libraries()
-> if frame.file_path_short:
  <python path>/pyinstrument/frame.py(160)file_path_short()
-> candidate = os.path.relpath(self.file_path, path)
  <python path>/python3.9/posixpath.py(473)relpath()
-> path_list = [x for x in abspath(path).split(sep) if x]
  <python path>/python3.9/posixpath.py(380)abspath()
-> cwd = os.getcwd()

So, I don't entirely understand why os.getcwd() is failing but I don't think that's due to pyinstrument.

What is maybe strange to me is the Frame triggering the issue looks like:

Frame(identifier=Int64HashTable.factorize<built-in>0, time=0.002000, len(children)=0), group=FrameGroup(len(frames)=29)

And if I look on https://github.com/joerick/pyinstrument/blob/main/pyinstrument/frame.py#L160,

(Pdb) self.file_path
'<built-in>'
(Pdb) self._identifier_parts
['Int64HashTable.factorize', '<built-in>', '0']

Which makes me think that pyinstrument shouldn't be trying loop through sys.path and immediately set self._file_path_short = None. Is that the intended behavior here?

Behaviour here might have changed recently, we no longer try to resolve against sys.path for paths like <built-in>. It may well be fixed. Would you mind trying again?

Closing due to inactivity. Feel free to reopen if you can reproduce!