Re: [cocci] Searching for duplicate exception handling code with SmPL?
Julia Lawall <[email protected]> Fri, 19 Jun 2026 18:57:59 +0200 (CEST)
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323329-885796785-1781888279=:2629565
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8BIT
On Fri, 19 Jun 2026, Markus Elfring wrote:
> > > file|function name|incidence
> > > fs/hpfs/dnode.c|map_fnode_dirent|40
> …
>
> > How will the software run time characteristics evolve further?
>
> I hope again that this information can trigger more constructive clarifications
> also with the help of the following SmPL script variant.
>
>
> @initialize:python@
> @@
> import sys, time
> delimiter = "|"
>
> def convert_to_seconds(x):
> return x / (10 ** 9)
>
> def get_seconds():
> return convert_to_seconds(time.time_ns())
>
> def display_data(source1, source2):
> x = time.time_ns()
> sys.stderr.write(f"display_data() was called after {x - init_time} ns from initialisation.\n")
>
> place1 = source1[0]
> place2 = source2[0]
> if (place1.line == place2.line) and (place1.column == place2.column):
> sys.stdout.write(delimiter.join(('"same position"',
> place1.current_element,
> place1.file,
> place1.line,
> str(int(place1.column) + 1),
> '"-"',
> '"-"'
> ))
> + "\n")
>
> else:
> sys.stdout.write(delimiter.join(('"update candidate"',
> place1.current_element,
> place1.file,
> place1.line,
> str(int(place1.column) + 1),
> place2.line,
> str(int(place2.column) + 1)))
> + "\n")
>
> sys.stderr.write(f"display_data() was finished after {time.time_ns() - x} ns.\n")
>
> init_time = time.time_ns()
> sys.stderr.write(f"{convert_to_seconds(init_time)}: Initialisation was finished.\n")
>
> @searching exists@
> expression e, x;
> identifier item, rc;
> position p1, p2;
> @@
> if (...)
> {
> ... when != rc = e
> when != item = x
> kfree@p1(item);
> return rc;
> }
> ... when any
> if (...)
> {
> ... when != rc = e
> when != item = x
Do you really require that e and x bind to the same things at the two
occurrences? If the running time is slow, that is probably why?
julia
> kfree@p2(item);
> return rc;
> }
>
> @script:python collection@
> p1 << searching.p1;
> p2 << searching.p2;
> @@
> display_data(p1, p2)
>
>
>
> Function implementation example:
> https://elixir.bootlin.com/linux/v7.1/source/fs/hpfs/dnode.c#L994-L1095
>
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time /usr/bin/spatch --no-loops ../janitor/list_selected_duplicate_statements_in_if_branches9.cocci map_fnode_dirent-excerpt-20260618.c
> …
> 1781883816.6302867: Initialisation was finished.
> HANDLING: map_fnode_dirent-excerpt-20260618.c
> display_data() was called after 3163180203 ns from initialisation.
> "update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|37|3
> display_data() was finished after 108330 ns.
> display_data() was called after 3163385848 ns from initialisation.
> "update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|46|3
> display_data() was finished after 33643 ns.
> display_data() was called after 3163493101 ns from initialisation.
> "update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|58|3
> display_data() was finished after 25862 ns.
> display_data() was called after 3163597031 ns from initialisation.
> "update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|72|5
> display_data() was finished after 23952 ns.
> …
> real 0m3,433s
> user 0m3,321s
> sys 0m0,107s
>
>
> Can such measurements influence any development approaches?
>
> Would you occasionally observe also in your test environments that data processing
> durations would look prohibitive?
>
>
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time /usr/bin/spatch --no-loops ../janitor/list_selected_duplicate_statements_in_if_branches8.cocci map_fnode_dirent-excerpt-20260618.c
> …
> Using SQLAlchemy version:
> 2.0.50
> 1781884889.1493413: Initialisation was finished.
> HANDLING: map_fnode_dirent-excerpt-20260618.c
> ^C C-c intercepted, will do some cleaning before exiting
>
> real 22m54,500s
> user 22m47,974s
> sys 0m2,294s
>
>
> How can the software situation be improved further here?
>
> Regards,
> Markus
>
--8323329-885796785-1781888279=:2629565--