Add method to count events by stack

We need this method to efficiently count events by stack to allow
pruning them if there are too many.

Change-Id: Ifd5ed78e37a14116497f8bc008739ee9938e194d
Related-Bug: #1209492
Merge "Add method to count events by stack"