Designing a performance stats framework

Perfromance stats are vital to understand dynamic efficiency of your code and may prove helpful to find and fix bottlenecks. This post discusses how to plug in these stats in your program.

There are primarily two classes of stats:

  • Counts
  • Time stamps

Stats are derived from events. You would be interested to know how many time an event happened, and how long did you spend to complete an operation. So, segragate your events into either “count” or “time”. Time could be computed for best, average and worst for an operation.

Next, figure out the fundamental events, e.g. “How many time printf was called” or “what is the average time my program spend in each call”? To compute latter, you need the frequency of “printf” and total time spent in all calls of printf. Such events are dependent on other events.

Design of perf stat framework need to have following phases:

  • Collection: Just collect raw data, most frequent operation.
  • Processing: Perform all calculation to compute derived events
  • Visualization

Please keep in mind that collection phase of events should be very quick. Do not perform any calculation during collection. This helps reducing intrusiveness of the event collection statements. The code to collect events should be tiny and can be inlined or #define’ed.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s