[Profiler][Minor] Set end time on python events when profiling stops. (#83621)
We don't have an end event for calls that are ongoing when profiling stops. (e.g. main) This cropped up when I was adding checks for negative durations.
I also refactored `populate` to use a pop method. This not only allows me to implement this fix, but should also provide a convenient entry point for https://github.com/pytorch/pytorch/pull/82154
Differential Revision: [D38426342](https://our.internmc.facebook.com/intern/diff/D38426342/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83621
Approved by: https://github.com/slgong-fb