-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pyinstrument grouping is incorrect #19
Comments
This might be to do with the cross-class function calls in the codebase, and how the function which sets off the population level events is called?
So the population level events are being run by So I guess PyInstrumment is technically right that the pop-level events are run within the scheduler class, though I'd now expect the population-level events to be nested within |
I don't think that's right. For example, the event HealthSeekingBehaviourPoll is not an HSI event, and is not run by the HealthSystem. It is processed in the main Simulation event loop, so I'd expect it to be under Simulation.fire_single_event. |
I've looked in to this a bit and think I've identified what is going on. The key issue seems to be that the class name used in the identifier for a frame corresponding to a method call will be written out as a particular subclass (specifically the mostly commonly observed subclass in the captured frames) even if the method being called is defined on a base class. As a simple minimal reproducer, consider the following script corresponding to a very simplified version of the import time
def simulate():
time.sleep(0.1)
events = [EventA(), EventB(), EventA()] * 10
for event in events:
event.run()
class Event:
def run(self):
self.apply()
class EventA(Event):
def apply(self):
time.sleep(0.1)
class EventB(Event):
def apply(self):
time.sleep(0.1)
if __name__ == "__main__":
simulate() Running
Here we see that underneath the top-level This seems like a bug to me or at least is a bit misleading so I'll raise an issue on Importantly it does seem however the overall call tree recorded is correct and if we just look at the file / line number references in the existing output we can correctly identify whether methods are actually defined. |
Accidentally hit close while writing comment 🤦 |
Not sure whether this can be fixed or corrected at all - probably not - but I noticed that the indentation of samples in the pyinstrument output is incorrect. Regular events are being placed as if they are being run by the health system scheduler. Any ideas?
The text was updated successfully, but these errors were encountered: