Skip to content

gh-160976: Preserve source file path in Gecko sampling collector - #160982

Open
makwana-akshat wants to merge 3 commits into
python:mainfrom
makwana-akshat:gh-160976-gecko-filename-path
Open

makwana-akshat wants to merge 3 commits into
python:mainfrom
makwana-akshat:gh-160976-gecko-filename-path

Conversation

@makwana-akshat

@makwana-akshat makwana-akshat commented Oct 30, 2026 •

Copy link
Copy Markdown

Fixes #160976.

Summary

The Gecko sampling profiler exporter used only the basename of Python source filenames, losing directory information when different files shared the same basename.

This PR:

  • Preserves the full source filename path in the Gecko function table.
  • Adds a regression test verifying that files with identical basenames in different directories retain distinct paths.
  • Adds a NEWS entry documenting the fix.

@python-cla-bot

python-cla-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@maurycy

maurycy commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

cc @ivonastojanovic ?

@ivonastojanovic ivonastojanovic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I’ve left a couple of nits.

One other thing I was wondering about is the resource name. _get_or_create_resource still uses the basename, so both files would show up as Resource: __init__.py in the profiler. Since Gecko resources are meant to group functions, for example by library or origin, would it make more sense to use the module name for the resource instead?

cc @pablogsal

self.assertGreater(stack_table["length"], 0)
self.assertGreater(len(stack_table["frame"]), 0)

def test_gecko_collector_preserves_source_file_paths(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could simplify this test quite a bit. Some of the assertions seem redundant, like checking the index types/ranges and that both the indices and strings are different. I think we could keep just the assertions that verify the behavior we actually care about here.

@@ -0,0 +1,2 @@
Fixed an issue in :mod:`profiling.sampling` where the Gecko exporter (``--gecko``)
only recorded source file basenames instead of preserving the source file path.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe a bit shorter, e.g. “The Gecko reporter (--gecko) in profiling.sampling now records full source file paths instead of only basenames.”

@makwana-akshat

makwana-akshat commented Nov 1, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review! I've simplified the regression test to focus on resolving each function's filename to the correct full source path and ensuring the two files are distinguished. I've also shortened the NEWS entry.

Regarding _get_or_create_resource(), I’ll keep that behavior unchanged in this PR so the fix stays focused on preserving source file paths in the function table. I agree that resource naming is worth considering separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

profiling.sampling (Tachyon) gecko output: Only source file basename is shown

3 participants