diff options
author | hunt <hunt> | 2005-11-09 22:04:05 +0000 |
---|---|---|
committer | hunt <hunt> | 2005-11-09 22:04:05 +0000 |
commit | 9262e8147c5b217b177713cdf197990a09136c1f (patch) | |
tree | 41f28eb110d91aebe1ac445915a990e62c3d51db /runtime | |
parent | bf46c40280548795f68031a937c56b422f3fdf35 (diff) | |
download | systemtap-steved-9262e8147c5b217b177713cdf197990a09136c1f.tar.gz systemtap-steved-9262e8147c5b217b177713cdf197990a09136c1f.tar.xz systemtap-steved-9262e8147c5b217b177713cdf197990a09136c1f.zip |
2005-11-09 Martin Hunt <hunt@redhat.com>
* map.c (_stp_cmp): Patch to sort on stats.
(_stp_map_sort): Ditto.
(_stp_map_sortn): Ditto.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/ChangeLog | 7 | ||||
-rw-r--r-- | runtime/map.c | 45 |
2 files changed, 48 insertions, 4 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog index dc21fffd..d98ce50e 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,6 +1,11 @@ 2005-11-09 Martin Hunt <hunt@redhat.com> - * map.c: Change order of includes. + * map.c (_stp_cmp): Patch to sort on stats. + (_stp_map_sort): Ditto. + (_stp_map_sortn): Ditto. +2005-11-09 Martin Hunt <hunt@redhat.com> + * map.c: Change order of includes. + 2005-11-09 Martin Hunt <hunt@redhat.com> * map.h (struct map_root): Delete fields used by old API. diff --git a/runtime/map.c b/runtime/map.c index e4cb0dde..bbcd144a 100644 --- a/runtime/map.c +++ b/runtime/map.c @@ -381,6 +381,13 @@ void _stp_pmap_del(MAP map) free_percpu(map); } +/* sort keynum values */ +#define SORT_COUNT -5 +#define SORT_SUM -4 +#define SORT_MIN -3 +#define SORT_MAX -2 +#define SORT_AVG -1 + /* comparison function for sorts. */ static int _stp_cmp (struct list_head *a, struct list_head *b, int keynum, int dir, int type) { @@ -400,9 +407,37 @@ static int _stp_cmp (struct list_head *a, struct list_head *b, int keynum, int d return ret; } else { int64_t a,b; - if (keynum) { + if (keynum > 0) { a = _stp_key_get_int64(m1, keynum); b = _stp_key_get_int64(m2, keynum); + } else if (keynum < 0) { + stat *sd1 = (stat *)((long)m1 + m1->map->data_offset); + stat *sd2 = (stat *)((long)m2 + m2->map->data_offset); + switch (keynum) { + case SORT_COUNT: + a = sd1->count; + b = sd2->count; + break; + case SORT_SUM: + a = sd1->sum; + b = sd2->sum; + break; + case SORT_MIN: + a = sd1->min; + b = sd2->min; + break; + case SORT_MAX: + a = sd1->max; + b = sd2->max; + break; + case SORT_AVG: + a = sd1->sum / sd1->count; + b = sd2->sum / sd2->count; + break; + default: + /* should never happen */ + a = b = 0; + } } else { a = _stp_get_int64(m1); b = _stp_get_int64(m2); @@ -443,8 +478,10 @@ void _stp_map_sort (MAP map, int keynum, int dir) if (list_empty(head)) return; - if (keynum) + if (keynum > 0) (*map->get_key)((struct map_node *)head->next, keynum, &type); + else if (keynum < 0) + type = INT64; else type = ((struct map_node *)head->next)->map->type; @@ -511,8 +548,10 @@ void _stp_map_sortn(MAP map, int n, int keynum, int dir) if (list_empty(head)) return; - if (keynum) + if (keynum > 0) (*map->get_key)((struct map_node *)head->next, keynum, &type); + else if (keynum < 0) + type = INT64; else type = ((struct map_node *)head->next)->map->type; |