What I do is that for every start, i push to the stack. But before pushing, I calculate the time it spent for the peek element.
For every end, i pop and compute time. And for the peek element, i update the start time as end time of it.
And you can also notice that log "start" and "end" is not needed to be added to stack. But it could be needed if CPU is not single thread.