+2005-11-09 Martin Hunt <hunt@redhat.com>
+
+ * map.h (struct map_root): Delete fields
+ used by old API.
+
+ * map.c: Remove old map API functions.
+ * map-stat.c (_stp_map_add_stat): Delete.
+ (_stp_pmap_new_hstat_linear): Move here from map.c.
+ (_stp_pmap_new_hstat_log): Ditto.
+
+ * list.c: Deleted.
+ * map-keys.c: Deleted.
+ * map-values.c: Deleted.
+ * map-int.c: Deleted.
+
2005-11-08 Martin Hunt <hunt@redhat.com>
* alloc.c (__stp_valloc_percpu): Fix call to vmalloc_node.
+++ /dev/null
-/* -*- linux-c -*-
- * List Functions
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-#ifndef _LIST_C_ /* -*- linux-c -*- */
-#define _LIST_C_
-
-#include "map.c"
-#include "copy.c"
-
-/********************** List Functions *********************/
-/** @file list.c
- * @brief List Functions
- */
-
-/** @addtogroup lists
- * Lists are special cases of maps.
- * @b Example:
- * @include list.c
- * @{ */
-
-/** Create a new list.
- * A list is a map that internally has an incrementing long key for each member.
- * Lists do not wrap if elements are added to exceed their maximum size.
- * @param max_entries The maximum number of entries allowed. Currently that number will
- * be preallocated. If max_entries is 0, there will be no maximum and entries
- * will be allocated dynamically.
- * @param type Type of values stored in this list.
- * @return A MAP on success or NULL on failure.
- * @sa foreach
- */
-
-MAP _stp_list_new(unsigned max_entries, int type)
-{
- MAP map = _stp_map_new_int64 (max_entries, type);
- map->list = 1;
- return map;
-}
-
-/** Clears a list.
- * All elements in the list are deleted.
- * @param map
- */
-
-void _stp_list_clear(MAP map)
-{
- if (map == NULL)
- return;
-
- if (!list_empty(&map->head)) {
- struct map_node *ptr = (struct map_node *)map->head.next;
-
- while (ptr && ptr != (struct map_node *)&map->head) {
- struct map_node *next = (struct map_node *)ptr->lnode.next;
-
- /* remove node from old hash list */
- hlist_del_init(&ptr->hnode);
-
- /* remove from entry list */
- list_del(&ptr->lnode);
-
- list_add(&ptr->lnode, &map->pool);
-
- map->num--;
- ptr = next;
- }
- }
-
- if (map->num != 0) {
- _stp_warn ("list is supposed to be empty (has %d)\n", map->num);
- }
-}
-
-/** Adds a C string to a list.
- * @param map
- * @param str
- * @sa _stp_list_add()
- */
-
-inline void _stp_list_add_str(MAP map, char *str)
-{
- _stp_map_key_int64 (map, map->num);
- _stp_map_set_str(map, str);
-}
-
-/** Adds a String to a list.
- * @param map
- * @param str String to add.
- * @sa _stp_list_add()
- */
-
-inline void _stp_list_add_string (MAP map, String str)
-{
- _stp_map_key_int64 (map, map->num);
- _stp_map_set_str(map, str->buf);
-}
-
-/** Adds an int64 to a list.
- * @param map
- * @param val
- * @sa _stp_list_add()
- */
-
-inline void _stp_list_add_int64(MAP map, int64_t val)
-{
- _stp_map_key_int64 (map, map->num);
- _stp_map_set_int64(map, val);
-}
-
-/** Get the number of elements in a list.
- * @param map
- * @returns The number of elements in a list.
- */
-
-inline int _stp_list_size(MAP map)
-{
- return map->num;
-}
-
-/** Copy an argv from user space to a List.
- *
- * @param list A list.
- * @param argv Source argv, in user space.
- * @return number of elements in <i>list</i>
- *
- * @b Example:
- * @include argv.c
- */
-
-int _stp_copy_argv_from_user (MAP list, char __user *__user *argv)
-{
- char str[128];
- char __user *vstr;
- int len;
-
- if (argv)
- argv++;
-
- while (argv != NULL) {
- if (get_user (vstr, argv))
- break;
-
- if (vstr == NULL)
- break;
-
- len = _stp_strncpy_from_user(str, vstr, 128);
- str[len] = 0;
- _stp_list_add_str (list, str);
- argv++;
- }
- return list->num;
-}
-
-/** @} */
-#endif /* _LIST_C_ */
struct hlist_head *head;
struct hlist_node *e;
struct KEYSYM(map_node) *n;
- int res;
if (map == NULL)
return -2;
+++ /dev/null
-/* -*- linux-c -*-
- * map functions to handle integer values
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-/** @file map-int.c
- * @brief Map functions to set and get int64s
- */
-
-int __stp_map_set_int64 (MAP map, int64_t val, int add)
-{
- struct map_node *m;
-
- if (map == NULL)
- return -2;
-
- if (map->create) {
- if (val == 0 && !map->list)
- return 0;
-
- m = __stp_map_create (map);
- if (!m)
- return -1;
-
- /* set the value */
- //dbug ("m=%lx offset=%lx\n", (long)m, (long)map->data_offset);
- *(int64_t *)((long)m + map->data_offset) = val;
- } else {
- if (map->key == NULL)
- return -2;
-
- if (val) {
- if (add)
- *(int64_t *)((long)map->key + map->data_offset) += val;
- else
- *(int64_t *)((long)map->key + map->data_offset) = val;
- } else if (!add) {
- /* setting value to 0 is the same as deleting */
- _stp_map_key_del(map);
- }
- }
- return 0;
-}
-/** Set the current element's value to an int64.
- * This sets the current element's value to an int64. The map must have been created
- * to hold int64s using <i>_stp_map_new_(xxx, INT64)</i>
- *
- * If the element doesn't exist, it is created. If no current element (key)
- * is set for the map, this function does nothing.
- * @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
- * @sa _stp_map_add_int64()
- * @sa _stp_map_set()
- * @ingroup map_set
- */
-#define _stp_map_set_int64(map,val) __stp_map_set_int64 (map,val,0)
-
-/** Get the value of a map.
- * This gets the current element's int64 value. The map must have been created
- * to hold int64s using <i>_stp_map_new_(xxx, INT64)</i>
- *
- * If no current element (key) is set for the map, this function returns 0.
- *
- * @ingroup map_set
- * @param map
- * @returns an int64 value.
- */
-int64_t _stp_map_get_int64 (MAP map)
-{
- struct map_node *m;
- if (map == NULL || map->create || map->key == NULL)
- return 0;
- //dbug ("key %lx\n", (long)map->key);
- m = (struct map_node *)map->key;
- return *(int64_t *)((long)m + map->data_offset);
-}
-
+++ /dev/null
-/* -*- linux-c -*-
- * map functions to handle keys
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-/** @file map-keys.c
- * @brief Map functions to set and get keys
- * This file is a template designed to be included as many times as
- * needed to generate the necessary functions to set map keys.
- */
-
-#include "map.h"
-
-#define JOIN(x,y) JOINx(x,y)
-#define JOINx(x,y) x##_##y
-
-#if defined (KEY1_TYPE)
-#define KEY_ARITY 1
-#if KEY1_TYPE == STRING
-#define KEY1TYPE char*
-#define KEY1NAME str
-#define KEY1STOR char key1[MAP_STRING_LENGTH]
-#else
-#define KEY1TYPE int64_t
-#define KEY1NAME int64
-#define KEY1STOR int64_t key1
-#endif
-#define KEY1_EQ_P JOIN(KEY1NAME,eq_p)
-#define KEY1_HASH JOIN(KEY1NAME,hash)
-#endif /* defined(KEY1_TYPE) */
-
-#if defined (KEY2_TYPE)
-#undef KEY_ARITY
-#define KEY_ARITY 2
-#if KEY2_TYPE == STRING
-#define KEY2TYPE char*
-#define KEY2NAME str
-#define KEY2STOR char key2[MAP_STRING_LENGTH]
-#else
-#define KEY2TYPE int64_t
-#define KEY2NAME int64
-#define KEY2STOR int64_t key2
-#endif
-#define KEY2_EQ_P JOIN(KEY2NAME,eq_p)
-#define KEY2_HASH JOIN(KEY2NAME,hash)
-#endif /* defined(KEY2_TYPE) */
-
-#if defined (KEY3_TYPE)
-#undef KEY_ARITY
-#define KEY_ARITY 3
-#if KEY3_TYPE == STRING
-#define KEY3TYPE char*
-#define KEY3NAME str
-#define KEY3STOR char key3[MAP_STRING_LENGTH]
-#else
-#define KEY3TYPE int64_t
-#define KEY3NAME int64
-#define KEY3STOR int64_t key3
-#endif
-#define KEY3_EQ_P JOIN(KEY3NAME,eq_p)
-#define KEY3_HASH JOIN(KEY3NAME,hash)
-#endif /* defined(KEY3_TYPE) */
-
-#if defined (KEY4_TYPE)
-#undef KEY_ARITY
-#define KEY_ARITY 4
-#if KEY4_TYPE == STRING
-#define KEY4TYPE char*
-#define KEY4NAME str
-#define KEY4STOR char key4[MAP_STRING_LENGTH]
-#else
-#define KEY4TYPE int64_t
-#define KEY4NAME int64
-#define KEY4STOR int64_t key4
-#endif
-#define KEY4_EQ_P JOIN(KEY4NAME,eq_p)
-#define KEY4_HASH JOIN(KEY4NAME,hash)
-#endif /* defined(KEY4_TYPE) */
-
-#if defined (KEY5_TYPE)
-#undef KEY_ARITY
-#define KEY_ARITY 5
-#if KEY5_TYPE == STRING
-#define KEY5TYPE char*
-#define KEY5NAME str
-#define KEY5STOR char key5[MAP_STRING_LENGTH]
-#else
-#define KEY5TYPE int64_t
-#define KEY5NAME int64
-#define KEY5STOR int64_t key5
-#endif
-#define KEY5_EQ_P JOIN(KEY5NAME,eq_p)
-#define KEY5_HASH JOIN(KEY5NAME,hash)
-#endif /* defined(KEY5_TYPE) */
-
-#if KEY_ARITY == 1
-#define KEYSYM(x) JOIN(x,KEY1NAME)
-#define ALLKEYS(x) x##1
-#define ALLKEYSD(x) KEY1TYPE x##1
-#elif KEY_ARITY == 2
-#define JOIN2(x,y,z) JOIN2x(x,y,z)
-#define JOIN2x(x,y,z) x##_##y##_##z
-#define KEYSYM(x) JOIN2(x,KEY1NAME,KEY2NAME)
-#define ALLKEYS(x) x##1, x##2
-#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2
-#elif KEY_ARITY == 3
-#define JOIN3(a,b,c,d) JOIN3x(a,b,c,d)
-#define JOIN3x(a,b,c,d) a##_##b##_##c##_##d
-#define KEYSYM(x) JOIN3(x,KEY1NAME,KEY2NAME,KEY3NAME)
-#define ALLKEYS(x) x##1, x##2, x##3
-#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3
-#elif KEY_ARITY == 4
-#define JOIN4(a,b,c,d,e) JOIN4x(a,b,c,d,e)
-#define JOIN4x(a,b,c,d,e) a##_##b##_##c##_##d##_##e
-#define KEYSYM(x) JOIN4(x,KEY1NAME,KEY2NAME,KEY3NAME,KEY4NAME)
-#define ALLKEYS(x) x##1, x##2, x##3, x##4
-#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4
-#elif KEY_ARITY == 5
-#define JOIN5(a,b,c,d,e,f) JOIN5x(a,b,c,d,e,f)
-#define JOIN5x(a,b,c,d,e,f) a##_##b##_##c##_##d##_##e##_##f
-#define KEYSYM(x) JOIN5(x,KEY1NAME,KEY2NAME,KEY3NAME,KEY4NAME,KEY5NAME)
-#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5
-#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5
-#endif
-
-/* */
-struct KEYSYM(map_node) {
- /* list of other nodes in the map */
- struct list_head lnode;
- /* list of nodes with the same hash value */
- struct hlist_node hnode;
- /* pointer back to the map struct */
- struct map_root *map;
-
- KEY1STOR;
-#if KEY_ARITY > 1
- KEY2STOR;
-#if KEY_ARITY > 2
- KEY3STOR;
-#if KEY_ARITY > 3
- KEY4STOR;
-#if KEY_ARITY > 4
- KEY5STOR;
-#endif
-#endif
-#endif
-#endif
-};
-
-#define type_to_enum(type) \
- ({ \
- int ret; \
- if (__builtin_types_compatible_p (type, char*)) \
- ret = STRING; \
- else \
- ret = INT64; \
- ret; \
- })
-
-static key_data KEYSYM(map_get_key) (struct map_node *mn, int n, int *type)
-{
- key_data ptr;
- struct KEYSYM(map_node) *m = (struct KEYSYM(map_node) *)mn;
-
- // dbug ("m=%lx\n", (long)m);
- if (n > KEY_ARITY || n < 1) {
- if (type)
- *type = END;
- return (key_data)(int64_t)0;
- }
-
- switch (n) {
- case 1:
- ptr = (key_data)m->key1;
- if (type)
- *type = type_to_enum(KEY1TYPE);
- break;
-#if KEY_ARITY > 1
- case 2:
- ptr = (key_data)m->key2;
- if (type)
- *type = type_to_enum(KEY2TYPE);
-
- break;
-#if KEY_ARITY > 2
- case 3:
- ptr = (key_data)m->key3;
- if (type)
- *type = type_to_enum(KEY3TYPE);
- break;
-#if KEY_ARITY > 3
- case 4:
- ptr = (key_data)m->key4;
- if (type)
- *type = type_to_enum(KEY4TYPE);
- break;
-#if KEY_ARITY > 4
- case 5:
- ptr = (key_data)m->key5;
- if (type)
- *type = type_to_enum(KEY5TYPE);
- break;
-#endif
-#endif
-#endif
-#endif
- default:
- ptr = (key_data)(int64_t)0;
- if (type)
- *type = END;
- }
- return ptr;
-}
-
-
-static void KEYSYM(map_copy_keys) (MAP map, struct map_node *n)
-{
- struct KEYSYM(map_node) *m = (struct KEYSYM(map_node) *)n;
-#if KEY1_TYPE == STRING
- str_copy (m->key1, map->c_key[0].strp);
-#else
- m->key1 = map->c_key[0].val;
-#endif
-#if KEY_ARITY > 1
-#if KEY2_TYPE == STRING
- str_copy (m->key2, map->c_key[1].strp);
-#else
- m->key2 = map->c_key[1].val;
-#endif
-#if KEY_ARITY > 2
-#if KEY3_TYPE == STRING
- str_copy (m->key3, map->c_key[2].strp);
-#else
- m->key3 = map->c_key[2].val;
-#endif
-#if KEY_ARITY > 3
-#if KEY4_TYPE == STRING
- str_copy (m->key4, map->c_key[3].strp);
-#else
- m->key4 = map->c_key[3].val;
-#endif
-#if KEY_ARITY > 4
-#if KEY5_TYPE == STRING
- str_copy (m->key5, map->c_key[4].strp);
-#else
- m->key5 = map->c_key[4].val;
-#endif
-#endif
-#endif
-#endif
-#endif
-}
-
-
-static unsigned int KEYSYM(hash) (ALLKEYSD(key))
-{
- unsigned int hash = KEY1_HASH(key1);
-#if KEY_ARITY > 1
- hash ^= KEY2_HASH(key2);
-#if KEY_ARITY > 2
- hash ^= KEY3_HASH(key3);
-#if KEY_ARITY > 3
- hash ^= KEY4_HASH(key4);
-#if KEY_ARITY > 4
- hash ^= KEY5_HASH(key5);
-#endif
-#endif
-#endif
-#endif
- return (unsigned int) hash;
-}
-
-/* _stp_map_new_key1_key2 (num, HSTAT_LINEAR, start, end, interval) */
-/* _stp_map_new_key1_key2 (num, HSTAT_LOG, buckets) */
-
-MAP KEYSYM(_stp_map_new) (unsigned max_entries, int valtype, ...)
-{
- int htype, buckets=0, start=0, stop=0, interval=0;
- MAP m;
-
- htype = valtype >> 8;
- // dbug ("htype=%d\n", htype);
-
- if (htype != HIST_NONE) {
- va_list ap;
- va_start (ap, valtype);
-
- if (htype == HIST_LOG) {
- buckets = va_arg(ap, int);
- // dbug ("buckets=%d\n", buckets);
- } else {
- start = va_arg(ap, int);
- stop = va_arg(ap, int);
- interval = va_arg(ap, int);
- // dbug ("start=%d stop=%d interval=%d\n", start, stop, interval);
- }
- va_end (ap);
- }
- switch (htype) {
- case HIST_NONE:
- m = _stp_map_new (max_entries, valtype & 0x0f,
- sizeof(struct KEYSYM(map_node)), 0);
- break;
- case HIST_LOG:
- m = _stp_map_new_hstat_log (max_entries, sizeof(struct KEYSYM(map_node)),
- buckets);
- break;
- case HIST_LINEAR:
- m = _stp_map_new_hstat_linear (max_entries, sizeof(struct KEYSYM(map_node)),
- start, stop, interval);
- break;
- default:
- _stp_warn ("Unknown histogram type %d\n", htype);
- m = NULL;
- }
-
- if (m) {
- m->copy_keys = KEYSYM(map_copy_keys);
- m->get_key = KEYSYM(map_get_key);
- }
- return m;
-}
-
-
-void KEYSYM(_stp_map_key) (MAP map, ALLKEYSD(key))
-{
- unsigned int hv;
- struct hlist_head *head;
- struct hlist_node *e;
-
- if (map == NULL)
- return;
-
- hv = KEYSYM(hash) (ALLKEYS(key));
- head = &map->hashes[hv];
-
- hlist_for_each(e, head) {
- struct KEYSYM(map_node) *n =
- (struct KEYSYM(map_node) *)((long)e - sizeof(struct hlist_node));
- //dbug ("n =%lx key=" EACHKEY(%ld) "\n", (long)n, n->key1.val, n->key2.val);
- if (KEY1_EQ_P(n->key1, key1)
-#if KEY_ARITY > 1
- && KEY2_EQ_P(n->key2, key2)
-#if KEY_ARITY > 2
- && KEY3_EQ_P(n->key3, key3)
-#if KEY_ARITY > 3
- && KEY4_EQ_P(n->key4, key4)
-#if KEY_ARITY > 4
- && KEY5_EQ_P(n->key5, key5)
-#endif
-#endif
-#endif
-#endif
- ) {
- map->key = (struct map_node *)n;
- // dbug ("saving key %lx\n", (long)map->key);
- map->create = 0;
- return;
- }
- }
- map->c_key[0] = (key_data)key1;
-#if KEY_ARITY > 1
- map->c_key[1] = (key_data)key2;
-#if KEY_ARITY > 2
- map->c_key[2] = (key_data)key3;
-#if KEY_ARITY > 3
- map->c_key[3] = (key_data)key4;
-#if KEY_ARITY > 4
- map->c_key[4] = (key_data)key5;
-#endif
-#endif
-#endif
-#endif
-
- map->c_keyhead = head;
- map->create = 1;
-}
-
-
-#undef KEY1NAME
-#undef KEY1TYPE
-#undef KEY1_TYPE
-#undef KEY1STOR
-
-#undef KEY2NAME
-#undef KEY2TYPE
-#undef KEY2_TYPE
-#undef KEY2STOR
-
-#undef KEY3NAME
-#undef KEY3TYPE
-#undef KEY3_TYPE
-#undef KEY3STOR
-
-#undef KEY4NAME
-#undef KEY4TYPE
-#undef KEY4_TYPE
-#undef KEY4STOR
-
-#undef KEY5NAME
-#undef KEY5TYPE
-#undef KEY5_TYPE
-#undef KEY5STOR
-
-#undef KEY_ARITY
-#undef KEYSYM
-#undef ALLKEYS
-#undef ALLKEYSD
-
-#include "map-values.c"
*/
/** @file map-stat.c
- * @brief Map functions to set and get stats
+ * @brief Map functions to handle statistics.
*/
#include "stat-common.c"
-/* Adds an int64 to a stats map */
-static int _stp_map_add_stat (MAP map, int64_t val)
-{
- stat *d;
-
- if (map == NULL)
- return -2;
-
- if (map->create) {
- struct map_node *m = __stp_map_create (map);
- if (!m)
- return -1;
-
- /* set the value */
- d = (stat *)((long)m + map->data_offset);
- d->count = 0;
- } else {
- if (map->key == NULL)
- return -2;
- d = (stat *)((long)map->key + map->data_offset);
- }
- __stp_stat_add (&map->hist, d, val);
- return 0;
-}
-
static void _stp_map_print_histogram (MAP map, stat *sd)
{
}
return m;
}
+
+static MAP _stp_pmap_new_hstat_linear (unsigned max_entries, int ksize, int start, int stop, int interval)
+{
+ MAP map;
+ int size;
+ int buckets = (stop - start) / interval;
+ if ((stop - start) % interval) buckets++;
+
+ /* add size for buckets */
+ size = buckets * sizeof(int64_t) + sizeof(stat);
+
+ map = _stp_pmap_new (max_entries, STAT, ksize, size);
+ if (map) {
+ int i;
+ MAP m;
+ for_each_cpu(i) {
+ m = per_cpu_ptr (map, i);
+ m->hist.type = HIST_LINEAR;
+ m->hist.start = start;
+ m->hist.stop = stop;
+ m->hist.interval = interval;
+ m->hist.buckets = buckets;
+ }
+ /* now set agg map params */
+ m = _stp_percpu_dptr(map);
+ m->hist.type = HIST_LINEAR;
+ m->hist.start = start;
+ m->hist.stop = stop;
+ m->hist.interval = interval;
+ m->hist.buckets = buckets;
+ }
+ return map;
+}
+
+static MAP _stp_pmap_new_hstat_log (unsigned max_entries, int key_size, int buckets)
+{
+ /* add size for buckets */
+ int size = buckets * sizeof(int64_t) + sizeof(stat);
+ MAP map = _stp_map_new (max_entries, STAT, key_size, size);
+ if (map) {
+ int i;
+ MAP m;
+ for_each_cpu(i) {
+ m = per_cpu_ptr (map, i);
+ m->hist.type = HIST_LOG;
+ m->hist.buckets = buckets;
+ }
+ /* now set agg map params */
+ m = _stp_percpu_dptr(map);
+ m->hist.type = HIST_LOG;
+ m->hist.buckets = buckets;
+ }
+ return map;
+}
+++ /dev/null
-/* -*- linux-c -*-
- * Map String Functions
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-/** @file map-str.c
- * @brief Map functions to set and get strings
- */
-
-/* from map.c */
-void str_copy(char *dest, char *src);
-
-void str_add(void *dest, char *val)
-{
- char *dst = (char *)dest;
- int len = strlen(val);
- int len1 = strlen(dst);
- int num = MAP_STRING_LENGTH - 1 - len1;
-
- if (len > num)
- len = num;
- strncpy (&dst[len1], val, len);
- dst[len + len1] = 0;
-}
-
-int __stp_map_set_str (MAP map, char *val, int add)
-{
- struct map_node *m;
-
- if (map == NULL)
- return -2;
-
- if (map->create) {
- if (val == 0 && !map->list)
- return 0;
-
- m = __stp_map_create (map);
- if (!m)
- return -1;
-
- /* set the value */
- //dbug ("m=%lx offset=%lx\n", (long)m, (long)map->data_offset);
- str_copy((void *)((long)m + map->data_offset), val);
- } else {
- if (map->key == NULL)
- return -2;
-
- if (val) {
- if (add)
- str_add((void *)((long)map->key + map->data_offset), val);
- else
- str_copy((void *)((long)map->key + map->data_offset), val);
- } else if (!add) {
- /* setting value to 0 is the same as deleting */
- _stp_map_key_del(map);
- }
- }
- return 0;
-}
-
-/** Set the current element's value to a string.
- * This sets the current element's value to a string. The map must have been created
- * to hold strings using <i>_stp_map_new(xxx, STRING)</i>
- *
- * If the element doesn't exist, it is created. If no current element (key)
- * is set for the map, this function does nothing.
- * @param map
- * @param str String containing new value.
- * @returns \li \c 0 on success \li \c -1 on overflow \li \c -2 on bad map or key
- * @sa _stp_map_set()
- * @ingroup map_set
- */
-#define _stp_map_set_str(map,val) __stp_map_set_str(map,val,0)
-/** Add to the current element's string value.
- * This sets the current element's value to a string consisting of the old
- * contents followed by the new string. The map must have been created
- * to hold strings using <i>_stp_map_new(xxx, STRING)</i>
- *
- * If the element doesn't exist, it is created. If no current element (key)
- * is set for the map, this function does nothing.
- * @param map
- * @param val String containing value to append.
- * @returns \li \c 0 on success \li \c -1 on overflow \li \c -2 on bad map or key
- * @ingroup map_set
- */
-#define _stp_map_add_str(map,val) __stp_map_set_str(map,val,1)
-
-/** Get the current element's string value.
- * This gets the current element's string value. The map must have been created
- * to hold strings using <i>_stp_map_new(xxx, STRING)</i>
- *
- * If no current element (key) is set for the map, this function
- * returns NULL.
- * @param map
- * @sa _stp_map_set()
- * @ingroup map_set
- */
-char *_stp_map_get_str (MAP map)
-{
- struct map_node *m;
- if (map == NULL || map->create || map->key == NULL)
- return 0;
- //dbug ("key %lx\n", (long)map->key);
- m = (struct map_node *)map->key;
- return (char *)((long)m + map->data_offset);
-}
-
-/** Set the current element's value to String.
- * This sets the current element's value to a String. The map must have been created
- * to hold strings using <i>_stp_map_new(xxx, STRING)</i>
- *
- * If the element doesn't exist, it is created. If no current element (key)
- * is set for the map, this function does nothing.
- * @param map
- * @param str String containing new value.
- * @returns 0 on success, -1 on error.
- * @sa _stp_map_set()
- * @ingroup map_set
- */
-
-void _stp_map_set_string (MAP map, String str)
-{
- __stp_map_set_str (map, str->buf, 0);
-}
-
+++ /dev/null
-/* -*- linux-c -*-
- * Map value functions
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-#ifndef _MAP_VALUES_C_
-#define _MAP_VALUES_C_
-
-/** @file map-values.c
- * @brief Includes the proper value functions for maps.
- */
-
-#include "map.h"
-#include "map-str.c"
-#include "map-stat.c"
-#include "map-int.c"
-
-/** Adds an int64 to the current element's value.
- * This adds an int64 to the current element's value. The map must have been created
- * to hold int64s or stats.
- *
- * If the element doesn't exist, it is created. If no current element (key)
- * is set for the map, this function does nothing.
- * @param map
- * @param val value
- * @returns \li \c 0 on success \li \c -1 on overflow \li \c -2 on bad map or key
- * @ingroup map_set
- */
-int _stp_map_add_int64 (MAP map, int64_t val)
-{
- if (map == NULL)
- return -2;
-
- if (map->type == INT64)
- return __stp_map_set_int64 (map, val, 1);
-
- if (map->type == STAT)
- return _stp_map_add_stat (map, val);
-
- /* shouldn't get here */
- return -2;
-}
-
-unsigned _stp_map_entry_exists (MAP map)
-{
- if (map == NULL || map->create || map->key == NULL)
- return 0;
- return 1;
-}
-
-
-#endif /* _MAP_VALUES_C_ */
-
* @brief Implements maps (associative arrays) and lists
*/
-#include "map-values.c"
+#include "stat-common.c"
+#include "map-stat.c"
#include "alloc.c"
#include "sym.c"
dest[len] = 0;
}
+void str_add(void *dest, char *val)
+{
+ char *dst = (char *)dest;
+ int len = strlen(val);
+ int len1 = strlen(dst);
+ int num = MAP_STRING_LENGTH - 1 - len1;
+
+ if (len > num)
+ len = num;
+ strncpy (&dst[len1], val, len);
+ dst[len + len1] = 0;
+}
+
int str_eq_p (char *key1, char *key2)
{
return strncmp(key1, key2, MAP_STRING_LENGTH - 1) == 0;
return NULL;
}
-static MAP _stp_pmap_new_hstat_linear (unsigned max_entries, int ksize, int start, int stop, int interval)
-{
- MAP map;
- int size;
- int buckets = (stop - start) / interval;
- if ((stop - start) % interval) buckets++;
-
- /* add size for buckets */
- size = buckets * sizeof(int64_t) + sizeof(stat);
-
- map = _stp_pmap_new (max_entries, STAT, ksize, size);
- if (map) {
- int i;
- MAP m;
- for_each_cpu(i) {
- m = per_cpu_ptr (map, i);
- m->hist.type = HIST_LINEAR;
- m->hist.start = start;
- m->hist.stop = stop;
- m->hist.interval = interval;
- m->hist.buckets = buckets;
- }
- /* now set agg map params */
- m = _stp_percpu_dptr(map);
- m->hist.type = HIST_LINEAR;
- m->hist.start = start;
- m->hist.stop = stop;
- m->hist.interval = interval;
- m->hist.buckets = buckets;
- }
- return map;
-}
-
-static MAP _stp_pmap_new_hstat_log (unsigned max_entries, int key_size, int buckets)
-{
- /* add size for buckets */
- int size = buckets * sizeof(int64_t) + sizeof(stat);
- MAP map = _stp_map_new (max_entries, STAT, key_size, size);
- if (map) {
- int i;
- MAP m;
- for_each_cpu(i) {
- m = per_cpu_ptr (map, i);
- m->hist.type = HIST_LOG;
- m->hist.buckets = buckets;
- }
- /* now set agg map params */
- m = _stp_percpu_dptr(map);
- m->hist.type = HIST_LOG;
- m->hist.buckets = buckets;
- }
- return map;
-}
-
-/** Deletes the current element.
- * If no current element (key) for this map is set, this function does nothing.
- * @param map
- */
-
-void _stp_map_key_del(MAP map)
-{
- struct map_node *m;
-
- //dbug("create=%d key=%lx\n", map->create, (long)map->key);
- if (map == NULL)
- return;
-
- if (map->create) {
- map->create = 0;
- map->key = NULL;
- return;
- }
-
- if (map->key == NULL)
- return;
-
- m = (struct map_node *)map->key;
-
- /* remove node from old hash list */
- hlist_del_init(&m->hnode);
-
- /* remove from entry list */
- list_del(&m->lnode);
-
- list_add(&m->lnode, &map->pool);
-
- map->key = NULL;
- map->num--;
-}
/** Get the first element in a map.
* @param map
if (map == NULL)
return;
- map->create = 0;
- map->key = NULL;
map->num = 0;
while (!list_empty(&map->head)) {
}
#define _stp_pmap_print(map,fmt) _stp_pmap_printn(map,0,fmt)
-static struct map_node *__stp_map_create (MAP map)
-{
- struct map_node *m;
- if (list_empty(&map->pool)) {
- if (!map->wrap) {
- /* ERROR. no space left */
- return NULL;
- }
- m = (struct map_node *)map->head.next;
- hlist_del_init(&m->hnode);
- //dbug ("got %lx off head\n", (long)m);
- } else {
- m = (struct map_node *)map->pool.next;
- //dbug ("got %lx off pool\n", (long)m);
- }
- list_move_tail(&m->lnode, &map->head);
-
- /* copy the key(s) */
- (map->copy_keys)(map, m);
-
- /* add node to new hash list */
- hlist_add_head(&m->hnode, map->c_keyhead);
-
- map->key = m;
- map->create = 0;
- map->num++;
- return m;
-}
static void _new_map_clear_node (struct map_node *m)
{
int data_offset;
- /* this is the creation data saved between the key functions and the
- set/get functions */
- u_int8_t create;
- key_data c_key[MAX_KEY_ARITY];
- struct hlist_head *c_keyhead;
-
/* the hash table for this array */
struct hlist_head hashes[HASH_TABLE_SIZE];
static MAP _stp_map_new_hstat_log(unsigned max_entries, int key_size, int buckets);
static MAP _stp_map_new_hstat_linear(unsigned max_entries, int ksize, int start, int stop, int interval);
static void _stp_map_print_histogram(MAP map, stat *s);
-void _stp_map_key_del(MAP map);
struct map_node * _stp_map_start(MAP map);
struct map_node * _stp_map_iter(MAP map, struct map_node *m);
void _stp_map_del(MAP map);
+void _stp_map_clear(MAP map);
void _stp_map_print(MAP map, const char *fmt);
-static struct map_node * __stp_map_create(MAP map);
static struct map_node *_new_map_create (MAP map, struct hlist_head *head);
static int _new_map_set_int64 (MAP map, struct map_node *n, int64_t val, int add);
+2005-11-08 Martin Hunt <hunt@redhat.com>
+
+ * maps/map.test: Remove old map API tests.
+ * maps/ii2.c: Renamed ii.c.
+ * maps/iiss2.c: Renamed iiss.c.
+ * maps/is2.c: Renamed is.c.
+ * maps/issii2.c: Renamed issii.c.
+ * maps/isx2.c: Renamed isx.c.
+ * maps/map_format2.c: Renamed map_format.c.
+ * maps/si2.c: Renamed si.c.
+ * maps/keys.c: Deleted
+ * maps/test_list_int64.c: Deleted.
+ * maps/test_list_string.c: Deleted.
+ * maps/sort.c: Update to use new map API.
+
2005-11-08 Martin Hunt <hunt@redhat.com>
* pmaps/*: Add new pmaps tests.