weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 1 | /* |
njn | 9a0cba4 | 2007-04-15 22:15:57 +0000 | [diff] [blame] | 2 | This file is part of Callgrind, a Valgrind tool for call graph |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 3 | profiling programs. |
| 4 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 5 | Copyright (C) 2002-2013, Josef Weidendorfer (Josef.Weidendorfer@gmx.de) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 6 | |
njn | 9a0cba4 | 2007-04-15 22:15:57 +0000 | [diff] [blame] | 7 | This tool is derived from and contains lot of code from Cachegrind |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 8 | Copyright (C) 2002-2013 Nicholas Nethercote (njn@valgrind.org) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 9 | |
| 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 */ |
| 46 | struct _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 */ |
| 82 | typedef struct _config_node config_node; |
| 83 | struct _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 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 92 | HChar name[1]; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* root of trie */ |
| 96 | static config_node* fn_configs = 0; |
| 97 | |
| 98 | static __inline__ |
| 99 | fn_config* new_fnc(void) |
| 100 | { |
weidendo | 0b23d6e | 2009-06-15 00:16:32 +0000 | [diff] [blame] | 101 | fn_config* fnc = (fn_config*) CLG_MALLOC("cl.clo.nf.1", |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 102 | sizeof(fn_config)); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 103 | |
weidendo | 0b23d6e | 2009-06-15 00:16:32 +0000 | [diff] [blame] | 104 | 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; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 113 | |
| 114 | #if CLG_ENABLE_DEBUG |
weidendo | 0b23d6e | 2009-06-15 00:16:32 +0000 | [diff] [blame] | 115 | fnc->verbosity = CONFIG_DEFAULT; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 116 | #endif |
| 117 | |
weidendo | 0b23d6e | 2009-06-15 00:16:32 +0000 | [diff] [blame] | 118 | return fnc; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 122 | static config_node* new_config(const HChar* name, int length) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 123 | { |
| 124 | int i; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 125 | config_node* node = (config_node*) CLG_MALLOC("cl.clo.nc.1", |
| 126 | sizeof(config_node) + length); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 127 | |
| 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 | |
| 147 | static __inline__ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 148 | Bool is_wild(HChar n) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 149 | { |
| 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 | */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 161 | static fn_config* get_fnc2(config_node* node, const HChar* name) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 162 | { |
| 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); |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 267 | new_sub->next = n->sub_node[ name[0]%NODE_DEGREE ]; |
| 268 | n->sub_node[ name[0]%NODE_DEGREE ] = new_sub; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 269 | |
| 270 | return get_fnc2(new_sub, name+offset); |
| 271 | } |
| 272 | |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 273 | static void print_config_node(int depth, int hash, config_node* node) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 274 | { |
| 275 | config_node* n; |
| 276 | int i; |
| 277 | |
| 278 | if (node != fn_configs) { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 279 | const HChar sp[] = " "; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 280 | |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 281 | 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); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 287 | } |
| 288 | for(i=0;i<NODE_DEGREE;i++) { |
| 289 | n = node->sub_node[i]; |
| 290 | while(n) { |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 291 | print_config_node(depth+1, i, n); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 292 | n = n->next; |
| 293 | } |
| 294 | } |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 295 | 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); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* get a function config for a name pattern (from command line) */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 300 | static fn_config* get_fnc(const HChar* name) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 301 | { |
| 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); |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 311 | print_config_node(3, -1, fn_configs); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 312 | } |
| 313 | return fnc; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | static 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 | */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 357 | static void update_fn_config2(fn_node* fn, const HChar* name, |
| 358 | config_node* node) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 359 | { |
| 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) { |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 365 | CLG_DEBUG(3, " found!\n"); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 366 | 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 | } |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 375 | 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 | } |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 380 | |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 381 | 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 | } |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 385 | |
| 386 | if (node->wild_star) { |
weidendo | 141e76d | 2009-05-29 15:30:08 +0000 | [diff] [blame] | 387 | CLG_DEBUG(3, " wildcard '*'\n"); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 388 | 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 */ |
| 397 | void 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 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 409 | Bool CLG_(process_cmd_line_option)(const HChar* arg) |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 410 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 411 | const HChar* tmp_str; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 412 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 413 | 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) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 416 | /* compatibility alias, deprecated option */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 417 | else if VG_BOOL_CLO(arg, "--trace-jump", CLG_(clo).collect_jumps) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 418 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 419 | else if VG_BOOL_CLO(arg, "--combine-dumps", CLG_(clo).combine_dumps) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 420 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 421 | else if VG_BOOL_CLO(arg, "--collect-atstart", CLG_(clo).collect_atstart) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 422 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 423 | else if VG_BOOL_CLO(arg, "--instr-atstart", CLG_(clo).instrument_atstart) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 424 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 425 | else if VG_BOOL_CLO(arg, "--separate-threads", CLG_(clo).separate_threads) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 426 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 427 | 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) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 430 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 431 | else if VG_STR_CLO(arg, "--fn-skip", tmp_str) { |
| 432 | fn_config* fnc = get_fnc(tmp_str); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 433 | fnc->skip = CONFIG_TRUE; |
| 434 | } |
| 435 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 436 | else if VG_STR_CLO(arg, "--dump-before", tmp_str) { |
| 437 | fn_config* fnc = get_fnc(tmp_str); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 438 | fnc->dump_before = CONFIG_TRUE; |
| 439 | } |
| 440 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 441 | else if VG_STR_CLO(arg, "--zero-before", tmp_str) { |
| 442 | fn_config* fnc = get_fnc(tmp_str); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 443 | fnc->zero_before = CONFIG_TRUE; |
| 444 | } |
| 445 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 446 | else if VG_STR_CLO(arg, "--dump-after", tmp_str) { |
| 447 | fn_config* fnc = get_fnc(tmp_str); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 448 | fnc->dump_after = CONFIG_TRUE; |
| 449 | } |
| 450 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 451 | else if VG_STR_CLO(arg, "--toggle-collect", tmp_str) { |
| 452 | fn_config* fnc = get_fnc(tmp_str); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 453 | fnc->toggle_collect = CONFIG_TRUE; |
| 454 | /* defaults to initial collection off */ |
| 455 | CLG_(clo).collect_atstart = False; |
| 456 | } |
| 457 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 458 | else if VG_INT_CLO(arg, "--separate-recs", CLG_(clo).separate_recursions) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 459 | |
weidendo | a762b0f | 2006-05-01 00:55:54 +0000 | [diff] [blame] | 460 | /* change handling of a jump between functions to ret+call */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 461 | 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); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 464 | fnc->pop_on_jump = CONFIG_TRUE; |
| 465 | } |
| 466 | |
| 467 | #if CLG_ENABLE_DEBUG |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 468 | else if VG_INT_CLO(arg, "--ct-verbose", CLG_(clo).verbose) {} |
| 469 | else if VG_INT_CLO(arg, "--ct-vstart", CLG_(clo).verbose_start) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 470 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 471 | else if VG_STREQN(12, arg, "--ct-verbose") { |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 472 | fn_config* fnc; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 473 | HChar* s; |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 474 | UInt n = VG_(strtoll10)(arg+12, &s); |
| 475 | if ((n <= 0) || *s != '=') return False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 476 | fnc = get_fnc(s+1); |
| 477 | fnc->verbosity = n; |
| 478 | } |
| 479 | #endif |
| 480 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 481 | 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) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 485 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 486 | else if VG_STREQN(10, arg, "--fn-group") { |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 487 | fn_config* fnc; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 488 | HChar* s; |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 489 | UInt n = VG_(strtoll10)(arg+10, &s); |
| 490 | if ((n <= 0) || *s != '=') return False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 491 | fnc = get_fnc(s+1); |
| 492 | fnc->group = n; |
| 493 | } |
| 494 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 495 | else if VG_STREQN(18, arg, "--separate-callers") { |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 496 | fn_config* fnc; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 497 | HChar* s; |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 498 | UInt n = VG_(strtoll10)(arg+18, &s); |
| 499 | if ((n <= 0) || *s != '=') return False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 500 | fnc = get_fnc(s+1); |
| 501 | fnc->separate_callers = n; |
| 502 | } |
| 503 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 504 | else if VG_STREQN(15, arg, "--separate-recs") { |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 505 | fn_config* fnc; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 506 | HChar* s; |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 507 | UInt n = VG_(strtoll10)(arg+15, &s); |
| 508 | if ((n <= 0) || *s != '=') return False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 509 | fnc = get_fnc(s+1); |
| 510 | fnc->separate_recursions = n; |
| 511 | } |
| 512 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 513 | else if VG_STR_CLO(arg, "--callgrind-out-file", CLG_(clo).out_format) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 514 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 515 | else if VG_BOOL_CLO(arg, "--mangle-names", CLG_(clo).mangle_names) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 516 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 517 | else if VG_BOOL_CLO(arg, "--skip-direct-rec", |
| 518 | CLG_(clo).skip_direct_recursion) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 519 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 520 | 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) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 524 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 525 | else if VG_INT_CLO( arg, "--dump-every-bb", CLG_(clo).dump_every_bb) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 526 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 527 | 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) {} |
weidendo | 320705f | 2010-07-02 19:56:23 +0000 | [diff] [blame] | 529 | 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 */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 533 | else if VG_BOOL_CLO(arg, "--simulate-cache", CLG_(clo).simulate_cache) {} |
weidendo | 320705f | 2010-07-02 19:56:23 +0000 | [diff] [blame] | 534 | /* for option compatibility with cachegrind */ |
| 535 | else if VG_BOOL_CLO(arg, "--branch-sim", CLG_(clo).simulate_branch) {} |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 536 | 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 | |
| 549 | void CLG_(print_usage)(void) |
| 550 | { |
| 551 | VG_(printf)( |
| 552 | "\n dump creation options:\n" |
weidendo | cbf4e19 | 2007-11-27 01:27:12 +0000 | [diff] [blame] | 553 | " --callgrind-out-file=<f> Output file name [callgrind.out.%%p]\n" |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 554 | " --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" |
weidendo | aeb8622 | 2010-06-09 22:33:02 +0000 | [diff] [blame] | 581 | " --collect-bus=no|yes Collect global bus events? [no]\n" |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 582 | #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" |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 590 | " --separate-callers<n>=<f> Separate <n> callers for function <f>\n" |
njn | 6559fd6 | 2009-08-06 02:30:26 +0000 | [diff] [blame] | 591 | " --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" |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 594 | " --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 |
weidendo | 320705f | 2010-07-02 19:56:23 +0000 | [diff] [blame] | 599 | "\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" |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 602 | ); |
| 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 | |
| 611 | void 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 | |
| 627 | void CLG_(set_clo_defaults)(void) |
| 628 | { |
| 629 | /* Default values for command line arguments */ |
| 630 | |
| 631 | /* dump options */ |
weidendo | cbf4e19 | 2007-11-27 01:27:12 +0000 | [diff] [blame] | 632 | CLG_(clo).out_format = 0; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 633 | 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; |
weidendo | 320705f | 2010-07-02 19:56:23 +0000 | [diff] [blame] | 652 | CLG_(clo).collect_bus = False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 653 | |
| 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; |
weidendo | 320705f | 2010-07-02 19:56:23 +0000 | [diff] [blame] | 662 | CLG_(clo).simulate_branch = False; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 663 | |
weidendo | a762b0f | 2006-05-01 00:55:54 +0000 | [diff] [blame] | 664 | /* Call graph */ |
| 665 | CLG_(clo).pop_on_jump = False; |
| 666 | |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 667 | #if CLG_ENABLE_DEBUG |
| 668 | CLG_(clo).verbose = 0; |
| 669 | CLG_(clo).verbose_start = 0; |
| 670 | #endif |
| 671 | } |