summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/map_8h-source.html
blob: 956ac2000321e034ceba27e199f1b35629f6d069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SystemTap: map.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>map.h</h1><a href="map_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _MAP_H_ </span><span class="comment">/* -*- linux-c -*- */</span>
00002 <span class="preprocessor">#define _MAP_H_</span>
00003 <span class="preprocessor"></span><span class="comment"></span>
00004 <span class="comment">/** @file map.h</span>
00005 <span class="comment"> * @brief Header file for maps and lists </span>
00006 <span class="comment"> */</span><span class="comment"></span>
00007 <span class="comment">/** @addtogroup maps </span>
00008 <span class="comment"> * @todo Needs to be made SMP-safe for when the big lock is removed from kprobes.</span>
00009 <span class="comment"> * @{ </span>
00010 <span class="comment"> */</span>
00011 
00012 <span class="preprocessor">#include &lt;linux/types.h&gt;</span>
00013 
00014 <span class="comment">/* Statistics are stored in this struct */</span>
00015 <span class="keyword">typedef</span> <span class="keyword">struct </span>{
00016         int64_t count;
00017         int64_t sum;
00018         int64_t min, max;
00019         int64_t histogram[BUCKETS];
00020 } stat;
00021 
00022 <span class="comment">/* Keys are either longs or char * */</span>
00023 <span class="keyword">union </span>key_data {
00024         <span class="keywordtype">long</span> val;
00025         <span class="keywordtype">char</span> *str;
00026 };
00027 <span class="comment"></span>
00028 <span class="comment">/** keys can be longs or strings */</span>
<a name="l00029"></a><a class="code" href="group__maps.html#ga33">00029</a> <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga33">keytype</a> { NONE, LONG, STR } __attribute__ ((packed));<span class="comment"></span>
00030 <span class="comment">/** values can be either int64, stats or strings */</span>
<a name="l00031"></a><a class="code" href="group__maps.html#ga34">00031</a> <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga34">valtype</a> { INT64, STAT, STRING, END };
00032 
00033 
00034 <span class="comment">/* basic map element */</span>
00035 <span class="keyword">struct </span>map_node {
00036         <span class="comment">/* list of other nodes in the map */</span>
00037         <span class="keyword">struct </span>list_head lnode;
00038         <span class="comment">/* list of nodes with the same hash value */</span>
00039         <span class="keyword">struct </span>hlist_node hnode; 
00040         <span class="keyword">union </span>key_data key1;
00041         <span class="keyword">union </span>key_data key2;
00042         <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga33">keytype</a> key1type;
00043         <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga33">keytype</a> key2type;
00044 };
00045 
00046 <span class="comment">/* map element containing int64 */</span>
00047 <span class="keyword">struct </span>map_node_int64 {
00048         <span class="keyword">struct </span>map_node n;
00049         int64_t val;
00050 };
00051 
00052 <span class="comment">/* map element containing string */</span>
00053 <span class="keyword">struct </span>map_node_str {
00054         <span class="keyword">struct </span>map_node n;
00055         <span class="keywordtype">char</span> *str;
00056 };
00057 
00058 <span class="comment">/* map element containing stats */</span>
00059 <span class="keyword">struct </span>map_node_stat {
00060         <span class="keyword">struct </span>map_node n;
00061         stat stats;
00062 };
00063 
00064 <span class="comment">/* This structure contains all information about a map.</span>
00065 <span class="comment"> * It is allocated once when _stp_map_new() is called. </span>
00066 <span class="comment"> */</span>
00067 <span class="keyword">struct </span>map_root {
00068         <span class="comment">/* type of the values stored in the array */</span>
00069         <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga34">valtype</a> type;
00070         
00071         <span class="comment">/* maximum number of elements allowed in the array. */</span>
00072         <span class="keywordtype">int</span> maxnum;
00073 
00074         <span class="comment">/* current number of used elements */</span>
00075         <span class="keywordtype">int</span> num;
00076 
00077         <span class="comment">/* when more than maxnum elements, wrap or discard? */</span>
00078         <span class="keywordtype">int</span> no_wrap;
00079 
00080         <span class="comment">/* linked list of current entries */</span>
00081         <span class="keyword">struct </span>list_head head;
00082 
00083         <span class="comment">/* pool of unused entries.  Used only when entries are statically allocated</span>
00084 <span class="comment">            at startup. */</span>
00085         <span class="keyword">struct </span>list_head pool;
00086 
00087         <span class="comment">/* saved key entry for lookups */</span>
00088         <span class="keyword">struct </span>map_node *key;
00089 <span class="comment"></span>
00090 <span class="comment">        /** this is the creation data saved between the key functions and the</span>
00091 <span class="comment">            set/get functions </span>
00092 <span class="comment">            @todo Needs to be per-cpu data for SMP support */</span>
00093         u_int8_t create;
00094         <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga33">keytype</a> c_key1type;
00095         <span class="keyword">enum</span> <a class="code" href="group__maps.html#ga33">keytype</a> c_key2type;
00096         <span class="keyword">struct </span>hlist_head *c_keyhead;
00097         <span class="keyword">union </span>key_data c_key1;
00098         <span class="keyword">union </span>key_data c_key2;
00099 <span class="comment"></span>
00100 <span class="comment">        /** the hash table for this array */</span>
00101         <span class="keyword">struct </span>hlist_head hashes[HASH_TABLE_SIZE];
00102 <span class="comment"></span>
00103 <span class="comment">        /** pointer to allocated memory space. Used for freeing memory. */</span>
00104         <span class="keywordtype">void</span> *membuf;
00105 };
00106 <span class="comment"></span>
00107 <span class="comment">/** All maps are of this type. */</span>
<a name="l00108"></a><a class="code" href="group__maps.html#ga1">00108</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>map_root *<a class="code" href="group__maps.html#ga1">MAP</a>;
00109 <span class="comment"></span>
00110 <span class="comment">/** Extracts string from key1 union */</span>
<a name="l00111"></a><a class="code" href="group__maps.html#ga25">00111</a> <span class="preprocessor">#define key1str(ptr) (ptr-&gt;n.key1.str)</span>
00112 <span class="preprocessor"></span><span class="comment">/** Extracts string from key2 union */</span>
<a name="l00113"></a><a class="code" href="group__maps.html#ga26">00113</a> <span class="preprocessor">#define key2str(ptr) (ptr-&gt;n.key2.str)</span>
00114 <span class="preprocessor"></span><span class="comment">/** Extracts int from key1 union */</span>
<a name="l00115"></a><a class="code" href="group__maps.html#ga27">00115</a> <span class="preprocessor">#define key1int(ptr) (ptr-&gt;n.key1.val)</span>
00116 <span class="preprocessor"></span><span class="comment">/** Extracts int from key2 union */</span>
<a name="l00117"></a><a class="code" href="group__maps.html#ga28">00117</a> <span class="preprocessor">#define key2int(ptr) (ptr-&gt;n.key2.val)</span>
00118 <span class="preprocessor"></span><span class="comment"></span>
00119 <span class="comment">/** Macro to call the proper _stp_map_key functions based on the</span>
00120 <span class="comment"> * types of the arguments. </span>
00121 <span class="comment"> * @note May cause compiler warning on some GCCs </span>
00122 <span class="comment"> */</span>
<a name="l00123"></a><a class="code" href="group__maps.html#ga29">00123</a> <span class="preprocessor">#define _stp_map_key2(map, key1, key2)                          \</span>
00124 <span class="preprocessor">  ({                                                            \</span>
00125 <span class="preprocessor">    if (__builtin_types_compatible_p (typeof (key1), char[]))   \</span>
00126 <span class="preprocessor">      if (__builtin_types_compatible_p (typeof (key2), char[])) \</span>
00127 <span class="preprocessor">        _stp_map_key_str_str (map, (char *)(key1), (char *)(key2));     \</span>
00128 <span class="preprocessor">      else                                                      \</span>
00129 <span class="preprocessor">        _stp_map_key_str_long (map, (char *)(key1), (long)(key2));      \</span>
00130 <span class="preprocessor">    else                                                        \</span>
00131 <span class="preprocessor">      if (__builtin_types_compatible_p (typeof (key2), char[])) \</span>
00132 <span class="preprocessor">        _stp_map_key_long_str (map, (long)(key1), (char *)(key2));      \</span>
00133 <span class="preprocessor">      else                                                      \</span>
00134 <span class="preprocessor">        _stp_map_key_long_long (map, (long)(key1), (long)(key2));       \</span>
00135 <span class="preprocessor">  })</span>
00136 <span class="preprocessor"></span><span class="comment"></span>
00137 <span class="comment">/** Macro to call the proper _stp_map_key function based on the</span>
00138 <span class="comment"> * type of the argument. </span>
00139 <span class="comment"> * @note May cause compiler warning on some GCCs </span>
00140 <span class="comment"> */</span>
<a name="l00141"></a><a class="code" href="group__maps.html#ga30">00141</a> <span class="preprocessor">#define _stp_map_key(map, key)                          \</span>
00142 <span class="preprocessor">  ({                                                            \</span>
00143 <span class="preprocessor">    if (__builtin_types_compatible_p (typeof (key), char[]))    \</span>
00144 <span class="preprocessor">      _stp_map_key_str (map, (char *)(key));                            \</span>
00145 <span class="preprocessor">    else                                                        \</span>
00146 <span class="preprocessor">      _stp_map_key_long (map, (long)(key));                             \</span>
00147 <span class="preprocessor">  })</span>
00148 <span class="preprocessor"></span><span class="comment"></span>
00149 <span class="comment">/** Macro to call the proper _stp_map_set function based on the</span>
00150 <span class="comment"> * type of the argument. </span>
00151 <span class="comment"> * @note May cause compiler warning on some GCCs </span>
00152 <span class="comment"> */</span>
<a name="l00153"></a><a class="code" href="group__maps.html#ga31">00153</a> <span class="preprocessor">#define _stp_map_set(map, val)                                  \</span>
00154 <span class="preprocessor">  ({                                                            \</span>
00155 <span class="preprocessor">    if (__builtin_types_compatible_p (typeof (val), char[]))            \</span>
00156 <span class="preprocessor">      _stp_map_set_str (map, (char *)(val));                            \</span>
00157 <span class="preprocessor">    else  if (__builtin_types_compatible_p (typeof (val), String))      \</span>
00158 <span class="preprocessor">      _stp_map_set_string (map, (String)(val));                         \</span>
00159 <span class="preprocessor">    else                                                                \</span>
00160 <span class="preprocessor">      _stp_map_set_int64 (map, (int64_t)(val));                         \</span>
00161 <span class="preprocessor">  })</span>
00162 <span class="preprocessor"></span><span class="comment"></span>
00163 <span class="comment">/** Loop through all elements of a map or list.</span>
00164 <span class="comment"> * @param map </span>
00165 <span class="comment"> * @param ptr pointer to a map_node_stat, map_node_int64 or map_node_str</span>
00166 <span class="comment"> *</span>
00167 <span class="comment"> * @b Example:</span>
00168 <span class="comment"> * @include foreach.c</span>
00169 <span class="comment"> */</span>
00170 
<a name="l00171"></a><a class="code" href="group__maps.html#ga32">00171</a> <span class="preprocessor">#define foreach(map, ptr)                               \</span>
00172 <span class="preprocessor">  for (ptr = (typeof(ptr))_stp_map_start(map); ptr; \</span>
00173 <span class="preprocessor">       ptr = (typeof(ptr))_stp_map_iter (map, (struct map_node *)ptr))</span>
00174 <span class="preprocessor"></span><span class="comment"></span>
00175 <span class="comment">/** @} */</span>
00176 <span class="comment"></span>
00177 <span class="comment">/** @ingroup lists</span>
00178 <span class="comment"> * @brief Macro to call the proper _stp_list_add function based on the</span>
00179 <span class="comment"> * types of the argument. </span>
00180 <span class="comment"> *</span>
00181 <span class="comment"> * @note May cause compiler warning on some GCCs </span>
00182 <span class="comment"> */</span>
<a name="l00183"></a><a class="code" href="group__lists.html#ga6">00183</a> <span class="preprocessor">#define _stp_list_add(map, val)                                 \</span>
00184 <span class="preprocessor">  ({                                                                    \</span>
00185 <span class="preprocessor">    if (__builtin_types_compatible_p (typeof (val), char[]))            \</span>
00186 <span class="preprocessor">      _stp_list_add_str (map, (char *)(val));                           \</span>
00187 <span class="preprocessor">    else if (__builtin_types_compatible_p (typeof (val), String))       \</span>
00188 <span class="preprocessor">      _stp_list_add_string (map, (String)(val));                        \</span>
00189 <span class="preprocessor">    else                                                                \</span>
00190 <span class="preprocessor">      _stp_list_add_int64 (map, (int64_t)(val));                        \</span>
00191 <span class="preprocessor">  })</span>
00192 <span class="preprocessor"></span>
00193 <span class="preprocessor">#endif </span><span class="comment">/* _MAP_H_ */</span>
</pre></div></body></html>