Skip to content

Commit 7a2de5a

Browse files
committed
Merge branch 'eyraud/document_integrated_instr' into 'master'
Document the integrated instrumentation workflow Closes #108 See merge request eng/cov/gnatcoverage!258 Closes eng/cov/gnatcoverage#108
2 parents e3dcc7a + 933bb26 commit 7a2de5a

7 files changed

+239
-7
lines changed

Diff for: doc/gnatcov/fig_flow_integrated_instr.dot

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
digraph {
2+
node [fontsize = 9]
3+
4+
edge [fontsize = 9, arrowsize=0.7]
5+
6+
setup [shape=box, label="gnatcov setup"]
7+
8+
/*-------------------
9+
Using Source traces
10+
-------------------*/
11+
subgraph "cluster_src_traces" {
12+
label = "Setup / Build / Execute / Analyze";
13+
fontsize = 10;
14+
labeljust = l;
15+
16+
/* processes */
17+
node [shape = box];
18+
19+
node [color = green];
20+
instrument [label = "Setup integrated instrumentation\n(gnatcov setup-integration -P<gpr>)"];
21+
build_instr [label = "Regular build\n(using the generated compiler wrapper)"];
22+
regular_execution [label = "Regular Execution\n(instrumented executable)"];
23+
24+
node [color = blue];
25+
srct_coverage [label = "Analyze/Consolidate\n(gnatcov coverage -P...)"];
26+
27+
/* products or inputs */
28+
node [shape = ellipse, color = green];
29+
st1 [label = "strace1"];
30+
stdots [label = "..."];
31+
st2 [label = "strace2"];
32+
33+
node [shape = ellipse, color = blue];
34+
srct_report [label = "Report"];
35+
srct_checkpoint [label = "Checkpoint"];
36+
37+
src [shape = ellipse, label = "Original Sources"];
38+
39+
/* Links */
40+
src -> instrument;
41+
instrument -> build_instr;
42+
build_instr -> regular_execution;
43+
44+
{rank = same;
45+
st1; stdots; st2;
46+
}
47+
48+
regular_execution -> st1 [style = dotted];
49+
regular_execution -> stdots [style = dotted];
50+
regular_execution -> st2 [style = dotted];
51+
52+
st1 -> srct_coverage;
53+
stdots -> srct_coverage;
54+
st2 -> srct_coverage;
55+
56+
srct_coverage -> srct_report [style = dotted];
57+
srct_coverage -> srct_checkpoint [style = dotted];
58+
srct_checkpoint -> srct_coverage;
59+
60+
}
61+
}

Diff for: doc/gnatcov/fig_flow_integrated_instr.pdf

23.7 KB
Binary file not shown.

Diff for: doc/gnatcov/fig_flow_integrated_instr.png

37.1 KB
Loading

Diff for: doc/gnatcov/getting_started.rst

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ stored in files that we call :dfn:`Coverage Checkpoints`.
8282

8383
Source instrumentation based Coverage analysis overview
8484

85+
|gcv| also provides an alternate workflow that consists in integrating
86+
seamlessly into an existing build process possibly not involving the use of
87+
gprbuild. This is provided as an experimental feature and is available for
88+
C/C++, compiling with gcc/g++ on a linux host. The figure
89+
:numref:`fig-flow_integrated_instr` depicts this workflow that is more
90+
thoroughly detailed in the section :ref:`integrated_instr`.
91+
92+
.. _fig-flow_integrated_instr:
93+
.. figure:: fig_flow_integrated_instr.*
94+
:align: center
95+
96+
Integrated instrumentation based Coverage analysis overview
8597

8698
A simple example
8799
================

Diff for: doc/gnatcov/gnatcov_part.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ GNATcoverage User's Guide
88
getting_started
99
units_of_interest
1010
src_traces
11+
integrated_instr
1112
cov_source
1213
consolidation
1314
exemptions

