Deleted Added
full compact
memstat.c (148354) memstat.c (148357)
1/*-
2 * Copyright (c) 2005 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2005 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libmemstat/memstat.c 148354 2005-07-23 21:17:15Z rwatson $
26 * $FreeBSD: head/lib/libmemstat/memstat.c 148357 2005-07-24 01:28:54Z rwatson $
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31
32#include <err.h>
33#include <errno.h>
34#include <stdio.h>

--- 7 unchanged lines hidden (view full) ---

42memstat_mtl_alloc(void)
43{
44 struct memory_type_list *mtlp;
45
46 mtlp = malloc(sizeof(*mtlp));
47 if (mtlp == NULL)
48 return (NULL);
49
27 */
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31
32#include <err.h>
33#include <errno.h>
34#include <stdio.h>

--- 7 unchanged lines hidden (view full) ---

42memstat_mtl_alloc(void)
43{
44 struct memory_type_list *mtlp;
45
46 mtlp = malloc(sizeof(*mtlp));
47 if (mtlp == NULL)
48 return (NULL);
49
50 LIST_INIT(mtlp);
50 LIST_INIT(&mtlp->mtl_list);
51 mtlp->mtl_error = MEMSTAT_ERROR_UNDEFINED;
51 return (mtlp);
52}
53
54struct memory_type *
55memstat_mtl_first(struct memory_type_list *list)
56{
57
52 return (mtlp);
53}
54
55struct memory_type *
56memstat_mtl_first(struct memory_type_list *list)
57{
58
58 return (LIST_FIRST(list));
59 return (LIST_FIRST(&list->mtl_list));
59}
60
61struct memory_type *
62memstat_mtl_next(struct memory_type *mtp)
63{
64
65 return (LIST_NEXT(mtp, mt_list));
66}
67
68void
69memstat_mtl_free(struct memory_type_list *list)
70{
71 struct memory_type *mtp;
72
60}
61
62struct memory_type *
63memstat_mtl_next(struct memory_type *mtp)
64{
65
66 return (LIST_NEXT(mtp, mt_list));
67}
68
69void
70memstat_mtl_free(struct memory_type_list *list)
71{
72 struct memory_type *mtp;
73
73 while ((mtp = LIST_FIRST(list))) {
74 while ((mtp = LIST_FIRST(&list->mtl_list))) {
74 LIST_REMOVE(mtp, mt_list);
75 free(mtp);
76 }
77 free(list);
78}
79
75 LIST_REMOVE(mtp, mt_list);
76 free(mtp);
77 }
78 free(list);
79}
80
81int
82memstat_mtl_geterror(struct memory_type_list *list)
83{
84
85 return (list->mtl_error);
86}
87
80/*
81 * Look for an existing memory_type entry in a memory_type list, based on the
88/*
89 * Look for an existing memory_type entry in a memory_type list, based on the
82 * allocator and name of the type. If not found, return NULL. O(n).
90 * allocator and name of the type. If not found, return NULL. No errno or
91 * memstat error.
83 */
84struct memory_type *
85memstat_mtl_find(struct memory_type_list *list, int allocator,
86 const char *name)
87{
88 struct memory_type *mtp;
89
92 */
93struct memory_type *
94memstat_mtl_find(struct memory_type_list *list, int allocator,
95 const char *name)
96{
97 struct memory_type *mtp;
98
90 LIST_FOREACH(mtp, list, mt_list) {
99 LIST_FOREACH(mtp, &list->mtl_list, mt_list) {
91 if ((mtp->mt_allocator == allocator ||
92 allocator == ALLOCATOR_ANY) &&
93 strcmp(mtp->mt_name, name) == 0)
94 return (mtp);
95 }
96 return (NULL);
97}
98

--- 12 unchanged lines hidden (view full) ---

111 mtp = malloc(sizeof(*mtp));
112 if (mtp == NULL)
113 return (NULL);
114
115 bzero(mtp, sizeof(*mtp));
116
117 mtp->mt_allocator = allocator;
118 strlcpy(mtp->mt_name, name, MEMTYPE_MAXNAME);
100 if ((mtp->mt_allocator == allocator ||
101 allocator == ALLOCATOR_ANY) &&
102 strcmp(mtp->mt_name, name) == 0)
103 return (mtp);
104 }
105 return (NULL);
106}
107

--- 12 unchanged lines hidden (view full) ---

120 mtp = malloc(sizeof(*mtp));
121 if (mtp == NULL)
122 return (NULL);
123
124 bzero(mtp, sizeof(*mtp));
125
126 mtp->mt_allocator = allocator;
127 strlcpy(mtp->mt_name, name, MEMTYPE_MAXNAME);
119 LIST_INSERT_HEAD(list, mtp, mt_list);
128 LIST_INSERT_HEAD(&list->mtl_list, mtp, mt_list);
120 return (mtp);
121}
122
123/*
124 * Reset any libmemstat(3)-owned statistics in a memory_type record so that
125 * it can be reused without incremental addition problems. Caller-owned
126 * memory is left "as-is", and must be updated by the caller if desired.
127 *

--- 251 unchanged lines hidden ---
129 return (mtp);
130}
131
132/*
133 * Reset any libmemstat(3)-owned statistics in a memory_type record so that
134 * it can be reused without incremental addition problems. Caller-owned
135 * memory is left "as-is", and must be updated by the caller if desired.
136 *

--- 251 unchanged lines hidden ---