[PATCH 4/7] GCOV: add -j argument (human readable format).

Martin Liška mliska@suse.cz
Tue Oct 31 14:04:00 GMT 2017


On 10/31/2017 01:05 PM, Nathan Sidwell wrote:
> On 10/31/2017 07:49 AM, Martin Liška wrote:
>> On 10/30/2017 01:35 PM, Nathan Sidwell wrote:
> 
>> Is the patch fine to be installed?
> not quite ...
> 
> 
> +  gcov_type divisor = 1;
> +  for (unsigned i = 0; i < strlen (units); i++)
> +    {
> +      if (v < (1000 * divisor))
> +    {
> +      gcov_type r = (gcov_type)roundf (v / divisor);
> +      sprintf (buffer, "%" PRId64 "%c", r, units[i]);
> +      return buffer;
> +    }
> +      divisor *= 1000;
> +    }
> 
> This doesn't deal with rounding to 1000, which will look a bit odd. It'll also overflow if we ever get 10^24 counts (yeah, like that'll ever happen in this universe).  We may as well not use floats either.

Hi.

Do you mean numbers a bit smaller than 1000 or bit bigger? Do you have an example that will
be handled in a different way?

> 
> Excuse the poor formatting
> 
>    unsigned i;
>    for (i = 0; units[i+1]; i++, divisor *= 1000) {
>      if (count + divisor / 2 < 1000 * divisor)
>         break;
>    }
>    gcov_type r  = (count + divisor / 2) / divisor;
>    sprintf (buffer, "%" PRId64 "%c", r, units[i]);
>    return buffer;
> 

I've adapted your code snippet.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-GCOV-add-j-argument-human-readable-format-v3.patch
Type: text/x-patch
Size: 7507 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20171031/9f092081/attachment.bin>


More information about the Gcc-patches mailing list