Diff for: doc/gnatcov/integrated_instr.rst

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
.. _integrated_instr:
2+
3+
######################################################################
4+
Producing source traces with integrated instrumentation (experimental)
5+
######################################################################
6+
7+
|gcv| provides an alternate way of instrumenting sources, available for C/C++
8+
under linux and when using gcc or g++ as a compiler. Theoretically, any build
9+
system should be supported, but it has only been tested for the Makefile / CMake
10+
build systems so far.
11+
12+
As with the workflow involving a separate instrumentation, a :term:`coverage
13+
runtime <Coverage Runtime>` to be used by the instrumented code needs to be
14+
setup as a required prerequisite. Refer to the :ref:`instr-rts` section of this
15+
manual for a description of this step. The installed instrumentation runtime
16+
must be visible on the ``GPR_PROJECT_PATH``.
17+
18+
Then the process essentially goes like:
19+
20+
#. Setup the integrated instrumentation process, specifying the instrumentation
21+
parameters (units of interest, coverage level etc.) and the compilers of use.
22+
#. Build the instrumented code using the generated compiler wrapper(s);
23+
#. Execute the program to produce a trace.
24+
25+
26+
Specifying instrumentation switches
27+
===================================
28+
29+
The user specifies the switches through the ``gnatcov setup-integration``
30+
command, which accepts any option accepted by ``gnatcov instrument``, except the
31+
ones using project mechanisms to filter out units of interest: ``--units`` and
32+
``--projects``. Refer to :ref:`src_traces` for more information regarding the
33+
source instrumentation specific switches.
34+
35+
As there is no project acting as a units of interest provider, the user must
36+
explicitly pass files of interest through the ``--files`` switch, which expects
37+
a list of full filenames that can be passed through the command line, or using a
38+
response file.
39+
40+
To generate a compiler wrapper, use the ``--compilers`` switch. The list of
41+
supported compilers is ``gcc`` and ``g++``.
42+
43+
This will generate in the current directory, or in the directory specified by
44+
the ``--output-dir`` switch an executable compiler wrapper and a
45+
``gnatcov_config.json`` file along. Note that this configuration file is used to
46+
configure various instrumentation options: it is thus very important that it
47+
resides in the same directory as the compiler wrapper.
48+
49+
50+
Building an instrumented executable
51+
===================================
52+
53+
The build process can be run unchanged after it has been configured to use the
54+
generated compiler wrapper instead of the original compiler.
55+
56+
57+
A simple Makefile example
58+
=========================
59+
60+
The following considers that the instrumentation runtime was previously
61+
installed with ``gnatcov setup``, and that the ``GPR_PROJECT_PATH`` variable
62+
contains its installed location. See :ref:`instr-rts`.
63+
64+
Let's consider a simple ``main.cpp`` file:
65+
66+
.. code-block:: c++
67+
68+
#include <iostream>
69+
70+
int main(int argc, char **argv){
71+
std::cout << "Hello World" << std::endl;
72+
return 0;
73+
}
74+
75+
and the following Makefile:
76+
77+
.. code-block:: makefile
78+
79+
CC=g++
80+
OBJ = main.o
81+
82+
%.o: %.c
83+
$(CC) -c -o $@ $<
84+
85+
test: $(OBJ)
86+
$(CC) -o $@ $^
87+
88+
We start by configuring the instrumentation process:
89+
90+
.. code-block:: sh
91+
92+
cd <my-project>
93+
gnatcov setup-integration --files=<my_project>/main.cpp --compilers=g++
94+
95+
Then, we launch the build processed unchanged, with the compiler wrapper first
96+
on the path:
97+
98+
.. code-block:: sh
99+
100+
export PATH=<my-project>:$PATH
101+
make
102+
103+
This will produce an instrumented executable, that will produce a source trace
104+
when run, that can be analyzed with ``gnatcov coverage``.
105+
106+
A simple CMake example
107+
======================
108+
109+
The following considers that the instrumentation runtime was installed through
110+
the use of ``gnatcov setup``.
111+
112+
Let's consider a simple ``main.cpp`` file
113+
114+
.. code-block:: c++
115+
116+
#include <iostream>
117+
118+
int main(int argc, char **argv){
119+
std::cout << "Hello World" << std::endl;
120+
return 0;
121+
}
122+
123+
The CMakeLists.txt file to be used to compile the main.cpp file is :
124+
125+
.. code-block:: cmake
126+
127+
project(HelloWorld)
128+
cmake_minimum_required(VERSION 3.0)
129+
130+
add_executable(hello_world main.cpp)
131+
132+
We start by creating the build directory, and configuring the instrumentation
133+
process there:
134+
135+
.. code-block:: sh
136+
137+
cd <my-project>
138+
mkdir build
139+
cd build
140+
gnatcov setup-integration --files=<my_project>/main.cpp --compilers=g++
141+
142+
This creates a ``g++`` compiler wrapper in the build directory, along with a
143+
``gnatcov_config.json`` file that we intend to use as a proxy for compilation.
144+
To do that, we have to configure the CMake build process accordingly, using the
145+
``CMAKE_CXX_COMPILER`` variable. We run the configuration command in the build
146+
directory:
147+
148+
.. code-block:: sh
149+
150+
cmake .. -CMAKE_CXX_COMPILER=<my_project>/build/g++
151+
152+
The default generator for CMake is "Unix Makefiles", so we can then run the
153+
build process with ``make``, and our executable which will produce a source trace
154+
that can be analyzed by ``gnatcov coverage``.

