Script for determining code coverage of functions listed in pg_proc.dat

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Script for determining code coverage of functions listed in pg_proc.dat
Date: 2025-02-26 14:04:42
Message-ID: CAJ7c6TPHyN0mBQQyjkq-ke6qaKUwzRV6pcmTx8ErsgtGvzzHJA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I would like to share a script that determines code coverage of
functions that are directly accessible from SQL.

To use the script you have to build a code coverage report first, as usual:

```
git clean -dfx
meson setup --buildtype debug -DPG_TEST_EXTRA="kerberos ldap ssl"
-Db_coverage=true -Dldap=disabled -Dssl=openssl -Dcassert=true
-Dtap_tests=enabled -Dprefix=/home/eax/pginstall build
ninja -C build
PG_TEST_EXTRA=1 meson test -C build
ninja -C build coverage-html
```

Note that this will only work in the Linux environment, to my
knowledge at least.

Then execute:

```
./coverage-analyze.py > coverage.csv
```

This will give you functions listed in pg_proc.dat and where to find
them in the source code, sorted by code coverage. These functions are
easy to cover with tests, see for instance [1] and similar patches in
`git log`. I believe this can be useful to newcomers looking for an
idea of the first patch.

You can also modify the script to check the coverage of particular
functions you are interested in. Just modify this part accordingly:

```
functions = set()

with open("src/include/catalog/pg_proc.dat") as f:
proc_data = f.read()
re_str = """prosrc[ ]+=>[ ]+['"](.*?)['"]"""
for m in re.finditer(re_str, proc_data):
func_name = m.group(1)
functions.add(func_name)
```

If you want to know coverage of *all* functions, just comment this part:

```
if current_func_name not in functions:
current_func_name = None
continue
```

Please find attached the script and the compressed report. I also
uploaded a copy of the report to Google Drive [2].

As always, your thoughts and feedback are most welcomed.

[1]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=4f071349
[2]: https://docs.google.com/spreadsheets/d/1i3_tfBjMO3QbnVVnWb1uwhp5R_gdmjdx1Q9eXmjoUUA/edit?usp=sharing

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
coverage.csv.tgz application/x-gzip 28.4 KB
coverage-analyze.py text/x-python-script 3.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-02-26 14:30:49 Re: Support a wildcard in backtrace_functions
Previous Message Amit Kapila 2025-02-26 13:48:57 Re: Race condition in replication slot usage introduced by commit f41d846