memstat.h revision 148170
1172302Spjd/*- 2172302Spjd * Copyright (c) 2005 Robert N. M. Watson 3172302Spjd * All rights reserved. 4172302Spjd * 5172302Spjd * Redistribution and use in source and binary forms, with or without 6172302Spjd * modification, are permitted provided that the following conditions 7172302Spjd * are met: 8172302Spjd * 1. Redistributions of source code must retain the above copyright 9172302Spjd * notice, this list of conditions and the following disclaimer. 10172302Spjd * 2. Redistributions in binary form must reproduce the above copyright 11172302Spjd * notice, this list of conditions and the following disclaimer in the 12172302Spjd * documentation and/or other materials provided with the distribution. 13172302Spjd * 14172302Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15172302Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16172302Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17172302Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18172302Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19172302Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20172302Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21172302Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22172302Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23172302Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24172302Spjd * SUCH DAMAGE. 25172302Spjd * 26172302Spjd * $FreeBSD: head/lib/libmemstat/memstat.h 148170 2005-07-20 09:17:40Z rwatson $ 27172302Spjd */ 28172302Spjd 29172302Spjd#ifndef _MEMSTAT_H_ 30172302Spjd#define _MEMSTAT_H_ 31172302Spjd 32172302Spjd/* 33172302Spjd * Number of CPU slots in library-internal data structures. This should be 34172302Spjd * at least the value of MAXCPU from param.h. 35172302Spjd */ 36172302Spjd#define MEMSTAT_MAXCPU 16 37172302Spjd 38172302Spjd/* 39172302Spjd * Amount of caller data to maintain for each caller data slot. Applications 40172302Spjd * must not request more than this number of caller save data, or risk 41172302Spjd * corrupting internal libmemstat(3) data structures. A compile time check 42172302Spjd * in the application is probably appropriate. 43172302Spjd */ 44172302Spjd#define MEMSTAT_MAXCALLER 16 45172302Spjd 46172302Spjd/* 47172302Spjd * libmemstat(3) is able to extract memory data from different allocators; 48172302Spjd * when it does so, it tags which allocator it got the data from so that 49172302Spjd * consumers can determine which fields are usable, as data returned varies 50172302Spjd * some. 51172302Spjd */ 52172302Spjd#define ALLOCATOR_UNKNOWN 0 53172302Spjd#define ALLOCATOR_MALLOC 1 54172302Spjd#define ALLOCATOR_UMA 2 55172302Spjd#define ALLOCATOR_ANY 255 56172302Spjd 57172302Spjd/* 58172302Spjd * Library maximum type name. Should be max(set of name maximums over 59172302Spjd * various allocators). 60172302Spjd */ 61172302Spjd#define MEMTYPE_MAXNAME 32 62172302Spjd 63172302Spjd/* 64172302Spjd * Forward declare struct memory_type, which holds per-type properties and 65172302Spjd * statistics. This is an opaque type, to be frobbed only from within the 66172302Spjd * library, in order to avoid building ABI assumptions into the application. 67172302Spjd * Accessor methods should be used to get and sometimes set the fields from 68172302Spjd * consumers of the library. 69172302Spjd */ 70172302Spjdstruct memory_type; 71172302Spjd 72172302Spjd/* 73172302Spjd * struct memory_type_list is the head of a list of memory types and 74172302Spjd * statistics. 75172302Spjd */ 76172302Spjdstruct memory_type_list; 77172302Spjd 78172302Spjd__BEGIN_DECLS 79172302Spjd/* 80172302Spjd * Functions for managing memory type and statistics data. 81172302Spjd */ 82172302Spjdstruct memory_type_list *memstat_mtl_alloc(void); 83172302Spjdstruct memory_type *memstat_mtl_first(struct memory_type_list *list); 84172302Spjdstruct memory_type *memstat_mtl_next(struct memory_type *mtp); 85172302Spjdstruct memory_type *memstat_mtl_find(struct memory_type_list *list, 86172302Spjd int allocator, const char *name); 87172302Spjdvoid memstat_mtl_free(struct memory_type_list *list); 88172302Spjd 89172302Spjd/* 90172302Spjd * Functions to retrieve data from a live kernel using sysctl. 91172302Spjd */ 92int memstat_sysctl_all(struct memory_type_list *list, int flags); 93int memstat_sysctl_malloc(struct memory_type_list *list, int flags); 94int memstat_sysctl_uma(struct memory_type_list *list, int flags); 95 96/* 97 * Accessor methods for struct memory_type_list. 98 */ 99const char *memstat_get_name(const struct memory_type *mtp); 100int memstat_get_allocator(const struct memory_type *mtp); 101uint64_t memstat_get_countlimit(const struct memory_type *mtp); 102uint64_t memstat_get_byteslimit(const struct memory_type *mtp); 103uint64_t memstat_get_sizemask(const struct memory_type *mtp); 104uint64_t memstat_get_size(const struct memory_type *mtp); 105uint64_t memstat_get_memalloced(const struct memory_type *mtp); 106uint64_t memstat_get_memfreed(const struct memory_type *mtp); 107uint64_t memstat_get_numallocs(const struct memory_type *mtp); 108uint64_t memstat_get_numfrees(const struct memory_type *mtp); 109uint64_t memstat_get_bytes(const struct memory_type *mtp); 110uint64_t memstat_get_count(const struct memory_type *mtp); 111uint64_t memstat_get_free(const struct memory_type *mtp); 112uint64_t memstat_get_failures(const struct memory_type *mtp); 113void *memstat_get_caller_pointer(const struct memory_type *mtp, 114 int index); 115void memstat_set_caller_pointer(struct memory_type *mtp, 116 int index, void *value); 117uint64_t memstat_get_caller_uint64(const struct memory_type *mtp, 118 int index); 119void memstat_set_caller_uint64(struct memory_type *mtp, int index, 120 uint64_t value); 121uint64_t memstat_get_zonefree(const struct memory_type *mtp); 122uint64_t memstat_get_kegfree(const struct memory_type *mtp); 123uint64_t memstat_get_percpu_memalloced(const struct memory_type *mtp, 124 int cpu); 125uint64_t memstat_get_percpu_memfreed(const struct memory_type *mtp, 126 int cpu); 127uint64_t memstat_get_percpu_numallocs(const struct memory_type *mtp, 128 int cpu); 129uint64_t memstat_get_percpu_numfrees(const struct memory_type *mtp, 130 int cpu); 131uint64_t memstat_get_percpu_sizemask(const struct memory_type *mtp, 132 int cpu); 133void *memstat_get_percpu_caller_pointer( 134 const struct memory_type *mtp, int cpu, int index); 135void memstat_set_percpu_caller_pointer(struct memory_type *mtp, 136 int cpu, int index, void *value); 137uint64_t memstat_get_percpu_caller_uint64( 138 const struct memory_type *mtp, int cpu, int index); 139void memstat_set_percpu_caller_uint64(struct memory_type *mtp, 140 int cpu, int index, uint64_t value); 141uint64_t memstat_get_percpu_free(const struct memory_type *mtp, 142 int cpu); 143__END_DECLS 144 145#endif /* !_MEMSTAT_H_ */ 146