Diff for: tools/gnatcov/command_line.ads

+11-7
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,13 @@ package Command_Line is
385385
"Generate the adequate configuration to use gnatcov in integrated"
386386
& " instrumentation mode. The files of interest must be passed"
387387
& " through the --files switch, the compiler driver in used through"
388-
& " the --compilers switch, the runtime installation directory"
389-
& " through the --runtime-install-dir switch, and the configuration"
390-
& " and compiler driver wrappers are generated in the subdirectory"
391-
& " pointed by the --output-dir switch.",
388+
& " the --compilers switch, and the configuration and compiler"
389+
& " driver wrappers are generated in the subdirectory pointed by"
390+
& " the --output-dir switch.",
392391
Pattern =>
393392
"--files=<files_of_interest> --compilers=<compiler>"
394-
& " --runtime-install-dir=<dir> [--output-dir=<dir>]",
395-
Internal => True));
393+
& " [--output-dir=<dir>]",
394+
Internal => False));
396395

397396
Bool_Infos : constant Bool_Option_Info_Array :=
398397
(Opt_Verbose => Create
@@ -526,6 +525,7 @@ package Command_Line is
526525
& " variations).",
527526
Commands => (Cmd_Setup
528527
| Cmd_Instrument_Project
528+
| Cmd_Setup_Integration
529529
| Cmd_Instrument_Main => True,
530530
others => False),
531531
Internal => False),
@@ -836,6 +836,7 @@ package Command_Line is
836836
& " for non-native programs.",
837837
Commands => (Cmd_Setup
838838
| Cmd_Instrument_Project
839+
| Cmd_Setup_Integration
839840
| Cmd_Instrument_Main => True,
840841
others => False),
841842
At_Most_Once => False,
@@ -848,6 +849,7 @@ package Command_Line is
848849
& " filename for created source traces.",
849850
Commands => (Cmd_Setup
850851
| Cmd_Instrument_Project
852+
| Cmd_Setup_Integration
851853
| Cmd_Instrument_Main => True,
852854
others => False),
853855
At_Most_Once => False,
@@ -858,6 +860,7 @@ package Command_Line is
858860
& " filename prefix for created source traces.",
859861
Commands => (Cmd_Setup
860862
| Cmd_Instrument_Project
863+
| Cmd_Setup_Integration
861864
| Cmd_Instrument_Main => True,
862865
others => False),
863866
At_Most_Once => False,
@@ -869,6 +872,7 @@ package Command_Line is
869872
& " filename tag for created source traces.",
870873
Commands => (Cmd_Setup
871874
| Cmd_Instrument_Project
875+
| Cmd_Setup_Integration
872876
| Cmd_Instrument_Main => True,
873877
others => False),
874878
At_Most_Once => False,
@@ -1351,7 +1355,7 @@ package Command_Line is
13511355
Pattern => "NAME",
13521356
Help =>
13531357
"List of compiler drivers for which we should generate wrappers."
1354-
& " Supported compilers are: gcc.",
1358+
& " Supported compilers are: gcc, g++.",
13551359
Commands => (others => True),
13561360
Internal => True)
13571361
);

0 commit comments

Comments
 (0)