2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 typedef struct _PinStatAddress PinStatAddress;
32 struct _PinStatAddress {
36 PinStatAddress *right;
39 static PinStatAddress *pin_stat_addresses = NULL;
40 static size_t pinned_byte_counts [PIN_TYPE_MAX];
43 pin_stats_tree_free (PinStatAddress *node)
47 pin_stats_tree_free (node->left);
48 pin_stats_tree_free (node->right);
49 free_internal_mem (node, INTERNAL_MEM_STATISTICS);
53 pin_stats_reset (void)
56 pin_stats_tree_free (pin_stat_addresses);
57 pin_stat_addresses = NULL;
58 for (i = 0; i < PIN_TYPE_MAX; ++i)
59 pinned_byte_counts [i] = 0;
63 pin_stats_register_address (char *addr, int pin_type)
65 PinStatAddress **node_ptr = &pin_stat_addresses;
67 int pin_type_bit = 1 << pin_type;
71 if (addr == node->addr) {
72 node->pin_types |= pin_type_bit;
75 if (addr < node->addr)
76 node_ptr = &node->left;
78 node_ptr = &node->right;
81 node = get_internal_mem (sizeof (PinStatAddress), INTERNAL_MEM_STATISTICS);
83 node->pin_types = pin_type_bit;
84 node->left = node->right = NULL;
90 pin_stats_count_object_from_tree (char *obj, size_t size, PinStatAddress *node, int *pin_types)
94 if (node->addr >= obj && node->addr < obj + size) {
96 for (i = 0; i < PIN_TYPE_MAX; ++i) {
98 if (!(*pin_types & pin_bit) && (node->pin_types & pin_bit)) {
99 pinned_byte_counts [i] += size;
100 *pin_types |= pin_bit;
104 if (obj < node->addr)
105 pin_stats_count_object_from_tree (obj, size, node->left, pin_types);
106 if (obj + size - 1 > node->addr)
107 pin_stats_count_object_from_tree (obj, size, node->right, pin_types);
111 pin_stats_register_object (char *obj, size_t size)
114 pin_stats_count_object_from_tree (obj, size, pin_stat_addresses, &pin_types);