HPCToolkit
NameMappings.cpp
Go to the documentation of this file.
1 //******************************************************************************
2 //******************************************************************************
3 // NameMappings.cpp
4 //
5 // Purpose:
6 // To support renamings, this file supports one operation: normalize_name,
7 // while maps input name into its output name. If no remapping exists, the
8 // input name and the output name will agree.
9 //******************************************************************************
10 //******************************************************************************
11 
12 
13 
14 //******************************************************************************
15 // global include files
16 //******************************************************************************
17 
18 #include <iostream>
19 #include <map>
20 #include <string.h>
21 
22 #include <lib/support/dictionary.h>
24 
25 
26 //******************************************************************************
27 // constants
28 //******************************************************************************
29 
30 const char *PROGRAM_ROOT = "<program root>";
31 const char *THREAD_ROOT = "<thread root>";
32 
33 const char *OMP_IDLE = "<omp idle>";
34 const char *OMP_OVERHEAD = "<omp overhead>";
35 const char *OMP_BARRIER_WAIT = "<omp barrier wait>";
36 const char *OMP_TASK_WAIT = "<omp task wait>";
37 const char *OMP_MUTEX_WAIT = "<omp mutex wait>";
38 const char *NO_THREAD_ROOT = "<no thread>";
39 
40 const char *MONITOR_DATA_FIRST_TOUCH = "<first touch>";
41 
42 const char *DATACENTRIC_ROOT = "<datacentric>";
43 const char *DATACENTRIC_DYNAMIC = "<heap allocation>";
44 const char *DATACENTRIC_STATIC = "<static variable>";
45 const char *DATACENTRIC_UNKNOWN = "<unknown attribute>";
46 
47 const int NO_FAKE = 0;
48 const int FAKE_PROCEDURE = 1;
49 const int FAKE_ROOT = 2;
50 
51 //******************************************************************************
52 // types
53 //******************************************************************************
54 
56 public:
57  bool operator()(const char *n1, const char *n2) const {
58  return strcmp(n1,n2) < 0;
59  }
60 };
61 
62 
63 typedef std::map<const char *, const char *, NameMapCompare> NameMappings_t;
64 typedef std::map<const char *, int> ProcedureStatusMapping_t;
65 
66 
67 typedef struct {
68  const char *in;
69  const char *out;
70 } NameMapping;
71 
72 
73 typedef struct {
74  const char *name;
75  const int status;
77 
78 //******************************************************************************
79 // private data
80 //******************************************************************************
81 
83  { "monitor_main", PROGRAM_ROOT },
84  { "monitor_main_fence1", PROGRAM_ROOT },
85  { "monitor_main_fence2", PROGRAM_ROOT },
86  { "monitor_main_fence3", PROGRAM_ROOT },
87  { "monitor_main_fence4", PROGRAM_ROOT },
88 
89  { "monitor_begin_thread", THREAD_ROOT },
90  { "monitor_thread_fence1", THREAD_ROOT },
91  { "monitor_thread_fence2", THREAD_ROOT },
92  { "monitor_thread_fence3", THREAD_ROOT },
93  { "monitor_thread_fence4", THREAD_ROOT },
94 
95  { "ompt_idle_state", OMP_IDLE },
96  { "ompt_idle", OMP_IDLE },
97 
98  { "ompt_overhead_state", OMP_OVERHEAD },
99  { "omp_overhead", OMP_OVERHEAD },
100 
101  { "ompt_barrier_wait_state", OMP_BARRIER_WAIT },
102  { "ompt_barrier_wait", OMP_BARRIER_WAIT },
103 
104  { "ompt_task_wait_state", OMP_TASK_WAIT },
105  { "ompt_task_wait", OMP_TASK_WAIT },
106 
107  { "ompt_mutex_wait_state", OMP_MUTEX_WAIT },
108  { "ompt_mutex_wait", OMP_MUTEX_WAIT },
109 
110  { "monitor_data_first_touch", MONITOR_DATA_FIRST_TOUCH },
111 
112  { "DATACENTRIC" , DATACENTRIC_ROOT },
113  { "DATACENTRIC_Dynamic" , DATACENTRIC_DYNAMIC },
114  { "DATACENTRIC_Static" , DATACENTRIC_STATIC },
115  { "DATACENTRIC_Unknown" , DATACENTRIC_UNKNOWN },
116 
117  { "NO_THREAD", NO_THREAD_ROOT }
118 };
119 
120 
123  {THREAD_ROOT, FAKE_PROCEDURE},
124  {GUARD_NAME, FAKE_PROCEDURE},
125  {"<partial call paths>", FAKE_PROCEDURE},
126  {DATACENTRIC_ROOT, FAKE_ROOT}, // need to be consider both root and fake
127  {DATACENTRIC_DYNAMIC, FAKE_PROCEDURE},
128  {DATACENTRIC_STATIC, FAKE_PROCEDURE},
129 };
130 
133 
134 
135 //******************************************************************************
136 // private operations
137 //******************************************************************************
138 
139 
140 static void
142 {
143  static int initialized = 0;
144  if (initialized) return;
145  initialized = 1;
146 
147  for (unsigned int i = 0; i < sizeof(renamingTable) / sizeof(NameMapping); i++) {
148  renamingMap[renamingTable[i].in] = renamingTable[i].out;
149  }
150  for (unsigned int i = 0; i < sizeof(fakeProcedureTable) / sizeof(const char*); i++) {
151  fakeProcedureMap[fakeProcedureTable[i].name] = fakeProcedureTable[i].status;
152  }
153 }
154 
155 
156 static const char *
157 normalize_name_rename(const char *in, int &fake_procedure)
158 {
159  // check if the name has to be changed or not
160  const char *name_new = in;
161  NameMappings_t::iterator it = renamingMap.find(in);
162 
163  if (it != renamingMap.end()) {
164  // it has to be renamed.
165  name_new = it->second;
166  }
167  // here we want to mark fake procedures if they match with the list from fakeProcedureMap
168  fake_procedure = NO_FAKE;
169 
170  ProcedureStatusMapping_t::iterator itf = fakeProcedureMap.find(name_new);
171  if (itf != fakeProcedureMap.end()) {
172  fake_procedure = itf->second;
173  }
174 
175  return name_new;
176 }
177 
178 
179 
180 //******************************************************************************
181 // interface operations
182 //******************************************************************************
183 
184 const char *
185 normalize_name(const char *in, int &fake_procedure)
186 {
188  return normalize_name_rename(in, fake_procedure);
189 }
190 
191 #if 0
192 
193 const char * tests[] = {
194  "omp_idle_state",
195  "foo",
196  "monitor_main_fence2",
197  "omp_mutex_wait_state",
198  "bar"
199 };
200 
201 main()
202 {
203  for(int i = 0; i < (sizeof(tests) / sizeof(const char *)); i++) {
204  std::cout << "input name = '" << tests[i]
205  << "', output name = '" << normalize_name(tests[i])
206  << "'" << std::endl;
207  }
208 }
209 
210 #endif
static NameMappings_t renamingMap
const char * out
static ProcedureStatusMapping_t fakeProcedureMap
const char * MONITOR_DATA_FIRST_TOUCH
const char * PROGRAM_ROOT
static void normalize_name_load_renamings()
const char * DATACENTRIC_UNKNOWN
const char * OMP_TASK_WAIT
std::map< const char *, const char *, NameMapCompare > NameMappings_t
#define GUARD_NAME
Definition: dictionary.h:50
const int NO_FAKE
const char * OMP_OVERHEAD
const char * THREAD_ROOT
const int FAKE_ROOT
const char * DATACENTRIC_DYNAMIC
const char * OMP_BARRIER_WAIT
static NameMapping renamingTable[]
const int FAKE_PROCEDURE
std::map< const char *, int > ProcedureStatusMapping_t
int main(int argc, char *argv[])
Definition: main.cpp:125
const char * DATACENTRIC_STATIC
const char * OMP_IDLE
const char * normalize_name(const char *in, int &fake_procedure)
const char * NO_THREAD_ROOT
const char * DATACENTRIC_ROOT
const char * OMP_MUTEX_WAIT
const char * in
static ProcedureStatusMapping fakeProcedureTable[]
static const char * normalize_name_rename(const char *in, int &fake_procedure)
bool operator()(const char *n1, const char *n2) const