2018-06-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libvtv / scripts / sum-vtv-counts.c
blobfc99498e70522a77645d27f01f4b3cdf754a8829
1 /*
2 This script sums up the counters for seeing how many virtual calls are
3 actually being verified. The flag for generating the count data is
4 "-fvtv-counts". This flag will generate two files in /tmp,
5 "vtv_count_data.log" and "vtv_class_set_sizes.log". The first file is
6 the one that contains the info I mentioned; the second one is one I
7 generated because I was curious about how big the average set size was
8 for the vtable verification work.
10 After compiling the attached program, run it on the vtv_count_data.log
11 file:
13 $ sum-counters /tmp/vtv_count_data.log
15 One can optionally pass a "--verbose" flag. This file generates an
16 output file whose name is the same as the input file, with ".summary"
17 appended to it, e.g. /tmp/vtv_count_data.log.summary . Without the
18 verbose flag, it will just contain something like this:
20 Total # virtual calls: 349123
21 Total # verified calls: 348236
22 Percent verified: 99 %
24 Total calls to __VLTRegisterSet: 42236
25 Total calls to __VLTRegisterPair: 84371
26 Total # unused vtable map vars: 1536333
28 With the --verbose flag it will also output one line for each
29 compilation unit for which it verified less than 90% of the virtual
30 calls (and there were more than 20 virtual calls in the file),
31 something like this:
33 Verified 1 out of 25 (4.00%) : foo.cc
34 Verified 27 out of 43 (62.00%) : bar.cc
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
41 void
42 usage (const char *error_text)
44 fprintf (stderr, "%s", error_text);
45 fprintf (stderr, "Usage: \n");
46 fprintf (stderr, "sum-counters <input-file> [--verbose]\n");
49 int
50 main (int argc, char **argv)
52 FILE *fp_in = NULL;
53 FILE *fp_out = NULL;
54 int sum_vcalls = 0;
55 int sum_verified = 0;
56 int sum_regset = 0;
57 int sum_regpair = 0;
58 int sum_unused = 0;
59 char fname_in[1024];
60 char fname_out[1024];
61 int total;
62 int verified;
63 int regset;
64 int regpair;
65 int unused;
66 float pct;
67 char buffer[1024];
68 int verbose = 0;
70 if (argc < 2)
72 usage ("Error: Need an input file.\n");
73 return 1;
76 fp_in = fopen (argv[1], "r");
77 if (!fp_in)
79 snprintf (buffer, 1024, "Error: Unable to open input file '%s'.\n",
80 argv[1]);
81 usage (buffer);
82 return 1;
85 if (argc == 3)
87 if (strcmp (argv[2], "--verbose") == 0)
88 verbose = 1;
89 else
91 snprintf (buffer, 1024, "Error: Unrecognized option '%s'.\n",
92 argv[2]);
93 usage (buffer);
94 return 1;
98 snprintf (fname_out, 1024, "%s.summary", argv[1]);
100 fp_out = fopen (fname_out, "w");
101 if (!fp_out)
103 fprintf (stderr, "Error: Unable to open output file '%s'\n",
104 fname_out);
105 return 1;
108 while (fscanf (fp_in, "%s %d %d %d %d %d\n", fname_in, &total,
109 &verified, &regset, &regpair, &unused) != EOF)
111 sum_vcalls += total;
112 sum_verified += verified;
113 sum_regset += regset;
114 sum_regpair += regpair;
115 sum_unused += unused;
117 float tmp_pct = 0.0;
119 if (total > 0)
120 tmp_pct = (verified * 100) / total;
122 if (verbose && tmp_pct < 90 && total >= 20)
124 fprintf (fp_out, "Verified %d out of %d (%.2f%%) : %s\n",
125 verified, total, tmp_pct, fname_in);
130 fclose (fp_in);
132 fprintf (fp_out, "\n\n");
133 fprintf (fp_out, "Total # virtual calls: %d\n", sum_vcalls);
134 fprintf (fp_out, "Total # verified calls: %d\n", sum_verified);
135 if (sum_vcalls > 0)
136 fprintf (fp_out, "Percent verified: %d %%\n",
137 sum_verified * 100 / sum_vcalls);
138 else
139 fprintf (fp_out, "Percent verified: NA %%\n");
141 fprintf (fp_out, "\nTotal calls to __VLTRegisterSet: %d\n",
142 sum_regset);
143 fprintf (fp_out, "Total calls to __VLTRegisterPair: %d\n",
144 sum_regpair);
145 fprintf (fp_out, "Total # unused vtable map vars: %d\n", sum_unused);
147 fclose (fp_out);
149 return 0;