weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 1 | /*--------------------------------------------------------------------*/ |
| 2 | /*--- Callgrind ---*/ |
| 3 | /*--- events.h ---*/ |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 6 | /* |
| 7 | This file is part of Callgrind, a Valgrind tool for call tracing. |
| 8 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 9 | Copyright (C) 2002-2013, Josef Weidendorfer (Josef.Weidendorfer@gmx.de) |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 10 | |
| 11 | This program is free software; you can redistribute it and/or |
| 12 | modify it under the terms of the GNU General Public License as |
| 13 | published by the Free Software Foundation; either version 2 of the |
| 14 | License, or (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but |
| 17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 24 | 02111-1307, USA. |
| 25 | |
| 26 | The GNU General Public License is contained in the file COPYING. |
| 27 | */ |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 28 | |
| 29 | /* Abstractions for 64-bit cost lists (events.h) */ |
| 30 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 31 | #ifndef CLG_EVENTS |
| 32 | #define CLG_EVENTS |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 33 | |
| 34 | #include "pub_tool_basics.h" |
| 35 | |
| 36 | #define CLG_(str) VGAPPEND(vgCallgrind_,str) |
| 37 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 38 | /* Event groups consist of one or more named event types. |
| 39 | * Event sets are constructed from such event groups. |
| 40 | * |
| 41 | * Event groups have to be registered globally with a unique ID |
| 42 | * before they can be used in an event set. |
| 43 | * A group can appear at most once in a event set. |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 44 | */ |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 45 | |
| 46 | #define MAX_EVENTGROUP_COUNT 10 |
| 47 | |
| 48 | typedef struct _EventGroup EventGroup; |
| 49 | struct _EventGroup { |
| 50 | Int size; |
florian | 25f6c57 | 2012-10-21 02:55:56 +0000 | [diff] [blame] | 51 | const HChar* name[0]; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 52 | }; |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 53 | |
| 54 | /* return 0 if event group can not be registered */ |
florian | 25f6c57 | 2012-10-21 02:55:56 +0000 | [diff] [blame] | 55 | EventGroup* CLG_(register_event_group) (int id, const HChar*); |
| 56 | EventGroup* CLG_(register_event_group2)(int id, const HChar*, const HChar*); |
| 57 | EventGroup* CLG_(register_event_group3)(int id, const HChar*, const HChar*, |
| 58 | const HChar*); |
| 59 | EventGroup* CLG_(register_event_group4)(int id, const HChar*, const HChar*, |
| 60 | const HChar*, const HChar*); |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 61 | EventGroup* CLG_(get_event_group)(int id); |
| 62 | |
| 63 | /* Event sets are defined by event groups they consist of. */ |
| 64 | |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 65 | typedef struct _EventSet EventSet; |
| 66 | struct _EventSet { |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 67 | /* if subset with ID x is in the set, then bit x is set */ |
| 68 | UInt mask; |
| 69 | Int count; |
| 70 | Int size; |
| 71 | Int offset[MAX_EVENTGROUP_COUNT]; |
| 72 | }; |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 73 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 74 | /* Same event set is returned when requesting same event groups */ |
| 75 | EventSet* CLG_(get_event_set)(Int id); |
| 76 | EventSet* CLG_(get_event_set2)(Int id1, Int id2); |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 77 | EventSet* CLG_(add_event_group)(EventSet*, Int id); |
| 78 | EventSet* CLG_(add_event_group2)(EventSet*, Int id1, Int id2); |
| 79 | EventSet* CLG_(add_event_set)(EventSet*, EventSet*); |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 80 | |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 81 | |
| 82 | /* Operations on costs. A cost pointer of 0 means zero cost. |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 83 | * Functions ending in _lz allocate cost arrays only when needed |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 84 | */ |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 85 | ULong* CLG_(get_eventset_cost)(EventSet*); |
| 86 | /* Set costs of event set to 0 */ |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 87 | void CLG_(init_cost)(EventSet*,ULong*); |
| 88 | /* This always allocates counter and sets them to 0 */ |
| 89 | void CLG_(init_cost_lz)(EventSet*,ULong**); |
| 90 | /* Set costs of an event set to zero */ |
| 91 | void CLG_(zero_cost)(EventSet*,ULong*); |
| 92 | Bool CLG_(is_zero_cost)(EventSet*,ULong*); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 93 | void CLG_(copy_cost)(EventSet*,ULong* dst, ULong* src); |
| 94 | void CLG_(copy_cost_lz)(EventSet*,ULong** pdst, ULong* src); |
| 95 | void CLG_(add_cost)(EventSet*,ULong* dst, ULong* src); |
| 96 | void CLG_(add_cost_lz)(EventSet*,ULong** pdst, ULong* src); |
| 97 | /* Adds src to dst and zeros src. Returns false if nothing changed */ |
| 98 | Bool CLG_(add_and_zero_cost)(EventSet*,ULong* dst, ULong* src); |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 99 | Bool CLG_(add_and_zero_cost2)(EventSet*,ULong* dst,EventSet*,ULong* src); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 100 | /* Adds difference of new and old to to dst, and set old to new. |
| 101 | * Returns false if nothing changed */ |
weidendo | 0b23d6e | 2009-06-15 00:16:32 +0000 | [diff] [blame] | 102 | Bool CLG_(add_diff_cost)(EventSet*,ULong* dst, ULong* old, ULong* new_cost); |
| 103 | Bool CLG_(add_diff_cost_lz)(EventSet*,ULong** pdst, ULong* old, ULong* new_cost); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 104 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 105 | /* EventMapping: An ordered subset of events from an event set. |
| 106 | * This is used to print out part of an EventSet, or in another order. |
| 107 | */ |
| 108 | struct EventMappingEntry { |
| 109 | Int group; |
| 110 | Int index; |
| 111 | Int offset; |
| 112 | }; |
| 113 | typedef struct _EventMapping EventMapping; |
| 114 | struct _EventMapping { |
| 115 | EventSet* es; |
| 116 | Int size; |
| 117 | Int capacity; |
| 118 | struct EventMappingEntry entry[0]; |
| 119 | }; |
| 120 | |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 121 | /* Allocate space for an event mapping */ |
| 122 | EventMapping* CLG_(get_eventmapping)(EventSet*); |
florian | 25f6c57 | 2012-10-21 02:55:56 +0000 | [diff] [blame] | 123 | void CLG_(append_event)(EventMapping*, const HChar*); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 124 | /* Returns number of characters written */ |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 125 | Int CLG_(sprint_eventmapping)(HChar* buf, EventMapping*); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 126 | /* Returns number of characters written */ |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 127 | Int CLG_(sprint_mappingcost)(HChar* buf, EventMapping*, ULong*); |
weidendo | a17f2a3 | 2006-03-20 10:27:30 +0000 | [diff] [blame] | 128 | |
weidendo | 5bba525 | 2010-06-09 22:32:53 +0000 | [diff] [blame] | 129 | #endif /* CLG_EVENTS */ |