Hello Martin, On 23/03/2022 13:19, Martin Liška wrote: > On 3/23/22 10:34, Sebastian Huber wrote: > > Hello. > > Thanks for the patch. Note we're in stage4, so the patch can eventually go > in in the next stage1. ok, good. > >> The gcov_profile_merge() already had code to deal with profile >> information >> which had no counterpart to merge with.  For profile information from >> files >> with no associated counterpart, the profile information is simply used >> as is >> with the weighting transformation applied.  Make sure that >> gcov_profile_merge() >> works with an empty target profile list.  Return the merged profile list. > > Can you please provide a simple demo with a pair of profiles > where I'll see what changes? The background for this feature is that I would like to combine the gcov information obtained from several test executables. Each test executable will print something like this (log.txt): *** BEGIN OF GCOV INFO *** /home/EB/sebastian_h/src/lwip/b-xilinx_zynq_a9_qemu/init.gcda YWRjZ1IzMEKtLjW3AAAAAQMAAADcaps855EX05p4KUUAAKEBOgAAAAEAAAAAAAAAAQAAAAAAAAAB AAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEA AAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAA AAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAABAwAAACXn3k16 TDqmuIMwpAAAoQECAAAAAgAAAAAAAAAAAAABAwAAADzkvDcfSnvcuIMwpAAAoQH+////AAAAAQMA AACnWNZaIM7GWZ9hiOIAAKEBBAAAAAEAAAAAAAAAAAAAAAAAAAAAAAABAwAAAPkGW3YHFUOO6Old 2wAAoQECAAAAAQAAAAAAAAAAAAABAwAAAIvy4CE9FxuM6Old2wAAoQECAAAAAQAAAAAAAAAAAAAB AwAAANyvBDZiERlQ6Old2wAAoQECAAAAAQAAAAAAAAAAAAABAwAAACKQjCp2pYlIuIMwpAAAoQEC AAAAAQAAAAAAAAAAAAABAwAAAKSSXEjQFDluuIMwpAAAoQH+////AAAAAA== ... *** END OF GCOV INFO *** The attached script reads the log file and creates the *.gcda files using gcov-tool. Initially, the target files do not exist. > >> >> gcc/ >>     * gcov-tool.cc (gcov_profile_merge): Adjust return type. >>     (profile_merge): Allow merging of directories which contain no >> profile >>     files. >> >> libgcc/ >>     * libgcov-util.c (gcov_profile_merge): Return the list of merged >>     profiles.  Accept empty target and source profile lists. >> --- >>   gcc/gcov-tool.cc      | 27 ++++++++++----------------- >>   libgcc/libgcov-util.c | 15 +++++++++------ >>   2 files changed, 19 insertions(+), 23 deletions(-) >> >> diff --git a/gcc/gcov-tool.cc b/gcc/gcov-tool.cc >> index f4e42ae763c..2e4083a664d 100644 >> --- a/gcc/gcov-tool.cc >> +++ b/gcc/gcov-tool.cc >> @@ -40,7 +40,8 @@ see the files COPYING3 and COPYING.RUNTIME >> respectively.  If not, see >>   #endif >>   #include >> -extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, >> int, int); >> +extern struct gcov_info *gcov_profile_merge (struct gcov_info*, >> +                         struct gcov_info*, int, int); >>   extern int gcov_profile_overlap (struct gcov_info*, struct gcov_info*); >>   extern int gcov_profile_normalize (struct gcov_info*, gcov_type); >>   extern int gcov_profile_scale (struct gcov_info*, float, int, int); >> @@ -141,26 +142,18 @@ profile_merge (const char *d1, const char *d2, >> const char *out, int w1, int w2) >>   { >>     struct gcov_info *d1_profile; >>     struct gcov_info *d2_profile; >> -  int ret; >> +  struct gcov_info *merged_profile; >>     d1_profile = gcov_read_profile_dir (d1, 0); >> -  if (!d1_profile) >> -    return 1; >> - >> -  if (d2) >> -    { >> -      d2_profile = gcov_read_profile_dir (d2, 0); >> -      if (!d2_profile) >> -        return 1; >> +  d2_profile = gcov_read_profile_dir (d2, 0); > > Is it fine calling 'gcov_read_profile_dir (d2, 0)' without 'if (d2)'? Yes, the caller ensures that d1 and d2 are both provided: if (argc - optind != 2) merge_usage (); return profile_merge (argv[optind], argv[optind+1], output_dir, w1, w2); Maybe we should provide a better error message, if the user doesn't provide two directories instead of the general usage message. > >> -      /* The actual merge: we overwrite to d1_profile.  */ >> -      ret = gcov_profile_merge (d1_profile, d2_profile, w1, w2); >> +  /* The actual merge: we overwrite to d1_profile.  */ >> +  merged_profile = gcov_profile_merge (d1_profile, d2_profile, w1, w2); >> -      if (ret) >> -        return ret; >> -    } >> - >> -  gcov_output_files (out, d1_profile); >> +  if (merged_profile) >> +    gcov_output_files (out, merged_profile); >> +  else if (verbose) >> +    fnotice (stdout, "no profile files were merged\n"); >>     return 0; >>   } >> diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c >> index ba7fb924b53..e5496f4ade2 100644 >> --- a/libgcc/libgcov-util.c >> +++ b/libgcc/libgcov-util.c >> @@ -677,13 +677,13 @@ find_match_gcov_info (struct gcov_info **array, >> int size, >>      Return 0 on success: without mismatch. >>      Reutrn 1 on error.  */ > > Please adjust the function comment. Oh, yes. -- embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/