HPCToolkit
sample_sources_registered.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 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <unistd.h>
51 
55 
56 #include <messages/messages.h>
57 
58 
59 //------------------------------------------------------------------------------
60 // external declarations
61 //------------------------------------------------------------------------------
62 
63 // external declarations for each of the sample source constructors
64 #define SAMPLE_SOURCE_DECL_MACRO(name) void SS_OBJ_CONSTRUCTOR(name)(void);
65 #include <sample-sources/ss-list.h>
66 #undef SAMPLE_SOURCE_DECL_MACRO
67 
68 
69 
70 //------------------------------------------------------------------------------
71 // local variables
72 //------------------------------------------------------------------------------
73 
75 
76 
77 
78 //------------------------------------------------------------------------------
79 // interface operations
80 //------------------------------------------------------------------------------
81 
82 static void
84 {
85  if (registered_sample_sources != NULL) return; // don't re-register after a fork
86 
87 // invoke each of the sample source constructors
88 #define SAMPLE_SOURCE_DECL_MACRO(name) SS_OBJ_CONSTRUCTOR(name)();
89 #include <sample-sources/ss-list.h>
90 #undef SAMPLE_SOURCE_DECL_MACRO
91 
92 }
93 
94 
95 
96 //------------------------------------------------------------------------------
97 // interface operations
98 //------------------------------------------------------------------------------
99 
100 // insert by order of 'sort_order', low to high
101 void
103 {
104  if (registered_sample_sources == NULL
105  || src->sort_order < registered_sample_sources->sort_order) {
107  registered_sample_sources = src;
108  return;
109  }
110 
112  for (sample_source_t *curr = prev->next_reg; ; prev = curr, curr = curr->next_reg) {
113  if (curr == NULL || src->sort_order < curr->sort_order) {
114  prev->next_reg = src;
115  src->next_reg = curr;
116  break;
117  }
118  }
119 }
120 
121 
124 {
125  for (sample_source_t* ss=registered_sample_sources; ss; ss = ss->next_reg){
126  if (METHOD_CALL(ss, supports_event, event)){
127  return ss;
128  }
129  }
130  return NULL;
131 }
132 
133 
134 // hpcrun_registered_sources_init(): This routine initializes all
135 // samples sources. It is necessary because a sample source, even if
136 // unused, may need to initialized to list available events.
137 // Cf. SAMPLE_SOURCES(init), which only initializes used sample
138 // sources.
139 void
141 {
142  hpcrun_sample_sources_register(); // ensure all sample sources are registered
143 
144  for (sample_source_t* ss=registered_sample_sources; ss; ss = ss->next_reg){
145  METHOD_CALL(ss, init);
146  TMSG(SS_COMMON, "sample source \"%s\": init", ss->name);
147  }
148 }
149 
150 void
152 {
153  for (sample_source_t* ss = registered_sample_sources; ss; ss = ss->next_reg) {
154  METHOD_CALL(ss, display_events);
155  }
156 
157  exit(0);
158 }
static sample_source_t * registered_sample_sources
void hpcrun_registered_sources_init(void)
void hpcrun_ss_register(sample_source_t *src)
exit
Definition: names.cpp:1
static void hpcrun_sample_sources_register(void)
struct sample_source_t * next_reg
#define TMSG(f,...)
Definition: messages.h:93
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
sample_source_t * hpcrun_source_can_process(char *event)
#define NULL
Definition: ElfHelper.cpp:85
void hpcrun_display_avail_events(void)