• Chris Toshok's avatar
    add StatTimer, a lightweight cpu tick timer · addbe087
    Chris Toshok authored
    Each thread has a stack of timers (which should have automatic scope.)  pushing a timer
    onto the stack pauses the currently running one to avoid double counting, and popping a
    timer resumes the previous one.
    
    also make sure we pause the current timer, and swap out the current stack of timers when
    swapping to/from generator stacks, since otherwise pushes/pops won't line up and we hit
    asserts in StatTimer.
    
    Timers and StatTimers accumulate their durations in terms of CPU ticks, which are converted
    to microseconds only at Stats::dump() time, calculated with our estimate of CPU frequency.
    Needless to say, this only works when there is no CPU stepping/scaling.
    
    There are some additions to the Timer class that allow us to get the start/end time so that
    we can sync up StatTimers with them, if both are used in a given piece of code.
    
    getCPUTicks() is only implemented using __rdtscp() at the moment, so won't work on anything
    not recent relatively recent x86.
    
    we accumulate total ticks during dumping and output both 'ticks_in_main' and 'ticks_all_timers',
    which should be equal.
    addbe087
types.h 6.01 KB