1 /* 2 * Copyright (c) 2015 Sippy Software, Inc., http://www.sippysoft.com 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 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 */ 27 28 #ifndef RTPP_MEMDEB_STDOUT 29 # define RTPP_MEMDEB_REPORT(handle, format, args...) \ 30 if (handle != NULL) { \ 31 RTPP_LOG(((struct rtpp_log *)handle), RTPP_LOG_DBUG, format, ## args); \ 32 } 33 #else 34 # define RTPP_MEMDEB_REPORT2(handle, nostdout, format, args...) { \ 35 if (!nostdout) { \ 36 printf((format "\n"), ## args); \ 37 fflush(stdout); \ 38 }; \ 39 if (handle != NULL) { \ 40 RTPP_LOG(((struct rtpp_log *)handle), RTPP_LOG_DBUG, format, ## args); \ 41 } \ 42 } 43 # define RTPP_MEMDEB_REPORT(handle, format, args...) \ 44 RTPP_MEMDEB_REPORT2(handle, 0, format, ## args) 45 #endif 46 47 #define RTPP_MEMDEB_STATIC(appname) void *_##appname##_memdeb 48 49 #define RTPP_MEMDEB_INIT(appname) { \ 50 _##appname##_memdeb = rtpp_memdeb_init(); \ 51 assert(_##appname##_memdeb != NULL); \ 52 } 53 54 #define RTPP_MEMDEB_FIN(appname) { \ 55 assert(_##appname##_memdeb != NULL); \ 56 rtpp_memdeb_dtor(_##appname##_memdeb); \ 57 _##appname##_memdeb = NULL; \ 58 } 59 60 struct rtpp_log; 61 62 int rtpp_memdeb_dumpstats(void *, int); 63 void rtpp_memdeb_setbaseln(void *); 64 int rtpp_memdeb_selftest(void *); 65 void rtpp_memdeb_setlog(void *, struct rtpp_log *); 66 void rtpp_memdeb_approve(void *, const char *, int, const char *); 67 68 void *rtpp_memdeb_init(); 69 void rtpp_memdeb_dtor(void *); 70