Skip to content

Commit 76047d0

Browse files
committed
Merge pull request #80 from lindig/coverage
CP-17268 add support for coverage profiling
2 parents 0cc3054 + 3f39af7 commit 76047d0

21 files changed

+259
-19
lines changed

COVERAGE.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# Coverage Analysis
3+
4+
This project can be compiled for coverage analysis using [bisect_ppx]. By
5+
default, this is not done. To compile for coverage analysis, do:
6+
7+
make coverage
8+
make
9+
10+
The `coverage` target adds the rules in `_tags.coverage` to the `_tags`
11+
file, which in turn causes all code to be compiled for coverage
12+
analysis. The `_tags.coverage` file could be tweaked to control which
13+
files get instrumented.
14+
15+
## Support Files
16+
17+
See [profiling/coverage.ml](./profiling/coverage.ml) for the run-time
18+
setup of coverage profiling. This code has no effect when not profiling
19+
during execution. Once [bixect_ppx] has better defaults we could get rid
20+
of it.
21+
22+
## Execution and Logging
23+
24+
During program execution, a binary writes coverage data to
25+
26+
/tmp/bisect-<binary>-*.out
27+
28+
This can be overridden by setting the `BISECT_FILE` environment
29+
variable, which is otherwise set at startup using the code in
30+
`profiling/coverage.ml`;
31+
32+
## Analysis
33+
34+
See the [bisect_ppx] documentation for details but try from the
35+
top-level directory:
36+
37+
bisect-ppx-report -I _build -html coverage /tmp/bisect-*.out
38+
39+
This creates an HTML document in [coverage/](./coverage].
40+
41+
[bisect_ppx]: https://github.com/aantron/bisect_ppx
42+
43+
44+
45+

INSTALL

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
2+
# Installation
3+
14
The easiest way to install is via opam:
25

36
opam init
47
opam remote add xen-org git://github.com/xen-org/opam-repo-dev
58
opam install xcp-networkd
69

10+
# Coverage Profiling
11+
12+
This code can be instrumented for coverage profiling:
13+
14+
make coverage
15+
make
16+
17+
See [COVERAGE.md](./COVERAGE.md) for details and
18+
[profiling/](./profiling/) for supporting code.
19+
720

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,21 @@ clean:
4747
@ocamlbuild -clean
4848
@rm -f setup.data setup.log setup.bin
4949
rm networkd/version.ml
50-
rm xcp-networkd xcp-networkd.1
50+
rm xcp-networkd.1
51+
52+
53+
# make coverage - prepares for building with coverage analysis
54+
# make uncover - reverses the setup from "make coverage"
55+
# make report - create coverage/index.html
56+
57+
coverage: _tags _tags.coverage
58+
test ! -f _tags.orig && mv _tags _tags.orig || true
59+
cat _tags.coverage _tags.orig > _tags
60+
61+
uncover: _tags.orig
62+
mv _tags.orig _tags
63+
64+
report:
65+
bisect-ppx-report -I _build -html coverage /tmp/bisect-network*out
66+
67+
.PHONY: report coverage uncover

