2.Run ./myprog and find the process ID of the process.

3.Specify the process you want to measure. For example: $ caliper fprof 7654

HP Caliper remains attached to the target process until it ends or you type Ctrl-C. If you type Ctrl-Cto stop HP Caliper and generate a report, HP Caliper forcibly terminates all processes that are being measured.

Taking PMU Samples in Your Code

On HP-UX, you have two methods to control where to collect performance information in your code:

Triggering samples in specific places in your code. See “Triggering PMU Samples in Specific Code Regions” (p. 159).

Limiting samples to specific blocks of your code. See “Restricting PMU Measurements to Specific Code Regions” (p. 161).

Both of these methods require you to make changes to your source code.

Triggering PMU Samples in Specific Code Regions

To analyze the performance in several regions of code, such as a function or a hot loop, you can collect samples at specific places as your code executes.

This feature works with the pmu_trace measurement to show each sample in the output with the associated delta in even counts since the last sample.

To specify the place in your code to trigger a sample:

1.Modify your source code to add trigger statements to take the samples.

Use the macros in include/caliper_control.h in the HP Caliper home directory. The macros are named CALIPER_PMU_TAKE_SAMPLE_n, with n varying from 1 to 8. The report shows the value of n next to each Sample Origin column.

Figure 30 (page 159) shows an example of how to use the macros.

Figure 30 Using Macros to Trigger PMU Samples

#include <caliper_control.h>

....

void my_function (void)

{

CALIPER_PMU_TAKE_SAMPLE_1();

[... code to be measured ...]

CALIPER_PMU_TAKE_SAMPLE_2();

}

2.Make a copy of the pmu_trace measurement configuration file under a new name, for example my_pmu_trace.

3.Edit the copy of the measurement configuration file to enable the samples you have specified. Change the value of collect_sample_desc to True.

This setting causes HP Caliper to collect and present information for each sample to identify the origin of the sample.

4.To create a report that shows samples only at the points in your code where you explicitly set the CALIPER_PMU_TAKE_SAMPLE_x instructions, you must change the sampling_counter setting in the measurement configuration file.

Setting the counter to NO_EVENT or None disables statistical sampling:

Taking PMU Samples in Your Code 159

Page 159
Image 159
HP UX Caliper Software manual Taking PMU Samples in Your Code, Triggering PMU Samples in Specific Code Regions