HP Caliper Advisor Rule Writer Guide

advice_text = "To get more advice on hot functions, " \
"make a 'caliper fprof ...' measurement."
Writing a Rule to Analyze the Same Metrics From All Datasets
A rule function typically needs metric data from only one performance measurement
run. The Advisor tries to return the best data available for the accessor function base
version.
Sometimes a rule will attempt to analyze the same performance metrics from all
applicable datasets. There are two ways to do this:
Use a negative accessor function nth version to retrieve only those datasets
containing the metrics of interest (–1 retrieves the first set, –2 retrieves the second,
and so on).
Use a positive accessor function nth version to attempt to retrieve the metrics from
all datasets (numbered sequentially starting at 0), some of which won’t contain
the requested data.
An example of the first method is:
n = -1
metrics = object.get_metrics_nth(CPU_CYCLES, NOPS_RETIRED, n)
while metrics:
# process metrics
n -= 1
metrics = object.get_metrics_nth(CPU_CYCLES, NOPS_RETIRED, n)
An example of the second method is:
for n in range(object.dataset_count):
metrics = object.get_metrics_nth(CPU_CYCLES, NOPS_RETIRED, n)
if metrics is None:
continue
# process metrics
The first method is slightly more efficient, because it returns performance data only
from the datasets that contain the requested metrics. The second method must skip the
datasets that do not contain the data. Note that the Python range(x) function returns
a sequence of integers from 0 through x – 1.
Using Chaining
The technique of retrieving supplemental information about the dataset that supplied
the performance metrics being analyzed is called chaining. For example, a rule function
might retrieve the performance data for an IP histogram and also need the associated
user and system time of that measurement run:
metrics = object.get_histogram(IP, FUNCTION, SAMPLE_COUNT, n)
if metrics:
times = object.get_run_info_nth(USER_TIME, SYSTEM_TIME, metrics[2])
Writing a Rule to Analyze the Same Metrics From All Datasets 61