Message ID | ebe54c78-9692-357f-55d0-b0714c5ca6ea@suse.cz |
---|---|
State | New |
Headers | show |
Series | gcov: add new option -t that prints output to stdout (PR gcov-profile/84846). | expand |
I forgot to document the option. Fixed that.
Martin
From 81236af4d1fac4c278b29e65162b3f73593a7d08 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 18 May 2018 14:22:06 +0200
Subject: [PATCH] gcov: add new option -t that prints output to stdout (PR
gcov-profile/84846).
gcc/ChangeLog:
2018-05-18 Martin Liska <mliska@suse.cz>
PR gcov-profile/84846
* gcov.c (print_usage): Add new -t option.
(process_args): Handle the option.
(generate_results): Use stdout as output when requested by
the option.
gcc/ChangeLog:
2018-05-18 Martin Liska <mliska@suse.cz>
PR gcov-profile/84846
* doc/gcov.texi: Document -t option of gcov tool.
---
gcc/doc/gcov.texi | 5 +++++
gcc/gcov.c | 36 +++++++++++++++++++++++++++++-------
2 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 9d5cdbc8e03..c249a28c12e 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -134,6 +134,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
[@option{-p}|@option{--preserve-paths}]
[@option{-r}|@option{--relative-only}]
[@option{-s}|@option{--source-prefix} @var{directory}]
+ [@option{-t}|@option{--stdout}]
[@option{-u}|@option{--unconditional-branches}]
[@option{-x}|@option{--hash-filenames}]
@var{files}
@@ -319,6 +320,10 @@ directory, and the pathname to the source directory is not wanted when
determining the output file names. Note that this prefix detection is
applied before determining whether the source file is absolute.
+@item -t
+@itemx --stdout
+Output to standard output instead of output files.
+
@item -u
@itemx --unconditional-branches
When branch probabilities are given, include those of unconditional branches.
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 92972e29b4d..0ee9c0e55b7 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -462,6 +462,10 @@ static int flag_unconditional = 0;
static int flag_gcov_file = 1;
+/* Output to stdout instead to a gcov file. */
+
+static int flag_use_stdout = 0;
+
/* Output progress indication if this is true. This is off by default
and can be turned on by the -d option. */
@@ -831,6 +835,7 @@ print_usage (int error_p)
fnotice (file, " -p, --preserve-paths Preserve all pathname components\n");
fnotice (file, " -r, --relative-only Only show data for relative sources\n");
fnotice (file, " -s, --source-prefix DIR Source prefix to elide\n");
+ fnotice (file, " -t, --stdout Output to stdout instead of a file\n");
fnotice (file, " -u, --unconditional-branches Show unconditional branch counts too\n");
fnotice (file, " -v, --version Print version number, then exit\n");
fnotice (file, " -w, --verbose Print verbose informations\n");
@@ -874,6 +879,7 @@ static const struct option options[] =
{ "object-directory", required_argument, NULL, 'o' },
{ "object-file", required_argument, NULL, 'o' },
{ "source-prefix", required_argument, NULL, 's' },
+ { "stdout", no_argument, NULL, 't' },
{ "unconditional-branches", no_argument, NULL, 'u' },
{ "display-progress", no_argument, NULL, 'd' },
{ "hash-filenames", no_argument, NULL, 'x' },
@@ -888,7 +894,7 @@ process_args (int argc, char **argv)
{
int opt;
- const char *opts = "abcdfhijklmno:prs:uvwx";
+ const char *opts = "abcdfhijklmno:prs:tuvwx";
while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
{
switch (opt)
@@ -952,6 +958,9 @@ process_args (int argc, char **argv)
case 'w':
flag_verbose = 1;
break;
+ case 't':
+ flag_use_stdout = 1;
+ break;
case 'v':
print_version ();
/* print_version will exit. */
@@ -1293,7 +1302,7 @@ generate_results (const char *file_name)
file_name = canonicalize_name (file_name);
}
- if (flag_gcov_file && flag_intermediate_format)
+ if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout)
{
/* Open the intermediate file. */
gcov_intermediate_filename = get_gcov_intermediate_filename (file_name);
@@ -1325,7 +1334,9 @@ generate_results (const char *file_name)
}
accumulate_line_counts (src);
- function_summary (&src->coverage, "File");
+
+ if (!flag_use_stdout)
+ function_summary (&src->coverage, "File");
total_lines += src->coverage.lines;
total_executed += src->coverage.lines_executed;
if (flag_gcov_file)
@@ -1333,14 +1344,25 @@ generate_results (const char *file_name)
if (flag_intermediate_format)
/* Output the intermediate format without requiring source
files. This outputs a section to a *single* file. */
- output_intermediate_file (gcov_intermediate_file, src);
+ output_intermediate_file ((flag_use_stdout
+ ? stdout : gcov_intermediate_file), src);
else
- output_gcov_file (file_name, src);
- fnotice (stdout, "\n");
+ {
+ if (flag_use_stdout)
+ {
+ if (src->coverage.lines)
+ output_lines (stdout, src);
+ }
+ else
+ {
+ output_gcov_file (file_name, src);
+ fnotice (stdout, "\n");
+ }
+ }
}
}
- if (flag_gcov_file && flag_intermediate_format)
+ if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout)
{
/* Now we've finished writing the intermediate file. */
fclose (gcov_intermediate_file);
On 05/18/2018 08:29 AM, Martin Liška wrote: > Hi. > > It's requested by LCOV folks, they want to be able to print to stdout > instead of into a file. > > Survives make check -k -j10 RUNTESTFLAGS="gcov.exp" I guess you looked at abstracting the output file a bit earlier, and passing in a FILE* to the outputting routines? That would be nicer, but if not practical, this is ok. nathan
On 05/18/2018 02:46 PM, Nathan Sidwell wrote: > On 05/18/2018 08:29 AM, Martin Liška wrote: >> Hi. >> >> It's requested by LCOV folks, they want to be able to print to stdout >> instead of into a file. >> >> Survives make check -k -j10 RUNTESTFLAGS="gcov.exp" > > I guess you looked at abstracting the output file a bit earlier, and passing in a FILE* to the outputting routines? That would be nicer, but if not practical, this is ok. Would be nice, but as we have quite some prologue and epilogue for file creation, let me please install the patch. Thanks, Martin > > nathan >
diff --git a/gcc/gcov.c b/gcc/gcov.c index 92972e29b4d..0ee9c0e55b7 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -462,6 +462,10 @@ static int flag_unconditional = 0; static int flag_gcov_file = 1; +/* Output to stdout instead to a gcov file. */ + +static int flag_use_stdout = 0; + /* Output progress indication if this is true. This is off by default and can be turned on by the -d option. */ @@ -831,6 +835,7 @@ print_usage (int error_p) fnotice (file, " -p, --preserve-paths Preserve all pathname components\n"); fnotice (file, " -r, --relative-only Only show data for relative sources\n"); fnotice (file, " -s, --source-prefix DIR Source prefix to elide\n"); + fnotice (file, " -t, --stdout Output to stdout instead of a file\n"); fnotice (file, " -u, --unconditional-branches Show unconditional branch counts too\n"); fnotice (file, " -v, --version Print version number, then exit\n"); fnotice (file, " -w, --verbose Print verbose informations\n"); @@ -874,6 +879,7 @@ static const struct option options[] = { "object-directory", required_argument, NULL, 'o' }, { "object-file", required_argument, NULL, 'o' }, { "source-prefix", required_argument, NULL, 's' }, + { "stdout", no_argument, NULL, 't' }, { "unconditional-branches", no_argument, NULL, 'u' }, { "display-progress", no_argument, NULL, 'd' }, { "hash-filenames", no_argument, NULL, 'x' }, @@ -888,7 +894,7 @@ process_args (int argc, char **argv) { int opt; - const char *opts = "abcdfhijklmno:prs:uvwx"; + const char *opts = "abcdfhijklmno:prs:tuvwx"; while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1) { switch (opt) @@ -952,6 +958,9 @@ process_args (int argc, char **argv) case 'w': flag_verbose = 1; break; + case 't': + flag_use_stdout = 1; + break; case 'v': print_version (); /* print_version will exit. */ @@ -1293,7 +1302,7 @@ generate_results (const char *file_name) file_name = canonicalize_name (file_name); } - if (flag_gcov_file && flag_intermediate_format) + if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout) { /* Open the intermediate file. */ gcov_intermediate_filename = get_gcov_intermediate_filename (file_name); @@ -1325,7 +1334,9 @@ generate_results (const char *file_name) } accumulate_line_counts (src); - function_summary (&src->coverage, "File"); + + if (!flag_use_stdout) + function_summary (&src->coverage, "File"); total_lines += src->coverage.lines; total_executed += src->coverage.lines_executed; if (flag_gcov_file) @@ -1333,14 +1344,25 @@ generate_results (const char *file_name) if (flag_intermediate_format) /* Output the intermediate format without requiring source files. This outputs a section to a *single* file. */ - output_intermediate_file (gcov_intermediate_file, src); + output_intermediate_file ((flag_use_stdout + ? stdout : gcov_intermediate_file), src); else - output_gcov_file (file_name, src); - fnotice (stdout, "\n"); + { + if (flag_use_stdout) + { + if (src->coverage.lines) + output_lines (stdout, src); + } + else + { + output_gcov_file (file_name, src); + fnotice (stdout, "\n"); + } + } } } - if (flag_gcov_file && flag_intermediate_format) + if (flag_gcov_file && flag_intermediate_format && !flag_use_stdout) { /* Now we've finished writing the intermediate file. */ fclose (gcov_intermediate_file);