This code is largely based on the work of Sherwood, Perelman, Hamerly and Calder, in their paper "Automatically Characterizing Large Scale Program Behavior", 2002. In that paper, they describe the algorithm for calculating distance metrics between phases of a serial executable. In this implementation, the phases are replaced by threads or events. Instead of comparing blocks of code to find phases of execution, the user can compare either threads or events. See the referenced paper for more details.