Skip to content
kissake edited this page Sep 7, 2022 · 4 revisions

Primary function

This is a very simple python script to grab the barest of details from a process being run from a script in order to collect performance information.

This data is collected into a file in CSV format, perfectly prepared to import into Excel, or OpenOffice Calc, or any other CSV-happy processor (sqlite?)

Example usage

  • export PERFEROUTPUT=/tmp/perfer-stats.csv
  • export PERFERCMD=TRUE
  • perfer --header
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>
  • perfer <command to be monitored>

Example explanation

In the above example, the environment variables set the context for perfer to run. The first call creates the performance data file, including the headers. The subsequent times perfer is called, it appends to the existing file the stats of the command called.

Once this data is collected, you can, for example, determine where most of the CPU or wall clock time is spent, you can see the exact commands executed and when, you can see how much memory or I/O is performed.

With this information you can start to identify bottlenecks in your processes so that you can begin to make improvements.

Environment variables

You probably want to set and export these once and not touch them while you are collecting a set of performance stats. Changing PERFERCMD, PERFERENVIRON or PERFERCWD will change the number of columns and position of the data being collected, which will make the CSV file very difficult to parse.

  • PERFEROUTPUT - The output file for the performance data. It is recommended to output a header line the first time you use a given output file, just to make interpretation of the data simpler.
  • PERFERCMD - Set to any value (e.g. TRUE) if you want to record the command being executed and its arguments.
  • PERFERENVIRON - A colon-separated list of environment variables to record for each execution.
  • PERFERCWD - Set to any value (e.g. TRUE) if you want to record the current working directory for each command execution.
  • PERFERDEBUG - Set to any value (e.g. 1) if you want a bunch of garbage to be sent to stderr with each execution. I do not recommend.

Examples of less common settings:

  • export PERFERENVIRON="PATH:PERL5LIB"
  • Ensure that any values of the listed environment variables (PATH and PERL5LIB in this case) are recorded. This can help you understand e.g. if one executable was chosen over another with the same name.
  • export PERFERCWD=TRUE
  • Ensure that perfer reords the current working directory at the time the command was run. This can be used to put commandline arguments in context if they are filenames without full paths.
Clone this wiki locally