xref: /freebsd/lib/libmemstat/memstat_all.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
10cddce49SRobert Watson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
40cddce49SRobert Watson  * Copyright (c) 2005 Robert N. M. Watson
50cddce49SRobert Watson  * All rights reserved.
60cddce49SRobert Watson  *
70cddce49SRobert Watson  * Redistribution and use in source and binary forms, with or without
80cddce49SRobert Watson  * modification, are permitted provided that the following conditions
90cddce49SRobert Watson  * are met:
100cddce49SRobert Watson  * 1. Redistributions of source code must retain the above copyright
110cddce49SRobert Watson  *    notice, this list of conditions and the following disclaimer.
120cddce49SRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
130cddce49SRobert Watson  *    notice, this list of conditions and the following disclaimer in the
140cddce49SRobert Watson  *    documentation and/or other materials provided with the distribution.
150cddce49SRobert Watson  *
160cddce49SRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170cddce49SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180cddce49SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190cddce49SRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200cddce49SRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210cddce49SRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220cddce49SRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230cddce49SRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240cddce49SRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250cddce49SRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260cddce49SRobert Watson  * SUCH DAMAGE.
270cddce49SRobert Watson  */
280cddce49SRobert Watson 
290cddce49SRobert Watson #include <sys/types.h>
300cddce49SRobert Watson #include <sys/queue.h>
310cddce49SRobert Watson 
320cddce49SRobert Watson #include "memstat.h"
330cddce49SRobert Watson 
340cddce49SRobert Watson /*
350cddce49SRobert Watson  * Query all available memory allocator sources.  Currently this consists of
360cddce49SRobert Watson  * malloc(9) and UMA(9).
370cddce49SRobert Watson  */
380cddce49SRobert Watson int
memstat_sysctl_all(struct memory_type_list * mtlp,int flags)390cddce49SRobert Watson memstat_sysctl_all(struct memory_type_list *mtlp, int flags)
400cddce49SRobert Watson {
410cddce49SRobert Watson 
420cddce49SRobert Watson 	if (memstat_sysctl_malloc(mtlp, flags) < 0)
430cddce49SRobert Watson 		return (-1);
440cddce49SRobert Watson 	if (memstat_sysctl_uma(mtlp, flags) < 0)
450cddce49SRobert Watson 		return (-1);
460cddce49SRobert Watson 	return (0);
470cddce49SRobert Watson }
4833c20d18SRobert Watson 
4933c20d18SRobert Watson int
memstat_kvm_all(struct memory_type_list * mtlp,void * kvm_handle)5033c20d18SRobert Watson memstat_kvm_all(struct memory_type_list *mtlp, void *kvm_handle)
5133c20d18SRobert Watson {
5233c20d18SRobert Watson 
5333c20d18SRobert Watson 	if (memstat_kvm_malloc(mtlp, kvm_handle) < 0)
5433c20d18SRobert Watson 		return (-1);
5533c20d18SRobert Watson 	if (memstat_kvm_uma(mtlp, kvm_handle) < 0)
5633c20d18SRobert Watson 		return (-1);
5733c20d18SRobert Watson 	return (0);
5833c20d18SRobert Watson }
59