aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcov.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2017-10-31 16:31:25 +0100
committerMartin Liska <marxin@gcc.gnu.org>2017-10-31 15:31:25 +0000
commit29a4ef18ec053a15ccc224d4cc5c8860b03496b4 (patch)
tree71b33bb93ae5a9f64c217d8e5eea0a24f2ea6b54 /gcc/gcov.c
parentcbb449d1f73ad948968b2e55387403f4ee58e0e8 (diff)
downloadgcc-29a4ef18ec053a15ccc224d4cc5c8860b03496b4.zip
gcc-29a4ef18ec053a15ccc224d4cc5c8860b03496b4.tar.gz
gcc-29a4ef18ec053a15ccc224d4cc5c8860b03496b4.tar.bz2
GCOV: add -j argument (human readable format).
2017-10-31 Martin Liska <mliska@suse.cz> * doc/gcov.texi: Document new option. * gcov.c (print_usage): Likewise print it. (process_args): Support the argument. (format_count): New function. (format_gcov): Use the function. 2017-10-31 Martin Liska <mliska@suse.cz> * g++.dg/gcov/loop.C: New test. * lib/gcov.exp: Support human readable format for counts. From-SVN: r254269
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r--gcc/gcov.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/gcc/gcov.c b/gcc/gcov.c
index f1e7777..48bcdc0 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -431,6 +431,10 @@ static int flag_use_colors = 0;
static int flag_all_blocks = 0;
+/* Output human readable numbers. */
+
+static int flag_human_readable_numbers = 0;
+
/* Output summary info for each function. */
static int flag_function_summary = 0;
@@ -742,6 +746,7 @@ print_usage (int error_p)
fnotice (file, " -f, --function-summaries Output summaries for each function\n");
fnotice (file, " -h, --help Print this help, then exit\n");
fnotice (file, " -i, --intermediate-format Output .gcov file in intermediate text format\n");
+ fnotice (file, " -j, --human-readable Output human readable numbers\n");
fnotice (file, " -k, --use-colors Emit colored output\n");
fnotice (file, " -l, --long-file-names Use long output file names for included\n\
source files\n");
@@ -784,6 +789,7 @@ static const struct option options[] =
{ "branch-probabilities", no_argument, NULL, 'b' },
{ "branch-counts", no_argument, NULL, 'c' },
{ "intermediate-format", no_argument, NULL, 'i' },
+ { "human-readable", no_argument, NULL, 'j' },
{ "no-output", no_argument, NULL, 'n' },
{ "long-file-names", no_argument, NULL, 'l' },
{ "function-summaries", no_argument, NULL, 'f' },
@@ -807,7 +813,7 @@ process_args (int argc, char **argv)
{
int opt;
- const char *opts = "abcdfhiklmno:prs:uvwx";
+ const char *opts = "abcdfhijklmno:prs:uvwx";
while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
{
switch (opt)
@@ -830,6 +836,9 @@ process_args (int argc, char **argv)
case 'l':
flag_long_names = 1;
break;
+ case 'j':
+ flag_human_readable_numbers = 1;
+ break;
case 'k':
flag_use_colors = 1;
break;
@@ -1914,6 +1923,33 @@ add_branch_counts (coverage_t *coverage, const arc_t *arc)
}
}
+/* Format COUNT, if flag_human_readable_numbers is set, return it human
+ readable format. */
+
+static char const *
+format_count (gcov_type count)
+{
+ static char buffer[64];
+ const char *units = " kMGTPEZY";
+
+ if (count < 1000 || !flag_human_readable_numbers)
+ {
+ sprintf (buffer, "%" PRId64, count);
+ return buffer;
+ }
+
+ unsigned i;
+ gcov_type divisor = 1;
+ 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;
+}
+
/* Format a GCOV_TYPE integer as either a percent ratio, or absolute
count. If dp >= 0, format TOP/BOTTOM * 100 to DP decimal places.
If DP is zero, no decimal point is printed. Only print 100% when
@@ -1961,7 +1997,7 @@ format_gcov (gcov_type top, gcov_type bottom, int dp)
}
}
else
- sprintf (buffer, "%" PRId64, (int64_t)top);
+ return format_count (top);
return buffer;
}