Code Coverage and Profiling (.NET COBOL)

You can use Visual Studio's integrated tools to collect code coverage and performance information for .NET COBOL applications.
Restriction: The current limitations include:
  • Visual Studio Professional or a more advanced edition is required to collect coverage information. Visual Studio Enterprise edition is required to view .coverage files in the IDE.
  • Visual Studio Enterprise edition is required if you are using C# or Visual Basic test projects to collect code coverage data for .NET COBOL applications.
  • The expanded copybook view sometimes shows incorrect code coverage information.
  • Profiling shows compiler-generated method names - for example, when the code being profiled is procedural (non-Object Oriented .NET) COBOL.
  • Code coverage using VSinstr requires binaries to be compiled with full PDB information. This is not supported for .NET (previously, .NET Core) COBOL projects since they only support embedded or portable PDBs. You can obtain code coverage information for such projects in Visual Studio if you use unit tests.

Collecting code coverage using Profiler

  1. In Visual Studio, build your .NET COBOL application with Compile for debugging enabled on the COBOL tab in the project's properties.
  2. Start a Visual Studio command prompt with elevated rights.

    You need the 32-bit Visual Studio command prompt for applications compiled for x86 and the 64-bit Visual Studio command prompt if the application you are testing is compiled with x64 or AnyCPU.

  3. At the command prompt, change to the output directory of the solution where the application executable is created.
  4. Execute the following at the command prompt to generate the instrumented binaries:
    VSinstr -coverage app-filename.exe
  5. Execute the following to start the Profile monitor for code coverage and to create a .coverage file:
    VSPerfCmd /start:coverage /output:run.coverage

    This creates a run.coverage file in the output directory of the solution.

  6. Run your application.
  7. Execute the following to close the Visual Studio Performance Profiler:
    VSPerfCmd /shutdown
  8. In Visual Studio, click File > Open > File, navigate to the output directory of the solution, and select and open the run.coverage file. (You must have Visual Studio Enterprise edition to view .coverage files in the IDE.)

Collecting code coverage through tests

You can collect code coverage by running your application using tests. Enterprise Developer does not provide Visual Studio test projects for COBOL so you need to create either a C# or a VB test project that references and runs COBOL.

Restriction: This is only supported in Visual Studio Enterprise edition.

Performance profiling of .NET COBOL code

You can access the Visual Studio Profiler as follows:

  1. Click Debug > Performance Profiler.
  2. From the Change Target menu, select what to analyze such as Executable.
  3. Specify the full path to the application executable and the Working directory, click OK.
  4. Click Finish to start profiling your application.
  5. Choose one of the available options in the main profiler window such as CPU Usage, and click Next.

    The profiler launches your application.

  6. Run the application and, when it finishes, Visual Studio generates the profiling report.

To rerun Profiler with a different setting such as Instrumentation:

  1. Click Debug > Performance Profiler.
  2. From the Change Target menu, select what to analyze such as Executable.
  3. In the main profiling window, select another tool.
  4. Click Start to start a diagnostic session.

Alternatively:

  1. Click Debug > Windows > Show Diagnostic Tools. This opens the Diagnostic Tools pane.
  2. From the Settings button in the toolbar, select CPU usage.
  3. Debug your application in order for your application to capture diagnostics data.

For more information on Performance Profiling, Code Coverage and other Visual Studio analysis tools, check Microsoft's MSDN.