Skip to content

Guidelines for Use of Profiler

COBOL-IT provides a profiling utility that allows you to analyze where your programs are spending time by providing output, in Excel format, on the number of times a paragraph is executed, and both CPU and elapsed time spent in each paragraph.

The time is expressed in a platform-dependent unit, named "Ticks" as provided by the runtime environment of the "C" Compiler at hand. Please check the clock function for more information about this.

Because of the coarseness of this unit, some of the times measured as described above may be zero, while the paragraph has been executed one or more times.

By default, on program exit, the COBOL_IT runtime generates a file named cob_profiling_<PID>_final.xls, where [PID] is the PID number. This file is a tab separated text file, and can be opened directly with a spreadsheet like OpenOffice Calc or Microsoft Excel.

To enable the profiling utility, compile your program with the -fprofiling compiler flag.

Example:

       >cobc -fprofiling sample.cbl
       >cobcrun sample
       >cob_profiling_11344_final.xls

Returning Profiling Dumps prior to the program exit:

Dumping Profiling Data at the Module Level

You can generate separate output files for each module in your COBOL runtime session by setting the runtime environment variable B_PROFILING_EACH_MODULE=Y. In this case an XLS file is output at the exit of each module in the application using the naming convention [MODULE]_[PID]_profile.xls.

Using the PRAGMA statement to produce Profiling Reports

The PRAGMA statement provides internal compiler control, for profiling. The first literal is the command sent to the compiler.

Format 1:

PRAGMA "PROFILING" { literal-1 } ...

Format 2:

PRAGMA "DUMP" { literal-1 } ...

Syntax:

literal-n is a character string.

General Rules:

  1. The PRAGMA "PROFILING" statement causes programs compiled with -fprofiling to report time measurements from the current PRAGMA statement to the next PRAGMA, or to the end of the program.

  2. The PRAGMA "PROFILING" statement should be entered in column 8, as in the Code Sample below.

  3. The PRAGMA "DUMP" statement causes a profiling report to be generated when executed. Profiling reports produced by the PRAGMA "DUMP" statement will overwrite previous PRAGMA "DUMP" files with the same name.

PRAGMA "PROFILING" Code Sample:

       PROCEDURE DIVISION. 
       . . . 
       PRAGMA "PROFILING" "STEP1". 
       . . . 
       PRAGMA "PROFILING" "STEP2".

PRAGMA "DUMP" Code Sample:

       PROCEDURE DIVISION. 
       . . . 
       PRAGMA "DUMP" "REPORT". 
       . . .

Info profiling debugging command

The cobcdb compiler command >info profiling causes a profiling dump to be produced, dumping profiling information at the current point in the program. Profiling information is dumped in the .xls file format.

Attaching a program compiled with -fprofiling to a running process

A program compiled using the -fprofiling compiler flag may be attached exactly like a program to debug (with cobcdb -p <pid>) even if the program is not compiled for debugging.

Back to top