HPCToolkit
io.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/io.h>
64 
65 #include <hpcrun/metrics.h>
66 #include <hpcrun/thread_data.h>
67 #include <messages/messages.h>
68 
69 #include <utilities/tokenize.h>
70 
71 /******************************************************************************
72  * local variables
73  *****************************************************************************/
74 
75 static int metric_id_read = -1;
76 static int metric_id_write = -1;
77 
78 
79 /******************************************************************************
80  * method definitions
81  *****************************************************************************/
82 
83 static void
84 METHOD_FN(init)
85 {
86  TMSG(IO, "init");
87  self->state = INIT;
88  metric_id_read = -1;
89  metric_id_write = -1;
90 }
91 
92 
93 static void
94 METHOD_FN(thread_init)
95 {
96  TMSG(IO, "thread init (no-op)");
97 }
98 
99 
100 static void
101 METHOD_FN(thread_init_action)
102 {
103  TMSG(IO, "thread init action (no-op)");
104 }
105 
106 
107 static void
108 METHOD_FN(start)
109 {
110  TMSG(IO, "starting IO sample source");
111  TD_GET(ss_state)[self->sel_idx] = START;
112 }
113 
114 
115 static void
116 METHOD_FN(thread_fini_action)
117 {
118  TMSG(IO, "thread fini action (no-op)");
119 }
120 
121 
122 static void
124 {
125  TMSG(IO, "stopping IO sample source");
126  TD_GET(ss_state)[self->sel_idx] = STOP;
127 }
128 
129 
130 static void
131 METHOD_FN(shutdown)
132 {
133  TMSG(IO, "shutdown IO sample source");
134  METHOD_CALL(self, stop);
135  self->state = UNINIT;
136 }
137 
138 
139 static bool
140 METHOD_FN(supports_event, const char *ev_str)
141 {
142  // FIXME: this message comes too early and goes to stderr instead of
143  // the log file.
144  // TMSG(IO, "test support event: %s", ev_str);
145  return hpcrun_ev_is(ev_str, "IO");
146 }
147 
148 
149 // IO metrics: bytes read and bytes written.
150 
151 static void
152 METHOD_FN(process_event_list, int lush_metrics)
153 {
154  TMSG(IO, "create metrics for IO bytes read and bytes written");
157  hpcrun_set_metric_info(metric_id_read, "IO Bytes Read");
158  hpcrun_set_metric_info(metric_id_write, "IO Bytes Written");
159  TMSG(IO, "metric id read: %d, write: %d", metric_id_read, metric_id_write);
160 }
161 
162 
163 static void
164 METHOD_FN(gen_event_set, int lush_metrics)
165 {
166  TMSG(IO, "gen event set (no-op)");
167 }
168 
169 
170 static void
171 METHOD_FN(display_events)
172 {
173  printf("===========================================================================\n");
174  printf("Available IO events\n");
175  printf("===========================================================================\n");
176  printf("Name\t\tDescription\n");
177  printf("---------------------------------------------------------------------------\n");
178  printf("IO\t\tThe number of bytes read and written per dynamic context\n");
179  printf("\n");
180 }
181 
182 
183 /***************************************************************************
184  * object
185  ***************************************************************************/
186 
187 // sync class is "SS_SOFTWARE" so that both synchronous and
188 // asynchronous sampling is possible
189 
190 #define ss_name io
191 #define ss_cls SS_SOFTWARE
192 #define ss_sort_order 40
193 
194 #include "ss_obj.h"
195 
196 
197 // ***************************************************************************
198 // Interface functions
199 // ***************************************************************************
200 
201 int
203 {
204  return metric_id_read;
205 }
206 
207 int
209 {
210  return metric_id_write;
211 }
int hpcrun_metric_id_write(void)
Definition: io.c:208
static int metric_id_write
Definition: io.c:76
int hpcrun_metric_id_read(void)
Definition: io.c:202
static void METHOD_FN(init)
Definition: io.c:84
static int metric_id_read
Definition: io.c:75
int lush_metrics
Definition: main.c:188
#define TD_GET(field)
Definition: thread_data.h:256
bool hpcrun_ev_is(const char *candidate, const char *event_name)
Definition: tokenize.c:194
#define TMSG(f,...)
Definition: messages.h:93
#define METHOD_CALL(obj, meth,...)
Definition: simple_oo.h:87
int hpcrun_new_metric(void)
Definition: metrics.c:333
metric_desc_t * hpcrun_set_metric_info(int metric_id, const char *name)
Definition: metrics.c:423