summaryrefslogtreecommitdiffstats
path: root/runtime/map.doc
blob: 6f05b6dbe295c9c2638f6c2447c365c18f53924d (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
/** @addtogroup maps 
Implements maps (associative arrays) and lists

Maps may contains up to five keys and one value.  Keys may 64-bit ints (INT64) or
strings (STRING). Values may be 64-bit ints, strings or statistics (STAT).

In order to efficiently handle maps with up to five keys of any combination
of int64s and strings, the functions to create maps and set and get values
are all generated as needed.  To do this, you must simply do some defines and 
include the proper files.  For example, if you need a map with 3 keys, int64, int64, and string
that stores strings, you need to do

@code
#define VALUE_TYPE STRING
#define KEY1_TYPE INT64
#define KEY2_TYPE INT64
#define KEY3_TYPE STRING
#include "map-gen.c"
@endcode

Repeat the above lines for any other needed maps.

In the above example, maps are created with _stp_map_new_iiss(). All the
generated functions start with a base name (such as _stp_map_new) and add the key and value types where types
are abbreviated by "i" (int64), "s" (string) and "x" (statistics).

To continue the provious example,

@code
//** create a map with a max of 100 elements containing strings **//
MAP mymap = _stp_map_new_iiss(100);

//** mymap[100, 300, "Ohio"] = "Columbus" **//
_stp_map_set_iiss (mymap, 100, 300, "Ohio", "Columbus");
@endcode

All elements have a default value of 0 (or NULL).  Elements are only saved to the map when their value is set
to something nonzero.  Setting a map node to 0 (or "") deletes it.

For good examples, see the runtime/tests/maps directory or the example probes.
@{ */

#include "map.h"

/** Create a new map.
* The exact name of this function depends on the defined key types.
* See the map overview.
* This functions accepts a variable number of arguments depending on 
* the value of valtype.  
* @param num_entries The maximum number of entries. Space for these
* entries are allocated when the SystemTap module is loaded.
* @returns A MAP pointer. NULL on error.
*/
MAP _stp_map_new_[is]+ (int num_entries){}

/** Create a new map with values of stats with log histograms.
* When the histogram type is HIST_LOG, the following parameters are expected.
* @param num_entries The maximum number of entries. Space for these
* entries are allocated when the SystemTap module is loaded.
* @param buckets Number of buckets in the histogram. The maximum values
* for each bucket are 0, 1, 2, 4, 8, 16, 32, ... So if buckets is 8 the
* histogram will go from 0 - 64.
*/
MAP _stp_map_new_([is]+)x (int num_entries, HIST_LOG, int buckets){}

/** Create a new map with values of stats with linear histograms.
* When the histogram type is HIST_LOG, the following parameters are expected.
* @param num_entries The maximum number of entries. Space for these
* entries are allocated when the SystemTap module is loaded.
* @param start The starting value of the histogram.
* @param stop The stopping value of the histogram.
* @param interval The interval.
* @todo Check for reasonable values.
*/
MAP _stp_map_new_([is]+)x (int num_entries, HIST_LINEAR, int start, int stop, int interval) {}

/** Set a node's value.
 * This sets a node's value to either an int64 or string.  If the map
 * is storing statistics, the statistics are cleared and the value is added to it.
 *
 * If the value is 0 or "", the node is deleted, if it exists.
 *
 * LOCKING: You must hold a writelock on the map when calling this.
 *
 * @param map
 * @param val new value
 * @returns \li \c 0 on success \li \c -1 on overflow \li \c -2 on bad map or key
 */
int _stp_map_set_([is]+)x (MAP map, <VALTYPE> val) {}

/** Adds to a node's value.
 * For INT64 maps, this adds to the node's value. 
 *
 * For STRING maps, this concatenates to the node's value. 
 *
 * For STAT maps, this adds to the node's accumulated stats.
 *
 * If no node with the proper key exists, it is created first.
 *
 * LOCKING: You must hold a writelock on the map when calling this.
 *
 * @param map
 * @param val value to append
 * @returns \li \c 0 on success \li \c -1 on overflow \li \c -2 on bad map or key
 */
int _stp_map_add_([is]+)x (MAP map, <VALTYPE> val) {}

/** Gets a node's value.
 * This looks up a node given the specified keys and returns its value.
 * If the node doesn't exist, it returns 0 or "" (depending on type).
 *
 * LOCKING: You must get a readlock on the map before calling this.
 * Release it when finished processing the returned value.
 *
 * @param map
 * @param key
 * @returns Depending on VALTYPE, returns \li \c int64_t value
 * \li \c char *value or \li \c stat *value.
 */
<VALTYPE> _stp_map_get_([is]+)x (MAP map, <KEY1TYPE> key1,..., <KEYNTYPE> keyn) {}

/** @} end of addtogroup */

/** @page format_string Format Strings
Format strings for maps and stats use a special format string. Be careful 
not to confuse it with a printf-style format.
@verbatim
--- KEYS and RESULTS ---
%p - address (hex padded to sizeof(void *))
%P - symbolic address
%x - hex int64
%X - HEX int64
%d - decimal int64
%s - string
--- STATS ---
%m - min
%M - max
%A - avg
%S - sum
%H - histogram
%C - count
--- MISC ---
%% - print '%'
--- PER_CPU ---
%c - CPU number
@endverbatim
When printing map keys, format types are preceeded by a single-digit number 
indicating the key number. For example, "%1d,%2s" prints key 1 as an int64 followed by
key 2 as a string. Here's a good example from the test files.
@include map_format.c
*/