memstat.h revision 147997
1147997Srwatson/*- 2147997Srwatson * Copyright (c) 2005 Robert N. M. Watson 3147997Srwatson * All rights reserved. 4147997Srwatson * 5147997Srwatson * Redistribution and use in source and binary forms, with or without 6147997Srwatson * modification, are permitted provided that the following conditions 7147997Srwatson * are met: 8147997Srwatson * 1. Redistributions of source code must retain the above copyright 9147997Srwatson * notice, this list of conditions and the following disclaimer. 10147997Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11147997Srwatson * notice, this list of conditions and the following disclaimer in the 12147997Srwatson * documentation and/or other materials provided with the distribution. 13147997Srwatson * 14147997Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15147997Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16147997Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17147997Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18147997Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19147997Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20147997Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21147997Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22147997Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23147997Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24147997Srwatson * SUCH DAMAGE. 25147997Srwatson * 26147997Srwatson * $FreeBSD: head/lib/libmemstat/memstat.h 147997 2005-07-14 17:40:02Z rwatson $ 27147997Srwatson */ 28147997Srwatson 29147997Srwatson#ifndef _MEMSTAT_H_ 30147997Srwatson#define _MEMSTAT_H_ 31147997Srwatson 32147997Srwatson/* 33147997Srwatson * Number of CPU slots in library-internal data structures. This should be 34147997Srwatson * at least the value of MAXCPU from param.h. 35147997Srwatson */ 36147997Srwatson#define MEMSTAT_MAXCPU 16 37147997Srwatson 38147997Srwatson/* 39147997Srwatson * libmemstat(3) is able to extract memory data from different allocators; 40147997Srwatson * when it does so, it tags which allocator it got the data from so that 41147997Srwatson * consumers can determine which fields are usable, as data returned varies 42147997Srwatson * some. 43147997Srwatson */ 44147997Srwatson#define ALLOCATOR_UNKNOWN 0 45147997Srwatson#define ALLOCATOR_MALLOC 1 46147997Srwatson#define ALLOCATOR_UMA 2 47147997Srwatson#define ALLOCATOR_ANY 255 48147997Srwatson 49147997Srwatson/* 50147997Srwatson * Library maximum type name. Should be max(set of name maximums over 51147997Srwatson * various allocators). 52147997Srwatson */ 53147997Srwatson#define MEMTYPE_MAXNAME 32 54147997Srwatson 55147997Srwatson/* 56147997Srwatson * Forward declare struct memory_type, which holds per-type properties and 57147997Srwatson * statistics. This is an opaque type, to be frobbed only from within the 58147997Srwatson * library, in order to avoid building ABI assumptions into the application. 59147997Srwatson * Accessor methods should be used to get and sometimes set the fields from 60147997Srwatson * consumers of the library. 61147997Srwatson */ 62147997Srwatsonstruct memory_type; 63147997Srwatson 64147997Srwatson/* 65147997Srwatson * struct memory_type_list is the head of a list of memory types and 66147997Srwatson * statistics. 67147997Srwatson */ 68147997Srwatsonstruct memory_type_list; 69147997Srwatson 70147997Srwatson/* 71147997Srwatson * Functions for managing memory type and statistics data. 72147997Srwatson */ 73147997Srwatsonstruct memory_type_list *memstat_mtl_alloc(void); 74147997Srwatsonstruct memory_type *memstat_mtl_first(struct memory_type_list *list); 75147997Srwatsonstruct memory_type *memstat_mtl_next(struct memory_type *mtp); 76147997Srwatsonstruct memory_type *memstat_mtl_find(struct memory_type_list *list, 77147997Srwatson int allocator, const char *name); 78147997Srwatsonvoid memstat_mtl_free(struct memory_type_list *list); 79147997Srwatson 80147997Srwatson/* 81147997Srwatson * Functions to retrieve data from a live kernel using sysctl. 82147997Srwatson */ 83147997Srwatsonint memstat_sysctl_all(struct memory_type_list *list, int flags); 84147997Srwatsonint memstat_sysctl_malloc(struct memory_type_list *list, int flags); 85147997Srwatsonint memstat_sysctl_uma(struct memory_type_list *list, int flags); 86147997Srwatson 87147997Srwatson/* 88147997Srwatson * Accessor methods for struct memory_type_list. 89147997Srwatson */ 90147997Srwatsonconst char *memstat_get_name(const struct memory_type *mtp); 91147997Srwatsonint memstat_get_allocator(const struct memory_type *mtp); 92147997Srwatsonuint64_t memstat_get_countlimit(const struct memory_type *mtp); 93147997Srwatsonuint64_t memstat_get_byteslimit(const struct memory_type *mtp); 94147997Srwatsonuint64_t memstat_get_sizemask(const struct memory_type *mtp); 95147997Srwatsonuint64_t memstat_get_size(const struct memory_type *mtp); 96147997Srwatsonuint64_t memstat_get_memalloced(const struct memory_type *mtp); 97147997Srwatsonuint64_t memstat_get_memfreed(const struct memory_type *mtp); 98147997Srwatsonuint64_t memstat_get_numallocs(const struct memory_type *mtp); 99147997Srwatsonuint64_t memstat_get_numfrees(const struct memory_type *mtp); 100147997Srwatsonuint64_t memstat_get_bytes(const struct memory_type *mtp); 101147997Srwatsonuint64_t memstat_get_count(const struct memory_type *mtp); 102147997Srwatsonuint64_t memstat_get_free(const struct memory_type *mtp); 103147997Srwatsonuint64_t memstat_get_failures(const struct memory_type *mtp); 104147997Srwatsonvoid *memstat_get_caller_pointer(const struct memory_type *mtp, 105147997Srwatson int index); 106147997Srwatsonvoid memstat_set_caller_pointer(struct memory_type *mtp, 107147997Srwatson int index, void *value); 108147997Srwatsonuint64_t memstat_get_caller_uint64(const struct memory_type *mtp, 109147997Srwatson int index); 110147997Srwatsonvoid memstat_set_caller_uint64(struct memory_type *mtp, int index, 111147997Srwatson uint64_t value); 112147997Srwatsonuint64_t memstat_get_zonefree(const struct memory_type *mtp); 113147997Srwatsonuint64_t memstat_get_percpu_memalloced(const struct memory_type *mtp, 114147997Srwatson int cpu); 115147997Srwatsonuint64_t memstat_get_percpu_memfreed(const struct memory_type *mtp, 116147997Srwatson int cpu); 117147997Srwatsonuint64_t memstat_get_percpu_numallocs(const struct memory_type *mtp, 118147997Srwatson int cpu); 119147997Srwatsonuint64_t memstat_get_percpu_numfrees(const struct memory_type *mtp, 120147997Srwatson int cpu); 121147997Srwatsonuint64_t memstat_get_percpu_sizemask(const struct memory_type *mtp, 122147997Srwatson int cpu); 123147997Srwatsonvoid *memstat_get_percpu_caller_pointer( 124147997Srwatson const struct memory_type *mtp, int cpu, int index); 125147997Srwatsonvoid memstat_set_percpu_caller_pointer(struct memory_type *mtp, 126147997Srwatson int cpu, int index, void *value); 127147997Srwatsonuint64_t memstat_get_percpu_caller_uint64( 128147997Srwatson const struct memory_type *mtp, int cpu, int index); 129147997Srwatsonvoid memstat_set_percpu_caller_uint64(struct memory_type *mtp, 130147997Srwatson int cpu, int index, uint64_t value); 131147997Srwatsonuint64_t memstat_get_percpu_free(const struct memory_type *mtp, 132147997Srwatson int cpu); 133147997Srwatson 134147997Srwatson#endif /* !_MEMSTAT_H_ */ 135