C H A P T E R 3 |
Profiler |
This chapter discusses the Sun Netra DPS profiler used in the Sun Netra Data Plane software. Topics include:
The Sun Netra DPS profiler is a set of API calls that help you collect various critical data during the execution of an application. The user can profile one or more areas of your application such as CPU utilization, I/O wait times, and so on. Information gathered using the profiler helps you decide where to direct performance-tuning efforts. The profiler uses special counters and resources available in the system hardware to collect critical information about the application.
As with instrumentation-based profiling, there is a slight overhead for collecting data during the application run. The profiler uses as little overhead as possible so that the presented data is very close to the actual application run without the profiler API in place.
The user enables the profiler with the -pg command-line option (tejacc). Insert the API calls at desired places to start collecting profiling data. The profiler configures and sets the hardware resources to capture the requested data. At the same time, the profiler reserves and sets up the memory buffer where the data will be stored. Insert calls to update the profiler data at any further location in the application. With this setup, the profiler reads the current values of the data and stores the values in memory.
There is an option to store additional user data in the memory along with each update capture. Storing this data helps you analyze the application in the context of different application-specific data.
The user can also obtain the current profiler data in the application and use the data as desired. With the assistance of other communication mechanisms you can send the data to the host or other parts of the application.
By demarking the portions that are being profiled, you can dump the collected data to the console. The data is presented as a comma-delimited table that can be further processed for report generation.
To minimize the amount of memory space needed for the profile capture, the profiler uses a circular buffer mechanism to store the data. In a circular buffer, the start and the end data is preserved, yet the intermediate data is overwritten when the buffer becomes full.
The profiling data is captured into different groups. For example, with the CPU performance group, events such as completed instruction cycles, data cache misses and secondary cache misses are captured. In the memory performance group, events such as memory queue and memory cycles are captured. Refer to the Profiler API chapter of the Sun Netra Data Plane Software Suite 2.1 Update 1 Reference Manual for the different groups and different events that are captured and measured on the target.
The profiler output consists of one line per profiler record. Each line commonly has a format of nine comma-delimited fields. The fields contain values in hexadecimal. If a record is prefixed with a -1, the buffer allocated for the profiler records has overrun. When a buffer overrun occurs, you should increase the value of the profiler_buffer_size property as described in the Configuration API chapter of the Sun Netra Data Plane Software Suite 2.1 Update 1 Reference Manual, and run the application again.
TABLE 3-1 describes the fields of the profiler record:
Refer to Profiler Output Example for an example of dump output.
For profiler API function descriptions, refer to the Sun Netra Data Plane Software Suite 2.1 Update 1 Reference Manual.
This section includes profiler API usage for both Sun UltraSPARC T1 and Sun UltraSPARC T2 processors.
The only difference when profiling functions are used for the Sun UltraSPARC T1 processor is in the teja_profiler_start function call for CPU group of events. Profiling CPU group on the Sun UltraSPARC T1 processor enables the measuring of only one additional event along with the completed instruction count that is always an available event for this group.
EXAMPLE 3-1 provides an example of profiler API usage for the Sun UltraSPARC T1 processor.
EXAMPLE 3-2 provides an example of profiler API usage for the Sun UltraSPARC T2 processor.
You can change the profiler configuration in the software architecture C-based file. The following example shows the profiler properties that you can change per process.
main_process is the process object that was created using the teja_process_create call. The property values are applied to all threads mapped to the process specified using main_process.
The following is an example of the profiler output.
The string, ver1.1, is the profiler dump format version. The string is used as an identifier of the output format. The string helps scripts written to process the output validate the format before processing further.
Each profiler record (which normally consists of a lot more lines than the above example) consists of a start delimiter, TEJA_PROFILE_DUMP_START, and an end delimiter, TEJA_PROFILE_DUMP_END. All profiled data records for a thread are displayed between the start and end delimiter.
In the first record, call type 1 represents teja_profiler_start. The values 100 and 1 seen in the event_hi and event_lo columns are the types of events in group 1 being measured. In the record with ID 30e6, call type 2 represents teja_profiler_update, so the values 36c2ba96 and ce are the values of the event types 100 and 2, respectively.
Cycle counts are accumulative. Thus, the difference between two of them provides the exact number of cycle counts between two profiler API calls. The difference divided by the processor frequency calculates the actual time between two calls.
IDs 18236 and 15136 represent the source location of the profiler API call. The
your-build-directory/reports/profiler_calls_location.txt file lists a table that maps IDs and actual source locations.
Profiling consists of instrumenting your application to extract performance information that can be used to analyze, diagnose, and tune your application. Sun Netra DPS provides an interface to assist you to obtain this information from your application. In general, profiling information consists of hardware performance counters and a few user-defined counters. This section defines the profiling information and how to obtain it.
Profiling is a disruptive activity that can have a significant performance effect. Take care to minimize profiling code and also to measure the effects of the profiling code. This can be done by measuring performance with and without the profiling code. One of the most disruptive parts of profiling is printing the profiling data to the console. To reduce the effects of prints, try to aggregate profiling statistics for many periods before printing, and print only in a designated strand.
The CPU, DRAM, and JBus performance counters for Sun UltraSPARC T1 processor are described in TABLE 3-2, TABLE 3-3, and TABLE 3-4, respectively.
instr_cnt |
Number of completed instructions. Annulled, mispredicted, or trapped instructions are not counted.[1] |
SB_full |
Number of store buffer full cycles.[2] |
FP_instr_cnt |
Number of completed floating-point instructions. [3] Annulled or trapped instruction are not counted. |
IC_miss |
|
DC_miss |
Number of data cache (L1) misses for loads (store misses are not included because the cache is write-through nonallocating). |
ITLB_miss |
Number of instruction TLB miss trap taken (includes real_translation misses). |
DTLB_miss |
Number of data TLB miss trap taken (includes real_translation misses). |
L2_imiss |
Number of secondary cache (L2) misses due to instruction cache requests. |
L2_dmiss_Id |
Number of secondary cache (L2) misses due to data cache load requests.[4] |
jbus_cycles |
|
dma_reads |
|
dma_read_latency |
|
dma_writes |
|
dma_write8 |
|
ordering_waits |
|
pio_reads |
|
pio_read_latency |
|
pio_writes |
|
aok_dok_off_cycles |
|
aok_off_cycles |
|
dok_off_cycles |
Each strand has its own set of CPU counters that only tracks its own events and can only be accessed by that strand. Performance counters are 32 bits wide so they can measure the values in range from 0 to 232. If measured event has value greater than 232 the corresponding counter will overflow as it will be indicated in the Overflow field of the output record. If the counter will overflow or not depends on properties of the code that is profiled, the clock frequency of the processor, the measured event and the profiling period. In the case of performance counter overflow it is suggested to the user to decrease the profiling period. When taking measurements, ensure that the application behavior is in a steady state. To check this behavior, measure the event a few times to see that it does not vary by more than a few percent between measurements. To measure all nine CPU counters, eight measurements are required. The application’s behavior should be consistent over the entire collection period. To profile each strand on a 32-thread application, each thread must have code to read and set the counters. The user must compile their own aggregate statistics across multiple strands or a core.
Since the JBus and DRAM performance counters are shared across all strands, only one thread should gather these counters.
The CPU performance counters for the Sun UltraSPARC T2 processor are described in TABLE 3-5.
Note - The final output of the profiler displays the Event names, shown in TABLE 3-5, which are the same as the events listed in Sun Netra Data Plane Software Suite 2.1 Update 1 Reference Manual. |
Each strand has its own set of CPU counters that only tracks its own events and can only be accessed by that strand. Performance counters are 32 bits wide so they can measure the values in range from 0 to 232. If measured event has value greater than 232 the corresponding counter will overflow as it will be indicated in the Overflow field of the output record. If the counter will overflow or not depends on the properties of the code that is profiled, the clock frequency of the processor, the measured event, and the profiling period. In the case of performance counter overflow, it is suggested to the user to decrease the profiling period.
When taking measurements, ensure that the application behavior is in a steady state. To check this behavior, measure the event a few times to see that it does not vary by more than a few percent between measurements. Since a user can measure any two events at a time, in order to measure all 38 CPU counters, 19 measurements are required. The application behavior should be consistent over the entire collection period. To profile each strand on a 64-thread application, each thread must have code to read and set the counters. Sample code is provided in EXAMPLE 3-2 (Sample Profiler API Usage for the Sun UltraSPARC T2 Processor). The user must compile their own aggregate statistics across multiple strands or a core.
The Sun UltraSPARC T2 DRAM Performance Counters are the same as the Sun UltraSPARC T1 DRAM Performance Counters described in TABLE 3-3.
The key user-defined statistic is the count of packets processed by the thread. Another statistic that can be important is a measure of idle time, which is the number of times the thread polled for a packet and did not find any packets to process.
The following example shows how to measure idle time. Assume that the workload looks like the following:
User-defined counters count the number of times through the loop where no work was done. Measure the time of the idle loop by running idle loop alone (idle_loop_time). Then run real workload, counting the number of idle loops (idle_loop_count)
The user can calculate the following metrics after collecting the appropriate hardware counter data using the Sun Netra DPS profiling infrastructure. Use the metrics to quantify performance effects and help in optimizing the application performance.
Calculate this metric by dividing instruction count by the total number of ticks during a time period when the thread is in a stable state. The user can also calculate the IPC for a specific section of code. The highest number possible is 1 IPC, which is the maximum throughput of 1 core of the UltraSPARC T processor.
This metric is the inverse of IPC. This metric is useful for estimating the effect of various stalls in the CPU.
Multiplying this number with the L1 cache miss latency helps estimate the cost, in cycles, of instruction cache misses. Compare this number to the overall CPI to see if this is the cause of a performance bottleneck.
This metric indicates the number of instructions that miss in the L2 cache, and enables you to calculate the contribution of instruction misses to overall CPI.
Data cache miss rate in combination with the L2 cache miss rate quantifies the effect of memory accesses. Multiplying this metric with data cache miss latency provides an indication of its effect (contribution) on CPI.
Similar to data cache miss rate, this metric has higher cost in terms of cycles of contribution to overall CPI. This metric also enables you to estimate the memory bandwidth requirements.
The profiler script is used to summarize the profiling output generated from the profiler. The profiler script (written in perl) converts the raw profiler output to a summarized format that is easy to read and interpret.
Two scripts are available, profiler.pl and profiler_n2.pl. profiler.pl is used for parsing outputs generated from a Sun UltraSPARC T1 (CMT1) processor. profile_n2.pl is used for parsing outputs generated from a Sun UltraSPARC T2 (CMT2) processor.
For Sun UltraSPARC T1 platforms (such as a Sun Fire T2000 system):
For Sun UltraSPARC T2 platforms (such as a Sun SPARC Enterprise T5220 system):
This file consists of raw profile data generated by the Sun Netra DPS profiler. Typically, this data is captured on the console and saved into a file with .csv suffix, indicating that this is a CSV (comma-separated values) file. For example, input_file.csv
This file is generated by redirecting the outputs of the profiler.pl script to an output file. This file should also be in CSV format. For example, output_file.csv.
Note - If there is no redirection (that is, the output_file is not specified), the output of the script will display on the console. |
Raw profile data is the direct output from the profiler.
The following shows an example of the raw profile data output from a Sun UltraSPARC T1 processor:
The following shows an example of the raw profile data output from the Sun UltraSPARC T2 processor:
Summarized profile data is the processed data generated from the profiler.pl and the profile_n2.pl for the Sun UltraSPARC T1 (CMT1) and (Sun UltraSPARC T2 (CMT2) processors, respectively.
For the Sun UltraSPARC T1 processor, the summary displays as in the following example:
TABLE 3-6 describes each field in the top section of the summarized Sun UltraSPARC T1 profile data output:
For the Sun UltraSPARC T2 processor, the summary displays as in the following example:
TABLE 3-7 describes each field in the top section of the summarized Sun UltraSPARC T2 profile data output:
Use the output values of the summarized data to derive various important performance parameters. This section lists performance parameters and the method from which they are derived.
This can be obtained from the Userdata.1 field.
Average number of instructions executed in a packet.
Formula: value = (Instr_cnt / pkts_per_interval)
Average number of instructions executed per cycle.
Formula: value = (Instr_cnt / cycle)
Average number of packets executed per second (in Kilo-packets per second).
Formula: value = ((pkts_per_interval / (cycle / cpu_frequency)) / 1000)
Average number of SB_full occurrences per 1000 instructions executed.
Formula: value = ((SB_full / Instr_cnt) * 1000)
Average number of FP_instr_cnt occurrences per 1000 instructions executed.
Formula: value = ((FP_Instr_cnt / Instr_cnt) * 1000)
Average number of IC_miss occurrences per 1000 instructions executed.
Formula: value = ((IC_miss / Instr_cnt) * 1000)
Average number of DC_miss occurrences per 1000 instructions executed.
Formula: value = ((DC_miss / Instr_cnt) * 1000)
Average number of ITLB_miss occurrences per 1000 instructions executed.
Formula: value = ((ITLB_miss / Instr_cnt) * 1000)
Average number of DTLB_miss occurrences per 1000 instructions executed.
Formula: value = ((DTLB_miss / Instr_cnt) * 1000)
Average number of L2_miss occurrences per 1000 instructions executed.
Formula: value = ((L2_miss / Instr_cnt) * 1000)
Average number of L2_Dmiss_LD occurrences per 1000 instructions executed.
Formula: value = ((L2_miss / Instr_cnt) * 1000)
Average number of instructions executed in a packet.
Formula: value = (All_instr / pkts_per_interval)
Average number of instructions executed per cycle.
Formula: value = (All_instr / cycle)
Average number of Store instructions executed per packet.
Formula: value = (Store_instr / pkts_per_interval)
Average number of Load instructions executed per packet.
Formula: value = (Load_instr / pkts_per_interval)
Average number of L2 cache Load misses per packet.
Formula: value = (L2_load_misses / pkts_per_interval)
Average number of L1 Icache misses per 1000 packet.
Formula: value = (Icache_misses x 1000) / pkts_per_interval)
Average number of L1 Icache misses per packet.
Formula: value = (Dcache_misses / pkts_per_interval)
Average number of packets executed per second (in Kilo-packets per second).
Formula: value = ((pkts_per_interval / (cycle / cpu_frequency)) / 1000)
Note - Not all possible parameters are shown here. The user can derive any parameter with any formula using the data outputs from the summary. |
Note - These formulas can easily be inserted into a spreadsheet program. |
|
For example, an output_file.csv generated by profiler.pl (for UltraSPARC T1) or by profiler_n2.pl (for UltraSPARC T2).
2. Insert formulas into the spreadsheet.
See the sample_analysis.sxc spreadsheet provided as part of the software package. You can open with an OpenOffice compatible software. This file is included in the SUNWndps/src/libs/profile directory. The first spreadsheet in this template (click on the Output from profile script tab) consists of sample output generated from
Step 1. The second spreadsheet in this template (click on the Analysis tab) consists of formulas for computing the data in the first spreadsheet. The format in the Analysis spreadsheet is designed so that you can compare the data generated on each thread side by side.
3. Save the spreadsheet for future reference.
You can form your own spreadsheet templates for your own analysis. For example, each application can have its own data imported to a spreadsheet for analysis.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.