HP Caliper Advisor Rule Writer Guide

The call to get_histogram() retrieves the first (and possibly only) IP histogram (in
metrics[0]), its sample count (in metrics[1]), and the ID number of the dataset
that provided the data (in metrics[2]). The call to get_run_info_nth() retrieves
the corresponding user and system time from that same dataset.
Additional Tips for Writing Rules
Here are some suggestions for writing good Advisor rules:
Each rule must be independent of all other rules. A rule can call common helper
functions, but is otherwise self-contained.
Rules should be “state-less” and not depend on any global data that they, or another
rule, sets. (It is acceptable, however, to reference a read-only global data table.)
The order of rule execution or objects being analyzed cannot be guaranteed.
When retrieving performance data, it is preferable to write code such as:
metrics = object.get_metrics(metric1, metric2)
if metrics is None:
return
(metric1, metric2) = metrics
rather than:
(metrics1, metrics2) = object.get_metrics(metric1, metric2)
If the performance data exists, then the two are functionally equivalent. However,
if the requested data does not exist, then the first example cleanly deals with the
None value returned while the second example raises a Python error (due to the
length mismatch of the assignment statement, one item None being assigned to
two).
Ideally, a rule function should work equally well with performance data from
HP-UX and Linux systems and from all processor types. This might involve looking
for performance data for different PMU events based on the processor type. If
there are small differences between the processors (or the operating systems), then
it is best to write a single rule function. Otherwise, you should develop separate
rule functions (with appropriate names such as my_rule_hpux and
my_rule_linux) for each processor/operating system.
The easiest way to determine the correct name of a PMU event metric is to use the
caliper info command. For example, the following command:
$ caliper info itlb misses
prints a list of all ITLB miss events and their exact spelling. Note that the full name
must be used in an Advisor get_metrics() call. The abbreviations shown can
only be used in an HP Caliper measurement run.
A rule should consider data gathered from different kinds of performance
measurements. For example, the sample rule in Figure 6-1 “Typical Rule Used by
62 Writing Rules for the HP Caliper Advisor