diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-04 21:52:35 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-04 21:53:18 +0000 |
commit | 35d73836839aec93055dade30e8230360ecf9614 (patch) | |
tree | 6a3fcd9d7f6572ceba5479b8936b4ab8807b3d5d /src/allocators-store.c | |
parent | 1d0fdedad0c98864354edbeeb70b0de6cba7e71e (diff) |
Support reordering the summary views.
Diffstat (limited to 'src/allocators-store.c')
-rw-r--r-- | src/allocators-store.c | 97 |
1 files changed, 87 insertions, 10 deletions
diff --git a/src/allocators-store.c b/src/allocators-store.c index dd730c5..1c47ac8 100644 --- a/src/allocators-store.c +++ b/src/allocators-store.c @@ -25,6 +25,7 @@ struct _allocators_store { GObject object; + AllocatorsStoreSort sort; GCompareFunc sum_allocators_cmp; GPtrArray *allocators; struct { @@ -82,24 +83,57 @@ _sum_allocators_cmp_by_size (gconstpointer A, gconstpointer B) { const struct _sum_allocator * const *aa = A, * const *bb = B; const struct _sum_allocator *a = *aa, *b = *bb; - gint cmp; if (b->size == 0) return 1; if (a->size == 0) return -1; - cmp = b->size - a->size; - if (cmp) - return cmp; + /* beware integer overflow! */ + if (b->size > a->size) + return 1; + else if (b->size < a->size) + return -1; - cmp = b->count - a->count; - if (cmp) - return cmp; + if (b->count > a->count) + return 1; + else if (b->count < a->count) + return -1; - cmp = b->n_pages - a->n_pages; - if (cmp) - return cmp; + if (b->n_pages > a->n_pages) + return 1; + else if (b->n_pages < a->n_pages) + return -1; + + return b->n_pages * 4096 / b->size * b->count - a->n_pages * 4096 / a->size * a->count; +} + +static gint +_sum_allocators_cmp_by_count (gconstpointer A, gconstpointer B) +{ + const struct _sum_allocator * const *aa = A, * const *bb = B; + const struct _sum_allocator *a = *aa, *b = *bb; + + if (b->size == 0) + return 1; + if (a->size == 0) + return -1; + + /* beware integer overflow! */ + if (b->count > a->count) + return 1; + else if (b->count < a->count) + return -1; + + if (b->n_pages > a->n_pages) + return 1; + else if (b->n_pages < a->n_pages) + return -1; + + if (b->size > a->size) + return 1; + else if (b->size < a->size) + return -1; return b->n_pages * 4096 / b->size * b->count - a->n_pages * 4096 / a->size * a->count; } @@ -309,6 +343,7 @@ allocators_store_init (AllocatorsStore *self) { self->allocators = g_ptr_array_new (); self->sum_allocators_cmp = _sum_allocators_cmp_by_size; + self->sort = ALLOCATORS_STORE_SORT_BY_SIZE; self->ht.size = g_spaced_primes_closest (40000); /* XXX */ self->ht.nodes = g_new0 (struct _sum_allocator *, self->ht.size); @@ -321,9 +356,44 @@ allocators_store_new (void) } void +allocators_store_set_sort (AllocatorsStore *store, AllocatorsStoreSort sort) +{ + switch (sort) { + case ALLOCATORS_STORE_SORT_BY_SIZE: + if (store->sort == ALLOCATORS_STORE_SORT_BY_SIZE) + return; + + store->sum_allocators_cmp = _sum_allocators_cmp_by_size; + break; + + case ALLOCATORS_STORE_SORT_BY_COUNT: + if (store->sort == ALLOCATORS_STORE_SORT_BY_COUNT) + return; + + store->sum_allocators_cmp = _sum_allocators_cmp_by_count; + break; + + case ALLOCATORS_STORE_SORT_OTHER: + default: + g_return_if_reached (); + } + + store->sort = sort; + allocators_store_update (store); +} + +AllocatorsStoreSort +allocators_store_get_sort (AllocatorsStore *store) +{ + return store->sort; +} + +void allocators_store_set_cmp (AllocatorsStore *store, GCompareFunc cmp) { + store->sort = ALLOCATORS_STORE_SORT_OTHER; store->sum_allocators_cmp = cmp; + allocators_store_update (store); } struct _sum_allocator * @@ -366,6 +436,7 @@ allocators_store_new_sum (AllocatorsStore *store, const gchar *fn) sum->max = 0; sum->sorted = FALSE; sum->blocks = NULL; + sum->largest = NULL; sum->frame = fn; @@ -391,6 +462,8 @@ allocators_store_reset_sums (AllocatorsStore *store) sum->min = (gulong) -1; sum->max = 0; sum->sorted = FALSE; + + sum->largest = NULL; } } @@ -486,6 +559,10 @@ allocators_store_update_from_allocators (AllocatorsStore *store, if (sum == NULL) sum = allocators_store_new_sum (store, A->alloc_fn); + if (sum->largest == NULL || + A->time_tail->bytes > sum->largest->time_tail->bytes) + sum->largest = A; + sum->size += A->time_tail->bytes; sum->count += A->time_tail->n_allocs; } |