Annotation of embedaddon/strongswan/src/libstrongswan/utils/leak_detective.h, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2008 Martin Willi
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: /**
! 17: * @defgroup leak_detective leak_detective
! 18: * @{ @ingroup utils
! 19: */
! 20:
! 21: #ifndef LEAK_DETECTIVE_H_
! 22: #define LEAK_DETECTIVE_H_
! 23:
! 24: typedef struct leak_detective_t leak_detective_t;
! 25:
! 26: #include <library.h>
! 27: #include <utils/backtrace.h>
! 28:
! 29: /**
! 30: * Callback function to report leak/usage information
! 31: *
! 32: * @param user user specific data
! 33: * @param count number of allocations
! 34: * @param bytes total size of allocations
! 35: * @param bt backtrace of allocation
! 36: * @param detailed TRUE to show a detailed backtrace
! 37: */
! 38: typedef void (*leak_detective_report_cb_t)(void *user, int count, size_t bytes,
! 39: backtrace_t *bt, bool detailed);
! 40:
! 41: /**
! 42: * Callback function to report leak/usage summary information
! 43: *
! 44: * @param user user specific data
! 45: * @param count total number of allocations
! 46: * @param bytes total size of all reported allocations
! 47: * @param whitelisted number of allocations suppressed by whitelist
! 48: */
! 49: typedef void (*leak_detective_summary_cb_t)(void* user, int count, size_t bytes,
! 50: int whitelisted);
! 51:
! 52: /**
! 53: * Leak detective finds leaks and invalid frees using malloc hooks.
! 54: *
! 55: * @todo Build an API for leak detective, allowing leak enumeration, statistics
! 56: * and dynamic whitelisting.
! 57: */
! 58: struct leak_detective_t {
! 59:
! 60: /**
! 61: * Report leaks to the registered callback functions.
! 62: *
! 63: * @param detailed TRUE to resolve line/filename of leaks (slow)
! 64: */
! 65: void (*report)(leak_detective_t *this, bool detailed);
! 66:
! 67: /**
! 68: * Set callback functions invoked when report() is called.
! 69: *
! 70: * @param cb callback invoked for each detected leak
! 71: * @param scb summary callback invoked at end of report
! 72: * @param user user data to supply to callbacks
! 73: */
! 74: void (*set_report_cb)(leak_detective_t *this, leak_detective_report_cb_t cb,
! 75: leak_detective_summary_cb_t scb, void *user);
! 76:
! 77: /**
! 78: * Report current memory usage using callback functions.
! 79: *
! 80: * @param cb callback invoked for each allocation
! 81: * @param scb summary callback invoked at end of usage report
! 82: * @param user user data to supply to callbacks
! 83: */
! 84: void (*usage)(leak_detective_t *this, leak_detective_report_cb_t cb,
! 85: leak_detective_summary_cb_t scb, void *user);
! 86:
! 87: /**
! 88: * Number of detected leaks.
! 89: *
! 90: * @return number of leaks
! 91: */
! 92: int (*leaks)(leak_detective_t *this);
! 93:
! 94: /**
! 95: * Enable/disable leak detective hooks for the current thread.
! 96: *
! 97: * @param TRUE to enable, FALSE to disable
! 98: * @return state active before calling set_state
! 99: */
! 100: bool (*set_state)(leak_detective_t *this, bool enabled);
! 101:
! 102: /**
! 103: * Destroy a leak_detective instance.
! 104: */
! 105: void (*destroy)(leak_detective_t *this);
! 106: };
! 107:
! 108: /**
! 109: * Create a leak_detective instance, unless the LEAK_DETECTIVE_DISABLE
! 110: * environment variable is set.
! 111: *
! 112: * @return leak detective instance
! 113: */
! 114: leak_detective_t *leak_detective_create();
! 115:
! 116: #endif /** LEAK_DETECTIVE_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>