On the Summary tab of Performance panel, total time taken by the browser for each category is displayed -
How are these times calculated? I referred to this SO answer as well as source code and can see that there are some events mapped to each category. I have Chrome performance trace dump and when I calculate the sum total of durations of these events for each category, the numbers don't match.
Can someone please help me with the calculation of these values? Or any other way to programmatically fetch them?

# Update 3
I fully rewrote my code, here's a better solution with comments.
Notes
https://example.com, there's no script on site, so scripting time would be 0