Fix format string warnings from gcc9. No functional change (I think!)
[valgrind.git] / coregrind / m_sbprofile.c
blob2878a70562c19651ae8ba8ef122b91f1b15aadae
2 /*--------------------------------------------------------------------*/
3 /*--- For printing superblock profiles m_sbprofile.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2012-2017 Mozilla Foundation
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
27 The GNU General Public License is contained in the file COPYING.
30 /* Contributed by Julian Seward <jseward@acm.org> */
32 #include "pub_core_basics.h"
33 #include "pub_core_transtab.h"
34 #include "pub_core_libcbase.h"
35 #include "pub_core_libcprint.h"
36 #include "pub_core_libcassert.h"
37 #include "pub_core_debuginfo.h"
38 #include "pub_core_translate.h"
39 #include "pub_core_options.h"
40 #include "pub_core_sbprofile.h" // self
42 /*====================================================================*/
43 /*=== SB profiling ===*/
44 /*====================================================================*/
46 static UInt n_profiles = 0;
48 static
49 void show_SB_profile ( const SBProfEntry tops[], UInt n_tops,
50 ULong score_total, ULong ecs_done )
52 ULong score_cumul, score_cumul_saved, score_here;
53 Int r; /* must be signed */
55 HChar ecs_txt[50]; // large enough
56 if (ecs_done > 0) {
57 VG_(sprintf)(ecs_txt, "%'llu ecs done", ecs_done);
58 } else {
59 VG_(strcpy)(ecs_txt, "for the entire run");
62 vg_assert(VG_(clo_profyle_sbs));
64 VG_(printf)("\n");
65 VG_(printf)("<<<---<<<---<<<---<<<---<<<---<<<---<<<---"
66 "<<<---<<<---<<<---<<<---<<<---<<<\n");
67 VG_(printf)("<<<---<<<---<<<---<<<---<<<---<<<---<<<---"
68 "<<<---<<<---<<<---<<<---<<<---<<<\n");
69 VG_(printf)("\n");
70 VG_(printf)("<<< BEGIN SB Profile #%u (%s)\n",
71 ++n_profiles, ecs_txt);
72 VG_(printf)("<<<\n");
73 VG_(printf)("\n");
75 VG_(printf)("Total score = %'llu\n\n", score_total);
77 // FIXME JRS EPOCH 28 July 2017: this is probably not right in general
78 DiEpoch cur_ep = VG_(current_DiEpoch)();
80 /* Print an initial per-block summary. */
81 VG_(printf)("rank ---cumulative--- -----self-----\n");
82 score_cumul = 0;
83 for (r = 0; r < n_tops; r++) {
84 if (tops[r].addr == 0)
85 continue;
86 if (tops[r].score == 0)
87 continue;
89 const HChar *name;
90 VG_(get_fnname_w_offset)(cur_ep, tops[r].addr, &name);
92 score_here = tops[r].score;
93 score_cumul += score_here;
95 /* Careful: do not divide by zero. score_total == 0 implies
96 score_cumul == 0 and also score_here == 0. */
97 Double percent_cumul =
98 score_total == 0 ? 100.0 : score_cumul * 100.0 / score_total;
99 Double percent_here =
100 score_total == 0 ? 100.0 : score_here * 100.0 / score_total;
102 VG_(printf)("%3d: (%9llu %5.2f%%) %9llu %5.2f%% 0x%lx %s\n",
104 score_cumul, percent_cumul,
105 score_here, percent_here, tops[r].addr, name);
107 score_cumul_saved = score_cumul;
109 if (VG_(clo_profyle_flags) > 0) {
111 /* Show the details, if requested. */
112 VG_(printf)("\n");
113 VG_(printf)("-----------------------------"
114 "------------------------------\n");
115 VG_(printf)("--- SB Profile (SB details) "
116 " ---\n");
117 VG_(printf)("-----------------------------"
118 "------------------------------\n");
119 VG_(printf)("\n");
121 score_cumul = 0;
122 for (r = 0; r < n_tops; r++) {
123 if (tops[r].addr == 0)
124 continue;
125 if (tops[r].score == 0)
126 continue;
128 const HChar *name;
129 VG_(get_fnname_w_offset)(cur_ep, tops[r].addr, &name);
131 score_here = tops[r].score;
132 score_cumul += score_here;
134 /* Careful: do not divide by zero. score_total == 0 implies
135 score_cumul == 0 and also score_here == 0. */
136 Double percent_cumul =
137 score_total == 0 ? 100.0 : score_cumul * 100.0 / score_total;
138 Double percent_here =
139 score_total == 0 ? 100.0 : score_here * 100.0 / score_total;
141 VG_(printf)("\n");
142 VG_(printf)("=-=-=-=-=-=-=-=-=-=-=-=-=-= begin SB rank %d "
143 "=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n", r);
144 VG_(printf)("%3d: (%9llu %5.2f%%) %9llu %5.2f%% 0x%lx %s\n",
146 score_cumul, percent_cumul,
147 score_here, percent_here, tops[r].addr, name );
148 VG_(printf)("\n");
149 VG_(discard_translations)(tops[r].addr, 1, "bb profile");
150 VG_(translate)(0, tops[r].addr, True, VG_(clo_profyle_flags), 0, True);
151 VG_(printf)("=-=-=-=-=-=-=-=-=-=-=-=-=-= end SB rank %d "
152 "=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n", r);
155 /* Print a final per-block summary, in reverse order, for the
156 convenience of people reading up from the end. */
157 score_cumul = score_cumul_saved;
158 for (r = n_tops-1; r >= 0; r--) {
159 if (tops[r].addr == 0)
160 continue;
161 if (tops[r].score == 0)
162 continue;
164 const HChar *name;
165 VG_(get_fnname_w_offset)(cur_ep, tops[r].addr, &name);
167 score_here = tops[r].score;
169 /* Careful: do not divide by zero. score_total == 0 implies
170 score_cumul == 0 and also score_here == 0. */
171 Double percent_cumul =
172 score_total == 0 ? 100.0 : score_cumul * 100.0 / score_total;
173 Double percent_here =
174 score_total == 0 ? 100.0 : score_here * 100.0 / score_total;
176 VG_(printf)("%3d: (%9llu %5.2f%%) %9llu %5.2f%% 0x%lx %s\n",
178 score_cumul, percent_cumul,
179 score_here, percent_here, tops[r].addr, name );
180 score_cumul -= score_here;
182 VG_(printf)("rank ---cumulative--- -----self-----\n");
186 VG_(printf)("\n");
187 VG_(printf)(">>>\n");
188 VG_(printf)(">>> END SB Profile #%u (%s)\n",
189 n_profiles, ecs_txt);
190 VG_(printf)(">>>\n");
191 VG_(printf)(">>>--->>>--->>>--->>>--->>>--->>>--->>>---"
192 ">>>--->>>--->>>--->>>--->>>--->>>\n");
193 VG_(printf)(">>>--->>>--->>>--->>>--->>>--->>>--->>>---"
194 ">>>--->>>--->>>--->>>--->>>--->>>\n");
195 VG_(printf)("\n");
199 /* Get and print a profile. Also, zero out the counters so that if we
200 call it again later, the second call will only show new work done
201 since the first call. ecs_done == 0 is taken to mean this is a
202 run-end profile. */
203 void VG_(get_and_show_SB_profile) ( ULong ecs_done )
205 /* The number of blocks to show for a end-of-run profile */
206 # define N_MAX_END 200
207 /* The number of blocks to show for a mid-run profile. */
208 # define N_MAX_INTERVAL 20
209 vg_assert(N_MAX_INTERVAL <= N_MAX_END);
210 SBProfEntry tops[N_MAX_END];
211 Int nToShow = ecs_done == 0 ? N_MAX_END : N_MAX_INTERVAL;
212 ULong score_total = VG_(get_SB_profile)(tops, nToShow);
213 show_SB_profile(tops, nToShow, score_total, ecs_done);
214 # undef N_MAX_END
215 # undef N_MAX_INTERVAL
219 /*--------------------------------------------------------------------*/
220 /*--- end m_sbprofile.c ---*/
221 /*--------------------------------------------------------------------*/