The IBM Software Development Kit for Linux on Power (SDK) provides two related tools, Source Code Advisor (SCA) and the Feedback Directed Program Restructuring tool (FDPR), that implement feedback-directed, post-link program analysis and optimization technology. SCA finds and visualizes performance problems in the application source code, using information produced by using FDPR.
1. Feedback Directed Program Restructuring
FDPR can analyze, report on and optimize the executable image of a program or shared library based on a typical execution profile. It works similarly to a compiler: it reads a linked executable program and produces an optimized version of it.
FDPR optimization is performed in three distinct steps:
- Instrumentation: FDPR analyzes the input program or shared library and creates an instrumented version.
- Profiling: The instrumented code is run with some representative input. During this run, profiling data is collected, including various counts, such as how many times each branch was executed.
- Optimization: FDPR processes the input program together with the profile. It performs various optimizations based on this profile, such as code restructuring, making the program run more efficiently.
The SDK provides a plug-in (also called FDPR) that allows you to run FDPR through the SDK user interface.
2. Source Code Advisor
During the code optimization process, FDPR can produce a journal of the optimization performed. The Source Code Advisor plug-in uses this journal, produced as an XML file, to highlight potential problems in the source code and to offer suggested solutions. The journal explains each optimization, including the source location, execution count, the performance problem found, and the user action required to resolve the problem.
In the SCA launcher configuration, one can specify the workload needed to collect the profile of the program. When running this configuration, the program is built, if necessary, using the standard project build
process. Once the executable is available, FDPR creates an instrumented version and runs it using the specified workload. FDPR then performs a pseudo optimization step producing a journal of the performance problems found. The result is an XML-formatted file that lists the specific problems found, their exact location in the source, and so on. With the XML journal available, the Source Code Advisor view is displayed to visualize the set of problems, allowing you to navigate through the problems and the corresponding places in the source where they were found. The view provides a recommended course of action for each problem at various abstraction levels (source change, compiler switches, and so on.)
For some events, SCA provides quick fixes which allows for automatically changing the code to improve performance. When a quick fix is not available, the user can manually do the changes based on the suggestions provided by SCA. For a complete list of events flagged by SCA see: http://www.ibm.com/support/knowledgecenter/linuxonibm/liaal/iplsdkscaeventref.htm
3. Using FDPR and SCA plug-ins with PHP 7.0 project
This section shows the result of using both FDPR and SCA plugins in the PHP 7.0 project. The PHP source code can be downloaded from the php.net download site (http://php.net/downloads.php) for current stable releases or from github for the current development releases (https://github.com/php/php-src).
3.1 FDPR Results
After running the FDPR plug-in with the PHP binary, a new binary called "php.fdpr" is generated and we can explore if the new binary is more optimized than the original. To do so, we can first compare the size of the 2 binaries. The figure 1 shows that the original PHP binary has 66MB while the new one has 37MB, so FDPR reduced a lot the size of final binary.
Figure 1: PHP binaries size
Another way to compare the binaries is running them with a benchmark. For this example the benchmark used was downloaded from: http://www.php-benchmark-script.com/bench.zip.
Figure 2 shows the original PHP binary execution output while figure 3 shows the output from PHP binary generated by FDPR. Comparing both outputs we can see that the binary generated by FDPR had performance gains in all operations, particularly in the "test_math" and "test_stringmanupulation".
3.2 SCA Results
After running the SCA plug-in with the PHP binary, a view called "Source Code Advisor" opens and displays the optimization problems found in the PHP project (Figure 4). The picture above show the SCA view with the possible optimization that can be done in the PHP code.
We can expand each problem type in the view and click in one of them to open it location in the source code. The view also shows a description about the problem and a possible solution to solve it and increase the program performance. For the "Unroll Loop" problem type, SCA provides a quick fix that can automatically change the code. To use this feature put the cursor in the yellow warning in the source code, use the "CTRL + 1" shortcut and press "Enter" key. Figure 5 shows the code after applying the quick fix.
Figure 4: SCA view
Figure 5: PHP code after the quick fix
4. More Information
For more information about FDPR and SCA, access the IBM SDK for Linux on Power online documentation: http://www.ibm.com/support/knowledgecenter/linuxonibm/liaal/iplsdksca.htm