aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2014-10-08 21:51:41 +0000
committerRong Xu <xur@gcc.gnu.org>2014-10-08 21:51:41 +0000
commit9b84e7a8365e61211975aceec67d086aceee0c58 (patch)
treea5055f5dbc707735c59ee18b1ffc1a4a658b4ca5 /gcc
parenta41bb2c947782287f983daac7807f0e0e4ef4b65 (diff)
downloadgcc-9b84e7a8365e61211975aceec67d086aceee0c58.zip
gcc-9b84e7a8365e61211975aceec67d086aceee0c58.tar.gz
gcc-9b84e7a8365e61211975aceec67d086aceee0c58.tar.bz2
Add overlap functionality to gcov-tool.
2014-10-08 Rong Xu <xur@google.com> * gcc/gcov-tool.c (profile_overlap): New driver function to compute profile overlap. (print_overlap_usage_message): New. (overlap_usage): New. (do_overlap): New. (print_usage): Add calls to overlap function. (main): Ditto. * libgcc/libgcov-util.c (read_gcda_file): Fix format. (find_match_gcov_info): Ditto. (calculate_2_entries): New. (compute_one_gcov): Ditto. (gcov_info_count_all_cold): Ditto. (gcov_info_count_all_zero): Ditto. (extract_file_basename): Ditto. (get_file_basename): Ditto. (set_flag): Ditto. (matched_gcov_info): Ditto. (calculate_overlap): Ditto. (gcov_profile_overlap): Ditto. * libgcc/libgcov-driver.c (compute_summary): Make it avavilable for external calls. * gcc/doc/gcov-tool.texi: Add documentation. From-SVN: r216015
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/doc/gcov-tool.texi46
-rw-r--r--gcc/gcov-tool.c119
3 files changed, 174 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 289f224..9491d8b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2014-10-08 Rong Xu <xur@google.com>
+
+ * gcov-tool.c (profile_overlap): New driver function
+ to compute profile overlap.
+ (print_overlap_usage_message): New.
+ (overlap_usage): New.
+ (do_overlap): New.
+ (print_usage): Add calls to overlap function.
+ (main): Ditto.
+ * doc/gcov-tool.texi: Add documentation.
+
2014-10-08 Steve Ellcey <sellcey@mips.com>
* config/mips/mti-linux.h (DRIVER_SELF_SPECS): Change
diff --git a/gcc/doc/gcov-tool.texi b/gcc/doc/gcov-tool.texi
index ff8b9e2..3a66872 100644
--- a/gcc/doc/gcov-tool.texi
+++ b/gcc/doc/gcov-tool.texi
@@ -103,8 +103,7 @@ in these kind of counters.
@section Invoking @command{gcov-tool}
@smallexample
-gcov-tool @r{[}@var{global-options}@r{]} SUB_COMMAND
-@r{[}@var{sub_command-options}@r{]} @var{profile_dir}
+gcov-tool @r{[}@var{global-options}@r{]} SUB_COMMAND @r{[}@var{sub_command-options}@r{]} @var{profile_dir}
@end smallexample
@command{gcov-tool} accepts the following options:
@@ -123,6 +122,15 @@ gcov-tool rewrite [rewrite-options] @var{directory}
[@option{-o}|@option{--output} @var{directory}]
[@option{-s}|@option{--scale} @var{float_or_simple-frac_value}]
[@option{-n}|@option{--normalize} @var{long_long_value}]
+
+gcov-tool overlap [overlap-options] @var{directory1} @var{directory2}
+ [@option{-v}|@option{--verbose}]
+ [@option{-h}|@option{--hotonly}]
+ [@option{-f}|@option{--function}]
+ [@option{-F}|@option{--fullname}]
+ [@option{-o}|@option{--object}]
+ [@option{-t}|@option{--hot_threshold}] @var{float}
+
@c man end
@c man begin SEEALSO
gpl(7), gfdl(7), fsf-funding(7), gcc(1), gcov(1) and the Info entry for
@@ -182,8 +190,42 @@ or simple fraction value form, such 1, 2, 2/3, and 5/3.
@itemx --normalize <long_long_value>
Normalize the profile. The specified value is the max counter value
in the new profile.
+@end table
+
+@item overlap
+Computer the overlap score between the two specified profile directories.
+The overlap score is computed based on the arc profiles. It is defined as
+the sum of min (p1_counter[i] / p1_sum_all, p2_counter[i] / p2_sum_all),
+for all arc counter i, where p1_counter[i] and p2_counter[i] are two
+matched counters and p1_sum_all and p2_sum_all are the sum of counter
+values in profile 1 and profile 2, respectively.
+
+@table @gcctabopt
+@item -v
+@itemx --verbose
+Set the verbose mode.
+
+@item -h
+@itemx --hotonly
+Only print info for hot objects/functions.
+@item -f
+@itemx --function
+Print function level overlap score.
+
+@item -F
+@itemx --fullname
+Print full gcda filename.
+
+@item -o
+@itemx --object
+Print object level overlap score.
+
+@item -t @var{float}
+@itemx --hot_threshold <float>
+Set the threshold for hot counter value.
@end table
+
@end table
@c man end
diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c
index 61e82a3..db23bd7 100644
--- a/gcc/gcov-tool.c
+++ b/gcc/gcov-tool.c
@@ -39,6 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <getopt.h>
extern int 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);
extern struct gcov_info* gcov_read_profile_dir (const char*, int);
@@ -368,6 +369,121 @@ do_rewrite (int argc, char **argv)
return ret;
}
+/* Driver function to computer the overlap score b/w profile D1 and D2.
+ Return 1 on error and 0 if OK. */
+
+static int
+profile_overlap (const char *d1, const char *d2)
+{
+ struct gcov_info *d1_profile;
+ struct gcov_info *d2_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;
+
+ return gcov_profile_overlap (d1_profile, d2_profile);
+ }
+
+ return 1;
+}
+
+/* Usage message for profile overlap. */
+
+static void
+print_overlap_usage_message (int error_p)
+{
+ FILE *file = error_p ? stderr : stdout;
+
+ fnotice (file, " overlap [options] <dir1> <dir2> Compute the overlap of two profiles\n");
+ fnotice (file, " -v, --verbose Verbose mode\n");
+ fnotice (file, " -h, --hotonly Only print info for hot objects/functions\n");
+ fnotice (file, " -f, --function Print function level info\n");
+ fnotice (file, " -F, --fullname Print full filename\n");
+ fnotice (file, " -o, --object Print object level info\n");
+ fnotice (file, " -t <float>, --hot_threshold <float> Set the threshold for hotness\n");
+
+}
+
+static const struct option overlap_options[] =
+{
+ { "verbose", no_argument, NULL, 'v' },
+ { "function", no_argument, NULL, 'f' },
+ { "fullname", no_argument, NULL, 'F' },
+ { "object", no_argument, NULL, 'o' },
+ { "hotonly", no_argument, NULL, 'h' },
+ { "hot_threshold", required_argument, NULL, 't' },
+ { 0, 0, 0, 0 }
+};
+
+/* Print overlap usage and exit. */
+
+static void
+overlap_usage (void)
+{
+ fnotice (stderr, "Overlap subcomand usage:");
+ print_overlap_usage_message (true);
+ exit (FATAL_EXIT_CODE);
+}
+
+int overlap_func_level;
+int overlap_obj_level;
+int overlap_hot_only;
+int overlap_use_fullname;
+double overlap_hot_threshold = 0.005;
+
+/* Driver for profile overlap sub-command. */
+
+static int
+do_overlap (int argc, char **argv)
+{
+ int opt;
+ int ret;
+
+ optind = 0;
+ while ((opt = getopt_long (argc, argv, "vfFoht:", overlap_options, NULL)) != -1)
+ {
+ switch (opt)
+ {
+ case 'v':
+ verbose = true;
+ gcov_set_verbose ();
+ break;
+ case 'f':
+ overlap_func_level = 1;
+ break;
+ case 'F':
+ overlap_use_fullname = 1;
+ break;
+ case 'o':
+ overlap_obj_level = 1;
+ break;
+ case 'h':
+ overlap_hot_only = 1;
+ break;
+ case 't':
+ overlap_hot_threshold = atof (optarg);
+ break;
+ default:
+ overlap_usage ();
+ }
+ }
+
+ if (argc - optind == 2)
+ ret = profile_overlap (argv[optind], argv[optind+1]);
+ else
+ overlap_usage ();
+
+ return ret;
+}
+
+
/* Print a usage message and exit. If ERROR_P is nonzero, this is an error,
otherwise the output of --help. */
@@ -383,6 +499,7 @@ print_usage (int error_p)
fnotice (file, " -v, --version Print version number, then exit\n");
print_merge_usage_message (error_p);
print_rewrite_usage_message (error_p);
+ print_overlap_usage_message (error_p);
fnotice (file, "\nFor bug reporting instructions, please see:\n%s.\n",
bug_report_url);
exit (status);
@@ -471,6 +588,8 @@ main (int argc, char **argv)
return do_merge (argc - optind, argv + optind);
else if (!strcmp (sub_command, "rewrite"))
return do_rewrite (argc - optind, argv + optind);
+ else if (!strcmp (sub_command, "overlap"))
+ return do_overlap (argc - optind, argv + optind);
print_usage (true);
}