HPCToolkit
sample_source_obj.h
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 #ifndef SAMPLE_SOURCE_H
48 #define SAMPLE_SOURCE_H
49 
50 #include <stdbool.h>
51 
52 #include "simple_oo.h"
53 
54 // OO macros for sample_sources
55 
56 #define METHOD_DEF(retn,name,...) retn (*name)(struct sample_source_t* self, ##__VA_ARGS__)
57 
58 // abbreviation macro for common case of void methods
59 #define VMETHOD_DEF(name,...) METHOD_DEF(void,name, ##__VA_ARGS__)
60 #define METHOD_FN(n,...) n(sample_source_t *self, ##__VA_ARGS__)
61 
62 #include "evlist.h"
63 
64 // A sample source "state"
65 // UNINIT and INIT refer to the source
66 // START and STOP are on a per-thread basis
67 
68 typedef enum {
75 
76 typedef struct {
77  void* ptr;
79 
80 typedef enum {
81  SS_HARDWARE, // use sample counters or other hardware.
82  // NOTE: *Currently limited to only 1 hardware class sample source*
83  SS_SOFTWARE // software-based, e.g. synchronous samples.
84 } ss_class_t;
85 
86 typedef struct sample_source_t {
87  // common methods
88 
89  VMETHOD_DEF(add_event, const char* ev_str);
90  VMETHOD_DEF(store_event, int event_id, long thresh);
91  VMETHOD_DEF(store_metric_id, int event_idx, int metric_id);
92 
93  METHOD_DEF(int, store_event_and_info, int event_id, long thresh, int metric_id, void *info);
94  METHOD_DEF(char*, get_event_str);
95  METHOD_DEF(bool, started);
96 
97  // specific methods
98 
99  VMETHOD_DEF(init);
100  VMETHOD_DEF(thread_init);
101  VMETHOD_DEF(thread_init_action);
102  VMETHOD_DEF(start);
103  VMETHOD_DEF(thread_fini_action);
104  VMETHOD_DEF(stop);
105  VMETHOD_DEF(shutdown);
106  METHOD_DEF(bool, supports_event, const char* ev_str);
107  VMETHOD_DEF(process_event_list, int lush_agents);
108  VMETHOD_DEF(gen_event_set, int lush_agents);
109  VMETHOD_DEF(display_events);
110 
111  // data
112  evlist_t evl; // event list
113  int sel_idx; // selection index of sample source
114  const char* name; // text name of sample source
115  source_state_t state; // state of sample source: limited to UNINIT or INIT
116  ss_class_t cls; // kind of sample source: see ss_class_t typedef at top of file
117  int sort_order; // registered list order: low to high
118  struct sample_source_t* next_reg; // simple linked list of REGISTERED sample source objects
119  struct sample_source_t* next_sel; // simple linked list of SELECTED sample source objects
120 
122 
123 
124 #endif // SAMPLE_SOURCE_H
source_state_t
struct sample_source_t * next_sel
ss_class_t
VMETHOD_DEF(add_event, const char *ev_str)
struct sample_source_t sample_source_t
source_state_t state
struct sample_source_t * next_reg
METHOD_DEF(int, store_event_and_info, int event_id, long thresh, int metric_id, void *info)
lush_agent_pool_t * lush_agents