blob: fcd025187ad555fe4d6f39e1d5571cceffd07a0f [file] [log] [blame]
weidendoa17f2a32006-03-20 10:27:30 +00001/*--------------------------------------------------------------------*/
2/*--- Callgrind ---*/
3/*--- events.h ---*/
weidendoa17f2a32006-03-20 10:27:30 +00004/*--------------------------------------------------------------------*/
5
weidendo5bba5252010-06-09 22:32:53 +00006/*
7 This file is part of Callgrind, a Valgrind tool for call tracing.
8
sewardj0f157dd2013-10-18 14:27:36 +00009 Copyright (C) 2002-2013, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
weidendo5bba5252010-06-09 22:32:53 +000010
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*/
weidendoa17f2a32006-03-20 10:27:30 +000028
29/* Abstractions for 64-bit cost lists (events.h) */
30
weidendo5bba5252010-06-09 22:32:53 +000031#ifndef CLG_EVENTS
32#define CLG_EVENTS
weidendoa17f2a32006-03-20 10:27:30 +000033
34#include "pub_tool_basics.h"
35
36#define CLG_(str) VGAPPEND(vgCallgrind_,str)
37
weidendo5bba5252010-06-09 22:32:53 +000038/* 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.
weidendoa17f2a32006-03-20 10:27:30 +000044 */
weidendo5bba5252010-06-09 22:32:53 +000045
46#define MAX_EVENTGROUP_COUNT 10
47
48typedef struct _EventGroup EventGroup;
49struct _EventGroup {
50 Int size;
florian25f6c572012-10-21 02:55:56 +000051 const HChar* name[0];
weidendoa17f2a32006-03-20 10:27:30 +000052};
weidendo5bba5252010-06-09 22:32:53 +000053
54/* return 0 if event group can not be registered */
florian25f6c572012-10-21 02:55:56 +000055EventGroup* CLG_(register_event_group) (int id, const HChar*);
56EventGroup* CLG_(register_event_group2)(int id, const HChar*, const HChar*);
57EventGroup* CLG_(register_event_group3)(int id, const HChar*, const HChar*,
58 const HChar*);
59EventGroup* CLG_(register_event_group4)(int id, const HChar*, const HChar*,
60 const HChar*, const HChar*);
weidendo5bba5252010-06-09 22:32:53 +000061EventGroup* CLG_(get_event_group)(int id);
62
63/* Event sets are defined by event groups they consist of. */
64
weidendoa17f2a32006-03-20 10:27:30 +000065typedef struct _EventSet EventSet;
66struct _EventSet {
weidendo5bba5252010-06-09 22:32:53 +000067 /* 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 };
weidendoa17f2a32006-03-20 10:27:30 +000073
weidendo5bba5252010-06-09 22:32:53 +000074/* Same event set is returned when requesting same event groups */
75EventSet* CLG_(get_event_set)(Int id);
76EventSet* CLG_(get_event_set2)(Int id1, Int id2);
77EventSet* CLG_(get_event_set3)(Int id1, Int id2, Int id3);
78EventSet* CLG_(add_event_group)(EventSet*, Int id);
79EventSet* CLG_(add_event_group2)(EventSet*, Int id1, Int id2);
80EventSet* CLG_(add_event_set)(EventSet*, EventSet*);
81/* Writes event names into buf. Returns number of characters written */
floriandbb35842012-10-27 18:39:11 +000082Int CLG_(sprint_eventset)(HChar* buf, EventSet*);
weidendo5bba5252010-06-09 22:32:53 +000083
weidendoa17f2a32006-03-20 10:27:30 +000084
85/* Operations on costs. A cost pointer of 0 means zero cost.
weidendo5bba5252010-06-09 22:32:53 +000086 * Functions ending in _lz allocate cost arrays only when needed
weidendoa17f2a32006-03-20 10:27:30 +000087 */
weidendo5bba5252010-06-09 22:32:53 +000088ULong* CLG_(get_eventset_cost)(EventSet*);
89/* Set costs of event set to 0 */
weidendoa17f2a32006-03-20 10:27:30 +000090void CLG_(init_cost)(EventSet*,ULong*);
91/* This always allocates counter and sets them to 0 */
92void CLG_(init_cost_lz)(EventSet*,ULong**);
93/* Set costs of an event set to zero */
94void CLG_(zero_cost)(EventSet*,ULong*);
95Bool CLG_(is_zero_cost)(EventSet*,ULong*);
96Bool CLG_(is_equal_cost)(EventSet*,ULong*,ULong*);
97void CLG_(copy_cost)(EventSet*,ULong* dst, ULong* src);
98void CLG_(copy_cost_lz)(EventSet*,ULong** pdst, ULong* src);
99void CLG_(add_cost)(EventSet*,ULong* dst, ULong* src);
100void CLG_(add_cost_lz)(EventSet*,ULong** pdst, ULong* src);
101/* Adds src to dst and zeros src. Returns false if nothing changed */
102Bool CLG_(add_and_zero_cost)(EventSet*,ULong* dst, ULong* src);
weidendo5bba5252010-06-09 22:32:53 +0000103Bool CLG_(add_and_zero_cost2)(EventSet*,ULong* dst,EventSet*,ULong* src);
weidendoa17f2a32006-03-20 10:27:30 +0000104/* Adds difference of new and old to to dst, and set old to new.
105 * Returns false if nothing changed */
weidendo0b23d6e2009-06-15 00:16:32 +0000106Bool CLG_(add_diff_cost)(EventSet*,ULong* dst, ULong* old, ULong* new_cost);
107Bool CLG_(add_diff_cost_lz)(EventSet*,ULong** pdst, ULong* old, ULong* new_cost);
weidendoa17f2a32006-03-20 10:27:30 +0000108/* Returns number of characters written */
floriandbb35842012-10-27 18:39:11 +0000109Int CLG_(sprint_cost)(HChar* buf, EventSet*, ULong*);
weidendoa17f2a32006-03-20 10:27:30 +0000110
weidendo5bba5252010-06-09 22:32:53 +0000111/* EventMapping: An ordered subset of events from an event set.
112 * This is used to print out part of an EventSet, or in another order.
113 */
114struct EventMappingEntry {
115 Int group;
116 Int index;
117 Int offset;
118};
119typedef struct _EventMapping EventMapping;
120struct _EventMapping {
121 EventSet* es;
122 Int size;
123 Int capacity;
124 struct EventMappingEntry entry[0];
125};
126
weidendoa17f2a32006-03-20 10:27:30 +0000127/* Allocate space for an event mapping */
128EventMapping* CLG_(get_eventmapping)(EventSet*);
florian25f6c572012-10-21 02:55:56 +0000129void CLG_(append_event)(EventMapping*, const HChar*);
weidendoa17f2a32006-03-20 10:27:30 +0000130/* Returns number of characters written */
floriandbb35842012-10-27 18:39:11 +0000131Int CLG_(sprint_eventmapping)(HChar* buf, EventMapping*);
weidendoa17f2a32006-03-20 10:27:30 +0000132/* Returns number of characters written */
floriandbb35842012-10-27 18:39:11 +0000133Int CLG_(sprint_mappingcost)(HChar* buf, EventMapping*, ULong*);
weidendoa17f2a32006-03-20 10:27:30 +0000134
weidendo5bba5252010-06-09 22:32:53 +0000135#endif /* CLG_EVENTS */