pyinstrument icon indicating copy to clipboard operation
pyinstrument copied to clipboard

Would it be possible to show the class name in the results ?

Open altimore opened this issue 4 years ago • 2 comments

Hello,

First many thanks for the work you put in this tool, it was the one i was dreaming of.

I'm using it to find bottlenecks in Django applications.

In this case i got multiple classes having a method called get_total(), would it be possible to display the class name to differentiate the different get_total() functions like Invoice.get_total(), InvoiceLine.get_total() or InvoiceQuerySet.get_total() in the results instead of just get_total. It would be more convenient than having to check which is which in the source file during the reading.

Regards,

Alti.

altimore avatar Feb 09 '21 08:02 altimore

Yes, this would be really nice. It's not something that is naturally available via the native Python frame interface but I think it's possible to 'guess' by looking at the type of an argument called self in the scope of the function. We'd have to be a little careful not to make it too slow, but I think there should be a way.

If you or somebody else is interested in working on a PR, the place to try adding it would be https://github.com/joerick/pyinstrument/blob/master/pyinstrument/profiler.py#L93, adding it to the first token in the identifier :)

joerick avatar Apr 03 '21 22:04 joerick

Hi there,

Reference from the above comment is outdated, as code has changed over time, this one has commit hash: https://github.com/joerick/pyinstrument/blob/568f2b78fb34e455420d3da5925c5f51734b0c79/pyinstrument/profiler.py#L93-L95

I created PR #154 that might be a possible solution.

@joerick thanks again for the great instrument!

naspeh avatar Oct 06 '21 13:10 naspeh

This now works in v4.4.0!

joerick avatar Nov 05 '22 12:11 joerick