HPCToolkit
metrics.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 METRICS_H
48 #define METRICS_H
49 
50 #include <sys/types.h>
51 #include <stdbool.h>
52 
53 #include <lib/prof-lean/hpcio.h>
54 #include <lib/prof-lean/hpcfmt.h>
56 
57 // tallent: I have moved flags into hpcfile_csprof.h. The flags don't
58 // really belong there but:
59 // 1) metrics.c uses hpcfile_hpcrun_data_t to implement metrics
60 // info, which already confuses boundaries
61 // 2) metric info needs to exist in a library so csprof (hpcrun),
62 // xcsprof (hpcprof) and hpcfile can use it. hpcfile at least
63 // satisfies this.
64 
65 #include <stdbool.h>
66 #include <stdlib.h>
67 #include <assert.h>
68 
69 #include <lib/prof-lean/hpcio.h>
70 #include <lib/prof-lean/hpcfmt.h>
72 
74 
75 // abstract the metric set
76 //
77 typedef struct metric_set_t metric_set_t;
78 
79 typedef void metric_upd_proc_t(int metric_id, metric_set_t* set, cct_metric_data_t datum);
80 
82 
83 typedef struct metric_proc_map_t {
86  int id;
87  int kind_idx; // metrics are divided into "kinds"
88  int offset;
90 
91 //
92 // To accomodate block sparse representation,
93 // use 'kinds' == dense subarrays of metrics
94 //
95 // Sample use:
96 // Std metrics = 1 class,
97 // CUDA metrics = another class
98 //
99 // To use the mechanism, call hpcrun_metrics_new_kind.
100 // Then each call to hpcrun_new_metric will yield a slot in the
101 // new metric kind subarray.
102 //
103 // For complicated metric assignment, hpcrun_switch_metric_kind(kind),
104 // and hpcrun_get_new_metric_of_kind(kind) enable fine-grain control
105 // of metric sloc allocation
106 //
107 // Default case is 1 kind ("STD")
108 //
109 // Future expansion to permit different strategies is possible, but
110 // unimplemented at this time
111 
112 typedef struct kind_info_t kind_info_t;
113 
115 
116 bool hpcrun_metrics_finalized(void);
117 
118 extern void hpcrun_finalize_metrics(void);
119 
120 void hpcrun_pre_allocate_metrics(size_t num);
121 
122 int hpcrun_get_num_metrics(void);
123 
125 
127 
128 metric_desc_p_tbl_t* hpcrun_get_metric_tbl(void);
129 
131 
132 // get a new metric from the cached kind
133 int hpcrun_new_metric(void);
134 
136 hpcrun_set_metric_info_w_fn(int metric_id, const char* name,
137  MetricFlags_ValFmt_t valFmt, size_t period,
139 
141 hpcrun_set_metric_and_attributes(int metric_id, const char* name,
143  uint8_t show, uint8_t show_percent);
144 
146 hpcrun_set_metric_info_and_period(int metric_id, const char* name,
148 
149 metric_desc_t* hpcrun_set_metric_info(int metric_id, const char* name);
150 
151 void hpcrun_set_metric_name(int metric_id, char* name);
152 
153 // metric set operations
154 
155 extern metric_set_t* hpcrun_metric_set_new(void);
157 extern void hpcrun_metric_std_set(int metric_id, metric_set_t* set,
158  hpcrun_metricVal_t value);
159 extern void hpcrun_metric_std_inc(int metric_id, metric_set_t* set,
160  hpcrun_metricVal_t incr);
161 
162 // set the minimum value (only applicable for address type value)
163 void
164 hpcrun_metric_std_min(int metric_id, metric_set_t *set, hpcrun_metricVal_t val);
165 
166 // set the maximum value (only applicable for address type value)
167 void
168 hpcrun_metric_std_max(int metric_id, metric_set_t *set, hpcrun_metricVal_t val);
169 
170 //
171 // copy a metric set
172 //
174  metric_set_t* set,
175  int num_metrics);
176 
177 #endif // METRICS_H
bool hpcrun_metrics_finalized(void)
Definition: metrics.c:183
cct_metric_data_t * hpcrun_metric_set_loc(metric_set_t *s, int id)
Definition: metrics.c:465
metric_desc_t * hpcrun_set_metric_info(int metric_id, const char *name)
Definition: metrics.c:423
void hpcrun_metric_set_dense_copy(cct_metric_data_t *dest, metric_set_t *set, int num_metrics)
Definition: metrics.c:560
void hpcrun_pre_allocate_metrics(size_t num)
Definition: metrics.c:190
void metric_upd_proc_t(int metric_id, metric_set_t *set, cct_metric_data_t datum)
Definition: metrics.h:79
void hpcrun_set_metric_name(int metric_id, char *name)
Definition: metrics.c:439
struct metric_proc_map_t * next
Definition: metrics.h:84
metric_upd_proc_t * hpcrun_get_metric_proc(int metric_id)
Definition: metrics.c:281
void hpcrun_metric_std_max(int metric_id, metric_set_t *set, hpcrun_metricVal_t val)
Definition: metrics.c:549
struct metric_proc_map_t metric_proc_map_t
kind_info_t * hpcrun_metrics_new_kind()
Definition: metrics.c:147
metric_set_t * hpcrun_metric_set_new(void)
Definition: metrics.c:456
hpcrun_metricVal_t v1
Definition: metrics.c:86
void hpcrun_finalize_metrics(void)
Definition: metrics.c:245
void hpcrun_metric_std_min(int metric_id, metric_set_t *set, hpcrun_metricVal_t val)
Definition: metrics.c:542
metric_desc_t * hpcrun_set_metric_info_w_fn(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_upd_proc_t upd_fn, metric_desc_properties_t prop)
Definition: metrics.c:339
cct_metric_data_t(* metric_bin_fn)(cct_metric_data_t v1, cct_metric_data_t v2)
Definition: metrics.h:81
int hpcrun_new_metric(void)
Definition: metrics.c:333
metric_list_t * hpcrun_get_metric_data(void)
Definition: metrics.c:271
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
hpcrun_metricVal_t cct_metric_data_t
Definition: metrics.h:73
metric_desc_t * hpcrun_set_metric_and_attributes(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_desc_properties_t prop, uint8_t show, uint8_t show_percent)
Definition: metrics.c:397
metric_desc_t * hpcrun_id2metric(int id)
Definition: metrics.c:251
metric_upd_proc_t * proc
Definition: metrics.h:85
void hpcrun_metric_std_set(int metric_id, metric_set_t *set, hpcrun_metricVal_t value)
Definition: metrics.c:525
MetricFlags_ValFmt_t
Definition: hpcrun-fmt.h:248
static long period
Definition: itimer.c:194
metric_desc_p_tbl_t * hpcrun_get_metric_tbl(void)
Definition: metrics.c:262
void hpcrun_metric_std_inc(int metric_id, metric_set_t *set, hpcrun_metricVal_t incr)
Definition: metrics.c:534
int hpcrun_get_num_metrics(void)
Definition: metrics.c:209