diff options
author | xur <xur@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-08 21:51:41 +0000 |
---|---|---|
committer | xur <xur@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-08 21:51:41 +0000 |
commit | 26054e0bbc61f13035da35075ea18a25c18fd3bb (patch) | |
tree | a5055f5dbc707735c59ee18b1ffc1a4a658b4ca5 /gcc/gcov-tool.c | |
parent | 8bb8c293aacc7683c91fa0fe6600773b4672730b (diff) | |
download | gcc-26054e0bbc61f13035da35075ea18a25c18fd3bb.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@216015 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gcov-tool.c')
-rw-r--r-- | gcc/gcov-tool.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c index 61e82a3dcb1..db23bd7bc49 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); } |