Intro | Functions | Defines | Enumerations | Enumeration Values

map.h

Go to the documentation of this file.
00001 /* -*- linux-c -*- */
00002 #include <linux/types.h>
00003 
00004 typedef struct {
00005         int64_t count;
00006         int64_t sum;
00007         int64_t min, max;
00008         int64_t histogram[BUCKETS];
00009 } stat;
00010 
00011 union key_data {
00012         long val;
00013         char *str;
00014 };
00015 
00016 enum keytype { NONE, LONG, STR } __attribute__ ((packed));
00017 enum valtype { INT64, STAT, STRING, END };
00018 
00019 /* all map nodes have the following structure */
00020 struct map_node {
00021         struct list_head lnode;
00022         struct hlist_node hnode;
00023         union key_data key1;
00024         union key_data key2;
00025         enum keytype key1type;
00026         enum keytype key2type;
00027 };
00028 
00029 /* specific map nodes with data attached */
00030 struct map_node_int64 {
00031         struct map_node n;
00032         int64_t val;
00033 };
00034 
00035 struct map_node_str {
00036         struct map_node n;
00037         char *str;
00038 };
00039 
00040 struct map_node_stat {
00041         struct map_node n;
00042         stat stats;
00043 };
00044 
00045 struct map_root {
00046         /* type of the values stored in the array */
00047         enum valtype type;
00048 
00049         /* maximum number of elements allowed in the array. */
00050         int maxnum;
00051 
00052         /* current number of elements */
00053         int num;
00054 
00055         /* when more than maxnum elements, wrap or discard */
00056         int no_wrap;
00057 
00058         /* linked list of current entries */
00059         struct list_head head;
00060 
00061         /* pool of unused entries.  Used only when entries are statically allocated */
00062         /* at startup. */
00063         struct list_head pool;
00064 
00065         /* saved key entry for lookups */
00066         struct map_node *key;
00067 
00068         /* this is the creation data saved between the key functions and the */
00069         /* set/get functions */
00070         u_int8_t create;
00071         enum keytype c_key1type;
00072         enum keytype c_key2type;
00073         struct hlist_head *c_keyhead;
00074         union key_data c_key1;
00075         union key_data c_key2;
00076 
00077         /* the hash table for this array */
00078         struct hlist_head hashes[HASH_TABLE_SIZE];
00079 
00080         /* pointer to allocated memory space */
00081         void *membuf;
00082 };
00083 
00084 typedef struct map_root *MAP;
00085 
00086 #define key1str(ptr) (ptr->n.key1.str)
00087 #define key2str(ptr) (ptr->n.key2.str)
00088 #define key1int(ptr) (ptr->n.key1.val)
00089 #define key2int(ptr) (ptr->n.key2.val)
00090 
00091 #define _stp_map_key2(map, key1, key2)                          \
00092   ({                                                            \
00093     if (__builtin_types_compatible_p (typeof (key1), char[]))   \
00094       if (__builtin_types_compatible_p (typeof (key2), char[])) \
00095         _stp_map_key_str_str (map, (char *)(key1), (char *)(key2));     \
00096       else                                                      \
00097         _stp_map_key_str_long (map, (char *)(key1), (long)(key2));      \
00098     else                                                        \
00099       if (__builtin_types_compatible_p (typeof (key2), char[])) \
00100         _stp_map_key_long_str (map, (long)(key1), (char *)(key2));      \
00101       else                                                      \
00102         _stp_map_key_long_long (map, (long)(key1), (long)(key2));       \
00103   })
00104 
00105 #define _stp_map_key(map, key)                          \
00106   ({                                                            \
00107     if (__builtin_types_compatible_p (typeof (key), char[]))    \
00108       _stp_map_key_str (map, (char *)(key));                            \
00109     else                                                        \
00110       _stp_map_key_long (map, (long)(key));                             \
00111   })
00112 
00113 #define _stp_map_set(map, val)                          \
00114   ({                                                            \
00115     if (__builtin_types_compatible_p (typeof (val), char[]))    \
00116       _stp_map_set_str (map, (char *)(val));                            \
00117     else                                                        \
00118       _stp_map_set_int64 (map, (int64_t)(val));                 \
00119   })
00120 
00121 #define _stp_list_add(map, val)                         \
00122   ({                                                            \
00123     if (__builtin_types_compatible_p (typeof (val), char[]))    \
00124       _stp_list_add_str (map, (char *)(val));                           \
00125     else                                                        \
00126       _stp_list_add_int64 (map, (int64_t)(val));                        \
00127   })
00128 
00129 
00138 #define foreach(map, ptr)                               \
00139   for (ptr = (typeof(ptr))_stp_map_start(map); ptr; \
00140        ptr = (typeof(ptr))_stp_map_iter (map, (struct map_node *)ptr))
00141 

Generated on Mon Mar 21 13:29:45 2005 for SystemTap by  doxygen 1.4.1