HPCToolkit
ga.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 // system includes
49 //***************************************************************************
50 
51 #include <stddef.h>
52 #include <stdio.h>
53 #include <string.h>
54 
55 
56 //***************************************************************************
57 // local includes
58 //***************************************************************************
59 
62 #include <sample-sources/common.h>
63 #include <sample-sources/ga.h>
64 
65 #include <hpcrun/metrics.h>
66 #include <hpcrun/thread_data.h>
67 #include <messages/messages.h>
68 #include <utilities/tokenize.h>
69 
70 
71 //***************************************************************************
72 // local variables
73 //***************************************************************************
74 
75 const static long periodDefault = 293;
76 
77 uint64_t hpcrun_ga_period = 0;
78 
84 
85 #if (GA_DataCentric_Prototype)
87 int hpcrun_ga_metricId_dataTblIdx_max = -1; // exclusive upper bound
88 
90 #endif // GA_DataCentric_Prototype
91 
92 
93 //***************************************************************************
94 // method definitions
95 //***************************************************************************
96 
97 static void
98 METHOD_FN(init)
99 {
100  TMSG(GA, "init");
101  self->state = INIT;
102 
108 
109 #if (GA_DataCentric_Prototype)
112 #endif
113 }
114 
115 
116 static void
117 METHOD_FN(thread_init)
118 {
119  TMSG(GA, "thread init (no-op)");
120 }
121 
122 
123 static void
124 METHOD_FN(thread_init_action)
125 {
126  TMSG(GA, "thread init action (no-op)");
127 }
128 
129 
130 static void
131 METHOD_FN(start)
132 {
133  TMSG(GA, "starting GA sample source");
134  TD_GET(ss_state)[self->sel_idx] = START;
135 }
136 
137 
138 static void
139 METHOD_FN(thread_fini_action)
140 {
141  TMSG(GA, "thread fini action (no-op)");
142 }
143 
144 
145 static void
147 {
148  TMSG(GA, "stopping GA sample source");
149  TD_GET(ss_state)[self->sel_idx] = STOP;
150 }
151 
152 
153 static void
154 METHOD_FN(shutdown)
155 {
156  TMSG(GA, "shutdown GA sample source");
157  METHOD_CALL(self, stop);
158  self->state = UNINIT;
159 }
160 
161 
162 static bool
163 METHOD_FN(supports_event, const char *ev_str)
164 {
165  // FIXME: this message comes too early and goes to stderr instead of
166  // the log file.
167  // TMSG(GA, "test support event: %s", ev_str);
168  return hpcrun_ev_is(ev_str, "GA");
169 }
170 
171 
172 static void
173 METHOD_FN(process_event_list, int lush_metrics)
174 {
175  TMSG(GA, "create GA metrics");
176 
177  char* evStr = METHOD_CALL(self, get_event_str);
178 
180  char evName[32];
181  hpcrun_extract_ev_thresh(evStr, sizeof(evName), evName,
183 
184  TMSG(GA, "GA: %s sampling period: %"PRIu64, evName, hpcrun_ga_period);
185 
186  // number of one-sided operations
189 
190  // number of collective operations
193 
194  // exposed latency
198 
199  // exposed excess latency
200  //hpcrun_ga_metricId_latencyExcess = hpcrun_new_metric();
201  //hpcrun_set_metric_info(hpcrun_ga_metricId_latencyExcess, "exs lat (us)");
202 
205 
206 #if (GA_DataCentric_Prototype)
207  for (int i = 0; i < hpcrun_ga_metricId_dataTblSz; ++i) {
209  desc->metricId = hpcrun_new_metric();
210  snprintf(desc->name, hpcrun_ga_metricId_dataStrLen, "ga-data-%d", i);
211  desc->name[hpcrun_ga_metricId_dataStrLen - 1] = '\0';
212  hpcrun_set_metric_info(desc->metricId, desc->name);
213  }
214 #endif
215 }
216 
217 
218 static void
219 METHOD_FN(gen_event_set, int lush_metrics)
220 {
221  TMSG(GA, "gen event set (no-op)");
222 }
223 
224 
225 static void
226 METHOD_FN(display_events)
227 {
228  printf("===========================================================================\n");
229  printf("Available Global Arrays events\n");
230  printf("===========================================================================\n");
231  printf("Name\t\tDescription\n");
232  printf("---------------------------------------------------------------------------\n");
233  printf("GA\t\tCollect Global Arrays metrics by sampling GA operations;\n");
234  printf("\t\tconfigurable sample period (default %ld ops/sample)\n", periodDefault);
235  printf("\n");
236 }
237 
238 
239 //***************************************************************************
240 // object
241 //***************************************************************************
242 
243 // sync class is "SS_SOFTWARE" so that both synchronous and
244 // asynchronous sampling is possible
245 
246 #define ss_name ga
247 #define ss_cls SS_SOFTWARE
248 #define ss_sort_order 110
249 
250 #include "ss_obj.h"
251 
252 
253 //***************************************************************************
254 // interface functions
255 //***************************************************************************
256 
257 #if (GA_DataCentric_Prototype)
258 int
259 hpcrun_ga_dataIdx_new(const char* name)
260 {
264 
266  strncpy(desc->name, name, hpcrun_ga_metricId_dataStrLen);
267  desc->name[hpcrun_ga_metricId_dataStrLen - 1] = '\0';
268  //hpcrun_set_metric_name(desc->metricId, desc->name);
269 
270  TMSG(GA, "hpcrun_ga_dataIdx_new: %s -> metric %d", name, desc->metricId);
271 
272  return idx;
273  }
274  else {
275  return -1;
276  }
277 }
278 #endif // GA_DataCentric_Prototype
int hpcrun_ga_metricId_dataTblIdx_next
hpcrun_ga_metricId_dataDesc_t hpcrun_ga_metricId_dataTbl[]
int hpcrun_ga_metricId_bytesXfr
Definition: ga.c:83
int hpcrun_ga_metricId_latencyExcess
Definition: ga.c:82
char name[hpcrun_ga_metricId_dataStrLen]
Definition: ga.h:91
static hpcrun_ga_metricId_dataDesc_t * hpcrun_ga_metricId_dataTbl_find(int idx)
Definition: ga.h:98
metric_desc_t * hpcrun_set_metric_info_and_period(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_desc_properties_t prop)
Definition: metrics.c:411
int hpcrun_ga_metricId_onesidedOp
Definition: ga.c:79
static const long periodDefault
Definition: ga.c:75
uint64_t hpcrun_ga_period
Definition: ga.c:77
int lush_metrics
Definition: main.c:188
global_array_t * GA
int hpcrun_ga_metricId_collectiveOp
Definition: ga.c:80
#define TD_GET(field)
Definition: thread_data.h:256
static void METHOD_FN(init)
Definition: ga.c:98
bool hpcrun_ev_is(const char *candidate, const char *event_name)
Definition: tokenize.c:194
#define TMSG(f,...)
Definition: messages.h:93
int hpcrun_extract_ev_thresh(const char *in, int evlen, char *ev, long *th, long def)
Definition: tokenize.c:157
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
int hpcrun_ga_dataIdx_new(const char *name)
int hpcrun_ga_metricId_latency
Definition: ga.c:81
int hpcrun_new_metric(void)
Definition: metrics.c:333
#define hpcrun_ga_metricId_dataTblSz
Definition: ga.h:83
metric_desc_t * hpcrun_set_metric_info(int metric_id, const char *name)
Definition: metrics.c:423
int hpcrun_ga_metricId_dataTblIdx_max
#define metric_property_none
Definition: hpcrun-fmt.h:202
#define hpcrun_ga_metricId_dataStrLen
Definition: ga.h:84