blob: b26ddd6cdfd323acbb14019f3ab0a556427b3ce0 [file] [log] [blame]
weidendoa17f2a32006-03-20 10:27:30 +00001/*
njn9a0cba42007-04-15 22:15:57 +00002 This file is part of Callgrind, a Valgrind tool for call graph
weidendoa17f2a32006-03-20 10:27:30 +00003 profiling programs.
4
Elliott Hughesed398002017-06-21 14:41:24 -07005 Copyright (C) 2002-2017, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
weidendoa17f2a32006-03-20 10:27:30 +00006
njn9a0cba42007-04-15 22:15:57 +00007 This tool is derived from and contains lot of code from Cachegrind
Elliott Hughesed398002017-06-21 14:41:24 -07008 Copyright (C) 2002-2017 Nicholas Nethercote (njn@valgrind.org)
weidendoa17f2a32006-03-20 10:27:30 +00009
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 02111-1307, USA.
24
25 The GNU General Public License is contained in the file COPYING.
26*/
27
28#include "config.h" // for VG_PREFIX
29
30#include "global.h"
31
32
33
34/*------------------------------------------------------------*/
35/*--- Function specific configuration options ---*/
36/*------------------------------------------------------------*/
37
38/* Special value for separate_callers: automatic = adaptive */
39#define CONFIG_AUTO -1
40
41#define CONFIG_DEFAULT -1
42#define CONFIG_FALSE 0
43#define CONFIG_TRUE 1
44
45/* Logging configuration for a function */
46struct _fn_config {
47 Int dump_before;
48 Int dump_after;
49 Int zero_before;
50 Int toggle_collect;
51
52 Int skip; /* Handle CALL to this function as JMP (= Skip)? */
53 Int group; /* don't change caller dependency inside group !=0 */
54 Int pop_on_jump;
55
56 Int separate_callers; /* separate logging dependent on caller */
57 Int separate_recursions; /* separate logging of rec. levels */
58
59#if CLG_ENABLE_DEBUG
60 Int verbosity; /* Change debug verbosity level while in function */
61#endif
62};
63
64/* Configurations for function name prefix patterns.
65 * Currently, only very limit patterns are possible:
66 * Exact prefix patterns and "*::" are allowed.
67 * E.g.
68 * - "abc" matches all functions starting with "abc".
69 * - "abc*::def" matches all functions starting with "abc" and
70 * starting with "def" after the first "::" separator.
71 * - "*::print(" matches C++ methods "print" in all classes
72 * without namespace. I.e. "*" doesn't match a "::".
73 *
74 * We build a trie from patterns, and for a given function, we
75 * go down the tree and apply all non-default configurations.
76 */
77
78
79#define NODE_DEGREE 30
80
81/* node of compressed trie search structure */
82typedef struct _config_node config_node;
83struct _config_node {
84 Int length;
85
86 fn_config* config;
87 config_node* sub_node[NODE_DEGREE];
88 config_node* next;
89 config_node* wild_star;
90 config_node* wild_char;
91
florian19f91bb2012-11-10 22:29:54 +000092 HChar name[1];
weidendoa17f2a32006-03-20 10:27:30 +000093};
94
95/* root of trie */
96static config_node* fn_configs = 0;
97
98static __inline__
99fn_config* new_fnc(void)
100{
weidendo0b23d6e2009-06-15 00:16:32 +0000101 fn_config* fnc = (fn_config*) CLG_MALLOC("cl.clo.nf.1",
sewardj9c606bd2008-09-18 18:12:50 +0000102 sizeof(fn_config));
weidendoa17f2a32006-03-20 10:27:30 +0000103
weidendo0b23d6e2009-06-15 00:16:32 +0000104 fnc->dump_before = CONFIG_DEFAULT;
105 fnc->dump_after = CONFIG_DEFAULT;
106 fnc->zero_before = CONFIG_DEFAULT;
107 fnc->toggle_collect = CONFIG_DEFAULT;
108 fnc->skip = CONFIG_DEFAULT;
109 fnc->pop_on_jump = CONFIG_DEFAULT;
110 fnc->group = CONFIG_DEFAULT;
111 fnc->separate_callers = CONFIG_DEFAULT;
112 fnc->separate_recursions = CONFIG_DEFAULT;
weidendoa17f2a32006-03-20 10:27:30 +0000113
114#if CLG_ENABLE_DEBUG
weidendo0b23d6e2009-06-15 00:16:32 +0000115 fnc->verbosity = CONFIG_DEFAULT;
weidendoa17f2a32006-03-20 10:27:30 +0000116#endif
117
weidendo0b23d6e2009-06-15 00:16:32 +0000118 return fnc;
weidendoa17f2a32006-03-20 10:27:30 +0000119}
120
121
florian19f91bb2012-11-10 22:29:54 +0000122static config_node* new_config(const HChar* name, int length)
weidendoa17f2a32006-03-20 10:27:30 +0000123{
124 int i;
sewardj9c606bd2008-09-18 18:12:50 +0000125 config_node* node = (config_node*) CLG_MALLOC("cl.clo.nc.1",
126 sizeof(config_node) + length);
weidendoa17f2a32006-03-20 10:27:30 +0000127
128 for(i=0;i<length;i++) {
129 if (name[i] == 0) break;
130 node->name[i] = name[i];
131 }
132 node->name[i] = 0;
133
134 node->length = length;
135 node->config = 0;
136 for(i=0;i<NODE_DEGREE;i++)
137 node->sub_node[i] = 0;
138 node->next = 0;
139 node->wild_char = 0;
140 node->wild_star = 0;
141
142 CLG_DEBUG(3, " new_config('%s', len %d)\n", node->name, length);
143
144 return node;
145}
146
147static __inline__
florian19f91bb2012-11-10 22:29:54 +0000148Bool is_wild(HChar n)
weidendoa17f2a32006-03-20 10:27:30 +0000149{
150 return (n == '*') || (n == '?');
151}
152
153/* Recursively build up function matching tree (prefix tree).
154 * Returns function config object for pattern <name>
155 * and starting at tree node <*pnode>.
156 *
157 * Tree nodes (config_node) are created as needed,
158 * tree root is stored into <*pnode>, and the created
159 * leaf (fn_config) for the given pattern is returned.
160 */
florian19f91bb2012-11-10 22:29:54 +0000161static fn_config* get_fnc2(config_node* node, const HChar* name)
weidendoa17f2a32006-03-20 10:27:30 +0000162{
163 config_node *new_sub, *n, *nprev;
164 int offset, len;
165
166 CLG_DEBUG(3, " get_fnc2(%p, '%s')\n", node, name);
167
168 if (name[0] == 0) {
169 if (!node->config) node->config = new_fnc();
170 return node->config;
171 }
172
173 if (is_wild(*name)) {
174 if (*name == '*') {
175 while(name[1] == '*') name++;
176 new_sub = node->wild_star;
177 }
178 else
179 new_sub = node->wild_char;
180
181 if (!new_sub) {
182 new_sub = new_config(name, 1);
183 if (*name == '*')
184 node->wild_star = new_sub;
185 else
186 node->wild_char = new_sub;
187 }
188
189 return get_fnc2( new_sub, name+1);
190 }
191
192 n = node->sub_node[ name[0]%NODE_DEGREE ];
193 nprev = 0;
194 len = 0;
195 while(n) {
196 for(len=0; name[len] == n->name[len]; len++);
197 if (len>0) break;
198 nprev = n;
199 n = n->next;
200 }
201
202 if (!n) {
203 len = 1;
204 while(name[len] && (!is_wild(name[len]))) len++;
205 new_sub = new_config(name, len);
206 new_sub->next = node->sub_node[ name[0]%NODE_DEGREE ];
207 node->sub_node[ name[0]%NODE_DEGREE ] = new_sub;
208
209 if (name[len] == 0) {
210 new_sub->config = new_fnc();
211 return new_sub->config;
212 }
213
214 /* recurse on wildcard */
215 return get_fnc2( new_sub, name+len);
216 }
217
218 if (len < n->length) {
219
220 /* split up the subnode <n> */
221 config_node *new_node;
222 int i;
223
224 new_node = new_config(n->name, len);
225 if (nprev)
226 nprev->next = new_node;
227 else
228 node->sub_node[ n->name[0]%NODE_DEGREE ] = new_node;
229 new_node->next = n->next;
230
231 new_node->sub_node[ n->name[len]%NODE_DEGREE ] = n;
232
233 for(i=0, offset=len; offset < n->length; i++, offset++)
234 n->name[i] = n->name[offset];
235 n->name[i] = 0;
236 n->length = i;
237
238 name += len;
239 offset = 0;
240 while(name[offset] && (!is_wild(name[offset]))) offset++;
241 new_sub = new_config(name, offset);
242 /* this sub_node of new_node could already be set: chain! */
243 new_sub->next = new_node->sub_node[ name[0]%NODE_DEGREE ];
244 new_node->sub_node[ name[0]%NODE_DEGREE ] = new_sub;
245
246 if (name[offset]==0) {
247 new_sub->config = new_fnc();
248 return new_sub->config;
249 }
250
251 /* recurse on wildcard */
252 return get_fnc2( new_sub, name+offset);
253 }
254
255 name += n->length;
256
257 if (name[0] == 0) {
258 /* name and node name are the same */
259 if (!n->config) n->config = new_fnc();
260 return n->config;
261 }
262
263 offset = 1;
264 while(name[offset] && (!is_wild(name[offset]))) offset++;
265
266 new_sub = new_config(name, offset);
weidendo141e76d2009-05-29 15:30:08 +0000267 new_sub->next = n->sub_node[ name[0]%NODE_DEGREE ];
268 n->sub_node[ name[0]%NODE_DEGREE ] = new_sub;
weidendoa17f2a32006-03-20 10:27:30 +0000269
270 return get_fnc2(new_sub, name+offset);
271}
272
weidendo141e76d2009-05-29 15:30:08 +0000273static void print_config_node(int depth, int hash, config_node* node)
weidendoa17f2a32006-03-20 10:27:30 +0000274{
275 config_node* n;
276 int i;
277
278 if (node != fn_configs) {
florian19f91bb2012-11-10 22:29:54 +0000279 const HChar sp[] = " ";
weidendoa17f2a32006-03-20 10:27:30 +0000280
weidendo141e76d2009-05-29 15:30:08 +0000281 if (depth>40) depth=40;
282 VG_(printf)("%s", sp+40-depth);
283 if (hash >=0) VG_(printf)(" [hash %2d]", hash);
284 else if (hash == -2) VG_(printf)(" [wildc ?]");
285 else if (hash == -3) VG_(printf)(" [wildc *]");
286 VG_(printf)(" '%s' (len %d)\n", node->name, node->length);
weidendoa17f2a32006-03-20 10:27:30 +0000287 }
288 for(i=0;i<NODE_DEGREE;i++) {
289 n = node->sub_node[i];
290 while(n) {
weidendo141e76d2009-05-29 15:30:08 +0000291 print_config_node(depth+1, i, n);
weidendoa17f2a32006-03-20 10:27:30 +0000292 n = n->next;
293 }
294 }
weidendo141e76d2009-05-29 15:30:08 +0000295 if (node->wild_char) print_config_node(depth+1, -2, node->wild_char);
296 if (node->wild_star) print_config_node(depth+1, -3, node->wild_star);
weidendoa17f2a32006-03-20 10:27:30 +0000297}
298
299/* get a function config for a name pattern (from command line) */
florian19f91bb2012-11-10 22:29:54 +0000300static fn_config* get_fnc(const HChar* name)
weidendoa17f2a32006-03-20 10:27:30 +0000301{
302 fn_config* fnc;
303
304 CLG_DEBUG(3, " +get_fnc(%s)\n", name);
305 if (fn_configs == 0)
306 fn_configs = new_config(name, 0);
307 fnc = get_fnc2(fn_configs, name);
308
309 CLG_DEBUGIF(3) {
310 CLG_DEBUG(3, " -get_fnc(%s):\n", name);
weidendo141e76d2009-05-29 15:30:08 +0000311 print_config_node(3, -1, fn_configs);
weidendoa17f2a32006-03-20 10:27:30 +0000312 }
313 return fnc;
314}
315
316
317
318static void update_fn_config1(fn_node* fn, fn_config* fnc)
319{
320 if (fnc->dump_before != CONFIG_DEFAULT)
321 fn->dump_before = (fnc->dump_before == CONFIG_TRUE);
322
323 if (fnc->dump_after != CONFIG_DEFAULT)
324 fn->dump_after = (fnc->dump_after == CONFIG_TRUE);
325
326 if (fnc->zero_before != CONFIG_DEFAULT)
327 fn->zero_before = (fnc->zero_before == CONFIG_TRUE);
328
329 if (fnc->toggle_collect != CONFIG_DEFAULT)
330 fn->toggle_collect = (fnc->toggle_collect == CONFIG_TRUE);
331
332 if (fnc->skip != CONFIG_DEFAULT)
333 fn->skip = (fnc->skip == CONFIG_TRUE);
334
335 if (fnc->pop_on_jump != CONFIG_DEFAULT)
336 fn->pop_on_jump = (fnc->pop_on_jump == CONFIG_TRUE);
337
338 if (fnc->group != CONFIG_DEFAULT)
339 fn->group = fnc->group;
340
341 if (fnc->separate_callers != CONFIG_DEFAULT)
342 fn->separate_callers = fnc->separate_callers;
343
344 if (fnc->separate_recursions != CONFIG_DEFAULT)
345 fn->separate_recursions = fnc->separate_recursions;
346
347#if CLG_ENABLE_DEBUG
348 if (fnc->verbosity != CONFIG_DEFAULT)
349 fn->verbosity = fnc->verbosity;
350#endif
351}
352
353/* Recursively go down the function matching tree,
354 * looking for a match to <name>. For every matching leaf,
355 * <fn> is updated with the pattern config.
356 */
florian19f91bb2012-11-10 22:29:54 +0000357static void update_fn_config2(fn_node* fn, const HChar* name,
358 config_node* node)
weidendoa17f2a32006-03-20 10:27:30 +0000359{
360 config_node* n;
361
362 CLG_DEBUG(3, " update_fn_config2('%s', node '%s'): \n",
363 name, node->name);
364 if ((*name == 0) && node->config) {
weidendo141e76d2009-05-29 15:30:08 +0000365 CLG_DEBUG(3, " found!\n");
weidendoa17f2a32006-03-20 10:27:30 +0000366 update_fn_config1(fn, node->config);
367 return;
368 }
369
370 n = node->sub_node[ name[0]%NODE_DEGREE ];
371 while(n) {
372 if (VG_(strncmp)(name, n->name, n->length)==0) break;
373 n = n->next;
374 }
weidendo141e76d2009-05-29 15:30:08 +0000375 if (n) {
376 CLG_DEBUG(3, " '%s' matching at hash %d\n",
377 n->name, name[0]%NODE_DEGREE);
378 update_fn_config2(fn, name+n->length, n);
379 }
weidendoa17f2a32006-03-20 10:27:30 +0000380
weidendo141e76d2009-05-29 15:30:08 +0000381 if (node->wild_char) {
382 CLG_DEBUG(3, " skip '%c' for wildcard '?'\n", *name);
383 update_fn_config2(fn, name+1, node->wild_char);
384 }
weidendoa17f2a32006-03-20 10:27:30 +0000385
386 if (node->wild_star) {
weidendo141e76d2009-05-29 15:30:08 +0000387 CLG_DEBUG(3, " wildcard '*'\n");
weidendoa17f2a32006-03-20 10:27:30 +0000388 while(*name) {
389 update_fn_config2(fn, name, node->wild_star);
390 name++;
391 }
392 update_fn_config2(fn, name, node->wild_star);
393 }
394}
395
396/* Update function config according to configs of name prefixes */
397void CLG_(update_fn_config)(fn_node* fn)
398{
399 CLG_DEBUG(3, " update_fn_config('%s')\n", fn->name);
400 if (fn_configs)
401 update_fn_config2(fn, fn->name, fn_configs);
402}
403
404
405/*--------------------------------------------------------------------*/
406/*--- Command line processing ---*/
407/*--------------------------------------------------------------------*/
408
florian19f91bb2012-11-10 22:29:54 +0000409Bool CLG_(process_cmd_line_option)(const HChar* arg)
weidendoa17f2a32006-03-20 10:27:30 +0000410{
florian19f91bb2012-11-10 22:29:54 +0000411 const HChar* tmp_str;
weidendoa17f2a32006-03-20 10:27:30 +0000412
njn83df0b62009-02-25 01:01:05 +0000413 if VG_BOOL_CLO(arg, "--skip-plt", CLG_(clo).skip_plt) {}
414
415 else if VG_BOOL_CLO(arg, "--collect-jumps", CLG_(clo).collect_jumps) {}
weidendoa17f2a32006-03-20 10:27:30 +0000416 /* compatibility alias, deprecated option */
njn83df0b62009-02-25 01:01:05 +0000417 else if VG_BOOL_CLO(arg, "--trace-jump", CLG_(clo).collect_jumps) {}
weidendoa17f2a32006-03-20 10:27:30 +0000418
njn83df0b62009-02-25 01:01:05 +0000419 else if VG_BOOL_CLO(arg, "--combine-dumps", CLG_(clo).combine_dumps) {}
weidendoa17f2a32006-03-20 10:27:30 +0000420
njn83df0b62009-02-25 01:01:05 +0000421 else if VG_BOOL_CLO(arg, "--collect-atstart", CLG_(clo).collect_atstart) {}
weidendoa17f2a32006-03-20 10:27:30 +0000422
njn83df0b62009-02-25 01:01:05 +0000423 else if VG_BOOL_CLO(arg, "--instr-atstart", CLG_(clo).instrument_atstart) {}
weidendoa17f2a32006-03-20 10:27:30 +0000424
njn83df0b62009-02-25 01:01:05 +0000425 else if VG_BOOL_CLO(arg, "--separate-threads", CLG_(clo).separate_threads) {}
weidendoa17f2a32006-03-20 10:27:30 +0000426
njn83df0b62009-02-25 01:01:05 +0000427 else if VG_BOOL_CLO(arg, "--compress-strings", CLG_(clo).compress_strings) {}
428 else if VG_BOOL_CLO(arg, "--compress-mangled", CLG_(clo).compress_mangled) {}
429 else if VG_BOOL_CLO(arg, "--compress-pos", CLG_(clo).compress_pos) {}
weidendoa17f2a32006-03-20 10:27:30 +0000430
njn83df0b62009-02-25 01:01:05 +0000431 else if VG_STR_CLO(arg, "--fn-skip", tmp_str) {
432 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000433 fnc->skip = CONFIG_TRUE;
434 }
435
njn83df0b62009-02-25 01:01:05 +0000436 else if VG_STR_CLO(arg, "--dump-before", tmp_str) {
437 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000438 fnc->dump_before = CONFIG_TRUE;
439 }
440
njn83df0b62009-02-25 01:01:05 +0000441 else if VG_STR_CLO(arg, "--zero-before", tmp_str) {
442 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000443 fnc->zero_before = CONFIG_TRUE;
444 }
445
njn83df0b62009-02-25 01:01:05 +0000446 else if VG_STR_CLO(arg, "--dump-after", tmp_str) {
447 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000448 fnc->dump_after = CONFIG_TRUE;
449 }
450
njn83df0b62009-02-25 01:01:05 +0000451 else if VG_STR_CLO(arg, "--toggle-collect", tmp_str) {
452 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000453 fnc->toggle_collect = CONFIG_TRUE;
454 /* defaults to initial collection off */
455 CLG_(clo).collect_atstart = False;
456 }
457
njn83df0b62009-02-25 01:01:05 +0000458 else if VG_INT_CLO(arg, "--separate-recs", CLG_(clo).separate_recursions) {}
weidendoa17f2a32006-03-20 10:27:30 +0000459
weidendoa762b0f2006-05-01 00:55:54 +0000460 /* change handling of a jump between functions to ret+call */
njn83df0b62009-02-25 01:01:05 +0000461 else if VG_XACT_CLO(arg, "--pop-on-jump", CLG_(clo).pop_on_jump, True) {}
462 else if VG_STR_CLO( arg, "--pop-on-jump", tmp_str) {
463 fn_config* fnc = get_fnc(tmp_str);
weidendoa17f2a32006-03-20 10:27:30 +0000464 fnc->pop_on_jump = CONFIG_TRUE;
465 }
466
467#if CLG_ENABLE_DEBUG
njn83df0b62009-02-25 01:01:05 +0000468 else if VG_INT_CLO(arg, "--ct-verbose", CLG_(clo).verbose) {}
469 else if VG_INT_CLO(arg, "--ct-vstart", CLG_(clo).verbose_start) {}
weidendoa17f2a32006-03-20 10:27:30 +0000470
njn83df0b62009-02-25 01:01:05 +0000471 else if VG_STREQN(12, arg, "--ct-verbose") {
weidendoa17f2a32006-03-20 10:27:30 +0000472 fn_config* fnc;
florian19f91bb2012-11-10 22:29:54 +0000473 HChar* s;
njn83df0b62009-02-25 01:01:05 +0000474 UInt n = VG_(strtoll10)(arg+12, &s);
475 if ((n <= 0) || *s != '=') return False;
weidendoa17f2a32006-03-20 10:27:30 +0000476 fnc = get_fnc(s+1);
477 fnc->verbosity = n;
478 }
479#endif
480
njn83df0b62009-02-25 01:01:05 +0000481 else if VG_XACT_CLO(arg, "--separate-callers=auto",
482 CLG_(clo).separate_callers, CONFIG_AUTO) {}
483 else if VG_INT_CLO( arg, "--separate-callers",
484 CLG_(clo).separate_callers) {}
weidendoa17f2a32006-03-20 10:27:30 +0000485
njn83df0b62009-02-25 01:01:05 +0000486 else if VG_STREQN(10, arg, "--fn-group") {
weidendoa17f2a32006-03-20 10:27:30 +0000487 fn_config* fnc;
florian19f91bb2012-11-10 22:29:54 +0000488 HChar* s;
njn83df0b62009-02-25 01:01:05 +0000489 UInt n = VG_(strtoll10)(arg+10, &s);
490 if ((n <= 0) || *s != '=') return False;
weidendoa17f2a32006-03-20 10:27:30 +0000491 fnc = get_fnc(s+1);
492 fnc->group = n;
493 }
494
njn83df0b62009-02-25 01:01:05 +0000495 else if VG_STREQN(18, arg, "--separate-callers") {
weidendoa17f2a32006-03-20 10:27:30 +0000496 fn_config* fnc;
florian19f91bb2012-11-10 22:29:54 +0000497 HChar* s;
njn83df0b62009-02-25 01:01:05 +0000498 UInt n = VG_(strtoll10)(arg+18, &s);
499 if ((n <= 0) || *s != '=') return False;
weidendoa17f2a32006-03-20 10:27:30 +0000500 fnc = get_fnc(s+1);
501 fnc->separate_callers = n;
502 }
503
njn83df0b62009-02-25 01:01:05 +0000504 else if VG_STREQN(15, arg, "--separate-recs") {
weidendoa17f2a32006-03-20 10:27:30 +0000505 fn_config* fnc;
florian19f91bb2012-11-10 22:29:54 +0000506 HChar* s;
njn83df0b62009-02-25 01:01:05 +0000507 UInt n = VG_(strtoll10)(arg+15, &s);
508 if ((n <= 0) || *s != '=') return False;
weidendoa17f2a32006-03-20 10:27:30 +0000509 fnc = get_fnc(s+1);
510 fnc->separate_recursions = n;
511 }
512
njn83df0b62009-02-25 01:01:05 +0000513 else if VG_STR_CLO(arg, "--callgrind-out-file", CLG_(clo).out_format) {}
weidendoa17f2a32006-03-20 10:27:30 +0000514
njn83df0b62009-02-25 01:01:05 +0000515 else if VG_BOOL_CLO(arg, "--mangle-names", CLG_(clo).mangle_names) {}
weidendoa17f2a32006-03-20 10:27:30 +0000516
njn83df0b62009-02-25 01:01:05 +0000517 else if VG_BOOL_CLO(arg, "--skip-direct-rec",
518 CLG_(clo).skip_direct_recursion) {}
weidendoa17f2a32006-03-20 10:27:30 +0000519
njn83df0b62009-02-25 01:01:05 +0000520 else if VG_BOOL_CLO(arg, "--dump-bbs", CLG_(clo).dump_bbs) {}
521 else if VG_BOOL_CLO(arg, "--dump-line", CLG_(clo).dump_line) {}
522 else if VG_BOOL_CLO(arg, "--dump-instr", CLG_(clo).dump_instr) {}
523 else if VG_BOOL_CLO(arg, "--dump-bb", CLG_(clo).dump_bb) {}
weidendoa17f2a32006-03-20 10:27:30 +0000524
njn83df0b62009-02-25 01:01:05 +0000525 else if VG_INT_CLO( arg, "--dump-every-bb", CLG_(clo).dump_every_bb) {}
weidendoa17f2a32006-03-20 10:27:30 +0000526
njn83df0b62009-02-25 01:01:05 +0000527 else if VG_BOOL_CLO(arg, "--collect-alloc", CLG_(clo).collect_alloc) {}
528 else if VG_BOOL_CLO(arg, "--collect-systime", CLG_(clo).collect_systime) {}
weidendo320705f2010-07-02 19:56:23 +0000529 else if VG_BOOL_CLO(arg, "--collect-bus", CLG_(clo).collect_bus) {}
530 /* for option compatibility with cachegrind */
531 else if VG_BOOL_CLO(arg, "--cache-sim", CLG_(clo).simulate_cache) {}
532 /* compatibility alias, deprecated option */
njn83df0b62009-02-25 01:01:05 +0000533 else if VG_BOOL_CLO(arg, "--simulate-cache", CLG_(clo).simulate_cache) {}
weidendo320705f2010-07-02 19:56:23 +0000534 /* for option compatibility with cachegrind */
535 else if VG_BOOL_CLO(arg, "--branch-sim", CLG_(clo).simulate_branch) {}
weidendoa17f2a32006-03-20 10:27:30 +0000536 else {
537 Bool isCachesimOption = (*CLG_(cachesim).parse_opt)(arg);
538
539 /* cache simulator is used if a simulator option is given */
540 if (isCachesimOption)
541 CLG_(clo).simulate_cache = True;
542
543 return isCachesimOption;
544 }
545
546 return True;
547}
548
549void CLG_(print_usage)(void)
550{
551 VG_(printf)(
552"\n dump creation options:\n"
weidendocbf4e192007-11-27 01:27:12 +0000553" --callgrind-out-file=<f> Output file name [callgrind.out.%%p]\n"
weidendoa17f2a32006-03-20 10:27:30 +0000554" --dump-line=no|yes Dump source lines of costs? [yes]\n"
555" --dump-instr=no|yes Dump instruction address of costs? [no]\n"
556" --compress-strings=no|yes Compress strings in profile dump? [yes]\n"
557" --compress-pos=no|yes Compress positions in profile dump? [yes]\n"
558" --combine-dumps=no|yes Concat all dumps into same file [no]\n"
559#if CLG_EXPERIMENTAL
560" --compress-events=no|yes Compress events in profile dump? [no]\n"
561" --dump-bb=no|yes Dump basic block address of costs? [no]\n"
562" --dump-bbs=no|yes Dump basic block info? [no]\n"
563" --dump-skipped=no|yes Dump info on skipped functions in calls? [no]\n"
564" --mangle-names=no|yes Mangle separation into names? [yes]\n"
565#endif
566
567"\n activity options (for interactivity use callgrind_control):\n"
568" --dump-every-bb=<count> Dump every <count> basic blocks [0=never]\n"
569" --dump-before=<func> Dump when entering function\n"
570" --zero-before=<func> Zero all costs when entering function\n"
571" --dump-after=<func> Dump when leaving function\n"
572#if CLG_EXPERIMENTAL
573" --dump-objs=no|yes Dump static object information [no]\n"
574#endif
575
576"\n data collection options:\n"
577" --instr-atstart=no|yes Do instrumentation at callgrind start [yes]\n"
578" --collect-atstart=no|yes Collect at process/thread start [yes]\n"
579" --toggle-collect=<func> Toggle collection on enter/leave function\n"
580" --collect-jumps=no|yes Collect jumps? [no]\n"
weidendoaeb86222010-06-09 22:33:02 +0000581" --collect-bus=no|yes Collect global bus events? [no]\n"
weidendoa17f2a32006-03-20 10:27:30 +0000582#if CLG_EXPERIMENTAL
583" --collect-alloc=no|yes Collect memory allocation info? [no]\n"
584#endif
585" --collect-systime=no|yes Collect system call time info? [no]\n"
586
587"\n cost entity separation options:\n"
588" --separate-threads=no|yes Separate data per thread [no]\n"
589" --separate-callers=<n> Separate functions by call chain length [0]\n"
weidendoa17f2a32006-03-20 10:27:30 +0000590" --separate-callers<n>=<f> Separate <n> callers for function <f>\n"
njn6559fd62009-08-06 02:30:26 +0000591" --separate-recs=<n> Separate function recursions up to level [2]\n"
592" --separate-recs<n>=<f> Separate <n> recursions for function <f>\n"
593" --skip-plt=no|yes Ignore calls to/from PLT sections? [yes]\n"
weidendoa17f2a32006-03-20 10:27:30 +0000594" --skip-direct-rec=no|yes Ignore direct recursions? [yes]\n"
595" --fn-skip=<function> Ignore calls to/from function?\n"
596#if CLG_EXPERIMENTAL
597" --fn-group<no>=<func> Put function into separation group <no>\n"
598#endif
weidendo320705f2010-07-02 19:56:23 +0000599"\n simulation options:\n"
600" --branch-sim=no|yes Do branch prediction simulation [no]\n"
601" --cache-sim=no|yes Do cache simulation [no]\n"
weidendoa17f2a32006-03-20 10:27:30 +0000602 );
603
604 (*CLG_(cachesim).print_opts)();
605
606// VG_(printf)("\n"
607// " For full callgrind documentation, see\n"
608// " "VG_PREFIX"/share/doc/callgrind/html/callgrind.html\n\n");
609}
610
611void CLG_(print_debug_usage)(void)
612{
613 VG_(printf)(
614
615#if CLG_ENABLE_DEBUG
616" --ct-verbose=<level> Verbosity of standard debug output [0]\n"
617" --ct-vstart=<BB number> Only be verbose after basic block [0]\n"
618" --ct-verbose<level>=<func> Verbosity while in <func>\n"
619#else
620" (none)\n"
621#endif
622
623 );
624}
625
626
627void CLG_(set_clo_defaults)(void)
628{
629 /* Default values for command line arguments */
630
631 /* dump options */
weidendocbf4e192007-11-27 01:27:12 +0000632 CLG_(clo).out_format = 0;
weidendoa17f2a32006-03-20 10:27:30 +0000633 CLG_(clo).combine_dumps = False;
634 CLG_(clo).compress_strings = True;
635 CLG_(clo).compress_mangled = False;
636 CLG_(clo).compress_events = False;
637 CLG_(clo).compress_pos = True;
638 CLG_(clo).mangle_names = True;
639 CLG_(clo).dump_line = True;
640 CLG_(clo).dump_instr = False;
641 CLG_(clo).dump_bb = False;
642 CLG_(clo).dump_bbs = False;
643
644 CLG_(clo).dump_every_bb = 0;
645
646 /* Collection */
647 CLG_(clo).separate_threads = False;
648 CLG_(clo).collect_atstart = True;
649 CLG_(clo).collect_jumps = False;
650 CLG_(clo).collect_alloc = False;
651 CLG_(clo).collect_systime = False;
weidendo320705f2010-07-02 19:56:23 +0000652 CLG_(clo).collect_bus = False;
weidendoa17f2a32006-03-20 10:27:30 +0000653
654 CLG_(clo).skip_plt = True;
655 CLG_(clo).separate_callers = 0;
656 CLG_(clo).separate_recursions = 2;
657 CLG_(clo).skip_direct_recursion = False;
658
659 /* Instrumentation */
660 CLG_(clo).instrument_atstart = True;
661 CLG_(clo).simulate_cache = False;
weidendo320705f2010-07-02 19:56:23 +0000662 CLG_(clo).simulate_branch = False;
weidendoa17f2a32006-03-20 10:27:30 +0000663
weidendoa762b0f2006-05-01 00:55:54 +0000664 /* Call graph */
665 CLG_(clo).pop_on_jump = False;
666
weidendoa17f2a32006-03-20 10:27:30 +0000667#if CLG_ENABLE_DEBUG
668 CLG_(clo).verbose = 0;
669 CLG_(clo).verbose_start = 0;
670#endif
671}