README.markdown

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
2+
# XCP Networkd
3+
14
Xen API (or xapi) is a management stack that configures and controls
25
Xen-enabled hosts and resource pools, and co-ordinates resources
36
within the pool. Xapi exposes the Xen API interface for many
47
languages and is a component of the Xen Cloud Platform (XCP) project.
5-
Xen API is written mostly in [Ocaml](http://caml.inria.fr/ocaml/) 3.12.
8+
Xen API is written mostly in [OCaml](http://ocaml.org/) 3.12.
69

710
Xen Cloud Platform (XCP) is an open source enterprise-ready server
811
virtualization and cloud computing platform. XCP builds on the Xen
@@ -22,3 +25,5 @@ Links:
2225

2326
You can usually find the developers hanging out in #xen-api on
2427
freenode.
28+
29+

_oasis

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ License: LGPL-2.1 with OCaml linking exception
77
Plugins: META (0.2)
88
BuildTools: ocamlbuild
99

10+
Library profiling
11+
CompiledObject: best
12+
Path: profiling
13+
Install: false
14+
Modules: Coverage
15+
BuildDepends:
16+
1017
Library networklibs
1118
CompiledObject: best
1219
Path: lib
1320
Findlibname: network-libs
1421
Modules: Network_config, Network_utils
15-
BuildDepends: forkexec, stdext, threads, rpclib, stdext, xcp-inventory, xcp.network
22+
BuildDepends:
23+
forkexec,
24+
stdext,
25+
threads,
26+
rpclib,
27+
stdext,
28+
xcp-inventory,
29+
xcp.network
1630
CSources: link_stubs.c, netdev.h
1731
CCOpt: -Wno-unused-function -g -ggdb
1832

@@ -22,22 +36,43 @@ Executable xcp_networkd
2236
MainIs: networkd.ml
2337
Custom: true
2438
Install: false
25-
BuildDepends: threads, rpclib, rpclib.unix, forkexec, stdext, xcp-inventory, network-libs, xen-api-client, xcp, xcp.network, netlink
39+
BuildDepends:
40+
profiling,
41+
threads,
42+
rpclib,
43+
rpclib.unix,
44+
forkexec,
45+
stdext,
46+
xcp-inventory,
47+
network-libs,
48+
xen-api-client,
49+
xcp,
50+
xcp.network,
51+
netlink
2652

2753
Executable networkd_db
2854
CompiledObject: best
2955
Path: networkd_db
3056
MainIs: networkd_db.ml
3157
Custom: true
3258
Install: false
33-
BuildDepends: network-libs, stdext, threads, xcp.network
59+
BuildDepends:
60+
profiling,
61+
network-libs,
62+
stdext,
63+
threads,
64+
xcp.network
3465

3566
Executable network_test
3667
CompiledObject: best
3768
Path: test
3869
MainIs: network_test.ml
3970
Install: false
40-
BuildDepends: stdext, oUnit, network-libs
71+
BuildDepends:
72+
profiling,
73+
stdext,
74+
oUnit,
75+
network-libs
4176

4277
Test test_networkd
4378
Run$: flag(tests)
@@ -48,5 +83,11 @@ Executable cli
4883
CompiledObject: best
4984
Path: cli
5085
MainIs: network_cli.ml
51-
BuildDepends: cmdliner, stdext, network-libs, xcp, xcp.network
86+
BuildDepends:
87+
profiling,
88+
cmdliner,
89+
stdext,
90+
network-libs,
91+
xcp,
92+
xcp.network
5293

_tags

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 24d382d63f193063ab9b3c2a825d1463)
2+
# DO NOT EDIT (digest: 6a8937157d81341f64a601d75a86be7f)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -14,6 +14,8 @@ true: annot, bin_annot
1414
".git": not_hygienic
1515
"_darcs": -traverse
1616
"_darcs": not_hygienic
17+
# Library profiling
18+
"profiling/profiling.cmxs": use_profiling
1719
# Library networklibs
1820
"lib/networklibs.cmxs": use_networklibs
1921
<lib/*.ml{,i,y}>: oasis_library_networklibs_ccopt
@@ -43,6 +45,7 @@ true: annot, bin_annot
4345
<networkd/networkd.{native,byte}>: pkg_xcp.network
4446
<networkd/networkd.{native,byte}>: pkg_xen-api-client
4547
<networkd/networkd.{native,byte}>: use_networklibs
48+
<networkd/networkd.{native,byte}>: use_profiling
4649
<networkd/*.ml{,i,y}>: pkg_forkexec
4750
<networkd/*.ml{,i,y}>: pkg_netlink
4851
<networkd/*.ml{,i,y}>: pkg_rpclib
@@ -54,6 +57,7 @@ true: annot, bin_annot
5457
<networkd/*.ml{,i,y}>: pkg_xcp.network
5558
<networkd/*.ml{,i,y}>: pkg_xen-api-client
5659
<networkd/*.ml{,i,y}>: use_networklibs
60+
<networkd/*.ml{,i,y}>: use_profiling
5761
<networkd/networkd.{native,byte}>: custom
5862
# Executable networkd_db
5963
<networkd_db/networkd_db.{native,byte}>: pkg_forkexec
@@ -63,13 +67,15 @@ true: annot, bin_annot
6367
<networkd_db/networkd_db.{native,byte}>: pkg_xcp-inventory
6468
<networkd_db/networkd_db.{native,byte}>: pkg_xcp.network
6569
<networkd_db/networkd_db.{native,byte}>: use_networklibs
70+
<networkd_db/networkd_db.{native,byte}>: use_profiling
6671
<networkd_db/*.ml{,i,y}>: pkg_forkexec
6772
<networkd_db/*.ml{,i,y}>: pkg_rpclib
6873
<networkd_db/*.ml{,i,y}>: pkg_stdext
6974
<networkd_db/*.ml{,i,y}>: pkg_threads
7075
<networkd_db/*.ml{,i,y}>: pkg_xcp-inventory
7176
<networkd_db/*.ml{,i,y}>: pkg_xcp.network
7277
<networkd_db/*.ml{,i,y}>: use_networklibs
78+
<networkd_db/*.ml{,i,y}>: use_profiling
7379
<networkd_db/networkd_db.{native,byte}>: custom
7480
# Executable network_test
7581
<test/network_test.{native,byte}>: pkg_forkexec
@@ -80,6 +86,7 @@ true: annot, bin_annot
8086
<test/network_test.{native,byte}>: pkg_xcp-inventory
8187
<test/network_test.{native,byte}>: pkg_xcp.network
8288
<test/network_test.{native,byte}>: use_networklibs
89+
<test/network_test.{native,byte}>: use_profiling
8390
<test/*.ml{,i,y}>: pkg_forkexec
8491
<test/*.ml{,i,y}>: pkg_oUnit
8592
<test/*.ml{,i,y}>: pkg_rpclib
@@ -88,6 +95,7 @@ true: annot, bin_annot
8895
<test/*.ml{,i,y}>: pkg_xcp-inventory
8996
<test/*.ml{,i,y}>: pkg_xcp.network
9097
<test/*.ml{,i,y}>: use_networklibs
98+
<test/*.ml{,i,y}>: use_profiling
9199
# Executable cli
92100
<cli/network_cli.{native,byte}>: pkg_cmdliner
93101
<cli/network_cli.{native,byte}>: pkg_forkexec
@@ -98,6 +106,7 @@ true: annot, bin_annot
98106
<cli/network_cli.{native,byte}>: pkg_xcp-inventory
99107
<cli/network_cli.{native,byte}>: pkg_xcp.network
100108
<cli/network_cli.{native,byte}>: use_networklibs
109+
<cli/network_cli.{native,byte}>: use_profiling
101110
<cli/*.ml{,i,y}>: pkg_cmdliner
102111
<cli/*.ml{,i,y}>: pkg_forkexec
103112
<cli/*.ml{,i,y}>: pkg_rpclib
@@ -107,5 +116,6 @@ true: annot, bin_annot
107116
<cli/*.ml{,i,y}>: pkg_xcp-inventory
108117
<cli/*.ml{,i,y}>: pkg_xcp.network
109118
<cli/*.ml{,i,y}>: use_networklibs
119+
<cli/*.ml{,i,y}>: use_profiling
110120
# OASIS_STOP
111121

_tags.coverage

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# START_COVERAGE
2+
# coverage analysis with bisect_ppx
3+
# compile and link with package bisect_ppx
4+
<**/*.ml{,i,y}>: pkg_bisect_ppx
5+
<**/*.native>: pkg_bisect_ppx
6+
# END_COVERAGE

cli/network_cli.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,6 @@ let cmds = [
350350
config_cmd]
351351

352352
let _ =
353+
Coverage.init "network_cli";
353354
match Term.eval_choice default_cmd cmds with
354355
| `Error _ -> exit 1 | _ -> exit 0

myocamlbuild.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(* OASIS_START *)
2-
(* DO NOT EDIT (digest: 4ff56aec2dfea165b1692e299cedba7e) *)
2+
(* DO NOT EDIT (digest: cda025dade953b8f1e9b18cca6f3e0fb) *)
33
module OASISGettext = struct
44
(* # 22 "src/oasis/OASISGettext.ml" *)
55

@@ -607,7 +607,8 @@ end
607607
open Ocamlbuild_plugin;;
608608
let package_default =
609609
{
610-
MyOCamlbuildBase.lib_ocaml = [("networklibs", ["lib"], [])];
610+
MyOCamlbuildBase.lib_ocaml =
611+
[("profiling", ["profiling"], []); ("networklibs", ["lib"], [])];
611612
lib_c = [("networklibs", "lib", ["lib/netdev.h"])];
612613
flags =
613614
[
@@ -627,10 +628,10 @@ let package_default =
627628
];
628629
includes =
629630
[
630-
("test", ["lib"]);
631-
("networkd_db", ["lib"]);
632-
("networkd", ["lib"]);
633-
("cli", ["lib"])
631+
("test", ["lib"; "profiling"]);
632+
("networkd_db", ["lib"; "profiling"]);
633+
("networkd", ["lib"; "profiling"]);
634+
("cli", ["lib"; "profiling"])
634635
]
635636
}
636637
;;
@@ -639,6 +640,6 @@ let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false}
639640

640641
let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;;
641642

642-
# 643 "myocamlbuild.ml"
643+
# 644 "myocamlbuild.ml"
643644
(* OASIS_STOP *)
644645
Ocamlbuild_plugin.dispatch dispatch_default;;

networkd/networkd.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ let options = [
5454
"mac-table-size", Arg.Set_int Network_utils.mac_table_size, (fun () -> string_of_int !Network_utils.mac_table_size), "Default value for the mac-table-size openvswitch parameter (see ovs-vswitchd.conf.db.5)";
5555
]
5656

57+
5758
let start server =
5859
Network_monitor_thread.start ();
5960
Network_server.on_startup ();
@@ -79,6 +80,7 @@ let doc = String.concat "\n" [
7980
]
8081

8182
let _ =
83+
Coverage.init "networkd";
8284
begin match Xcp_service.configure2
8385
~name:Sys.argv.(0)
8486
~version:Version.version

0 commit comments

Comments
 (0)