Category Archives: pmctools

PmcTools talk at the Bangalore chapter of the ACM

In April 2009 I was invited to speak on FreeBSD/PmcTools by the Bangalore chapter of the ACM. The slides for this talk are available at: http://people.freebsd.org/~jkoshy/download/acm-apr-09.pdf (550KB, PDF).

This was an overview talk. The talk briefly touched upon: the motivations and goals of the project, the programming APIs, some aspects of the implementation and on possible future work.

PmcTools talk at the Bangalore chapter of the ACM

In April 2009 I was invited to speak on FreeBSD/PmcTools by the Bangalore chapter of the ACM. The slides for this talk are available at: http://people.freebsd.org/~jkoshy/download/acm-apr-09.pdf (550KB, PDF).

This was an overview talk. The talk briefly touched upon: the motivations and goals of the project, the programming APIs, some aspects of the implementation and on possible future work.

Short updates

A couple of (lagged!) updates on my FreeBSD/PmcTools work:

  • In Nov'08, I added support for Intel™ Core 2™ PMCs to PmcTools (SVN #185363 and later changesets).

    More recently, Nokia, via Jeff Roberson, contributed basic support for the PMCs in the Core/i7™ CPU, the next member in the Core™ family of CPUs (SVN #187761).

    With these additions PmcTools supports most Intel CPUs that have PMCs in them. (I have plans to finish support for 166Mhz Pentium MMX™ CPUs soon.)

  • A couple of tricky bugs were tracked down and fixed:

    • The NMI handler code I had written for the amd64 architecture needed to be more robust than it was. Fixed in SVN #188065.

    • A bug in callchain capture code that would appear only under high loads and only on SMP machines. Fixed in SVN #186037.

    Thanks to Artem Belevich, Fabien Thomas, George Neville-Neil and Jeff Roberson for their assistance with debugging.

Short updates

A couple of (lagged!) updates on my FreeBSD/PmcTools work:

  • In Nov'08, I added support for Intel™ Core 2™ PMCs to PmcTools (SVN #185363 and later changesets).

    More recently, Nokia, via Jeff Roberson, contributed basic support for the PMCs in the Core/i7™ CPU, the next member in the Core™ family of CPUs (SVN #187761).

    With these additions PmcTools supports most Intel CPUs that have PMCs in them. (I have plans to finish support for 166Mhz Pentium MMX™ CPUs soon.)

  • A couple of tricky bugs were tracked down and fixed:

    • The NMI handler code I had written for the amd64 architecture needed to be more robust than it was. Fixed in SVN #188065.

    • A bug in callchain capture code that would appear only under high loads and only on SMP machines. Fixed in SVN #186037.

    Thanks to Artem Belevich, Fabien Thomas, George Neville-Neil and Jeff Roberson for their assistance with debugging.

Timed measurements with pmcstat(8)

Every once in a while I get email asking for an option to pmcstat(8) that would allow hardware events to be measured for a specified time interval.

The good news is: pmcstat(8) already supports timed measurements — using /bin/sleep.

Here is how you would do it:

  • Timed system sampling would be done in the following manner:

    % pmcstat -S instructions -O logfile /bin/sleep 42

    This invocation allocates a system-scope sampling PMC (-S) and profiles the whole system while /bin/sleep executes, i.e., for 42 seconds.

  • Timed measurements on groups of processes are performed in a similar fashion:

    % pmcstat -d -p dc-misses -t '1234' /bin/sleep 24

    This invocation would allocate a process-scope counting PMC (-p) that counts data cache misses, attach it (-t) to the process with pid 1234 and its descendants (-d), and count for 24 seconds.

    Note that the '-t' option also takes regular expressions, so you don't need to know process ids beforehand. To count instructions executed by processes named 'httpd' for an hour you would use:

    % pmcstat -p instructions -t 'httpd' /bin/sleep 3600

The "Unix way" uses small tools, each of which does a defined task reasonably well and which are combined to perform more complex tasks. In the examples above, /bin/sleep manages time intervals and pmcstat(8) manages PMC based measurements.

When you combine them, voilà, you get timed PMC based measurements.

Timed measurements with pmcstat(8)

Every once in a while I get email asking for an option to pmcstat(8) that would allow hardware events to be measured for a specified time interval.

The good news is: pmcstat(8) already supports timed measurements — using /bin/sleep.

Here is how you would do it:

  • Timed system sampling would be done in the following manner:

    % pmcstat -S instructions -O logfile /bin/sleep 42

    This invocation allocates a system-scope sampling PMC (-S) and profiles the whole system while /bin/sleep executes, i.e., for 42 seconds.

  • Timed measurements on groups of processes are performed in a similar fashion:

    % pmcstat -d -p dc-misses -t '1234' /bin/sleep 24

    This invocation would allocate a process-scope counting PMC (-p) that counts data cache misses, attach it (-t) to the process with pid 1234 and its descendants (-d), and count for 24 seconds.

    Note that the '-t' option also takes regular expressions, so you don't need to know process ids beforehand. To count instructions executed by processes named 'httpd' for an hour you would use:

    % pmcstat -p instructions -t 'httpd' /bin/sleep 3600

The "Unix way" uses small tools, each of which does a defined task reasonably well and which are combined to perform more complex tasks. In the examples above, /bin/sleep manages time intervals and pmcstat(8) manages PMC based measurements.

When you combine them, voilà, you get timed PMC based measurements.