objcnt.c 4.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/* SCTP kernel reference Implementation
 * (C) Copyright IBM Corp. 2001, 2004
3
 *
L
Linus Torvalds 已提交
4
 * This file is part of the SCTP kernel reference Implementation
5
 *
L
Linus Torvalds 已提交
6
 * Support for memory object debugging.  This allows one to monitor the
7 8 9 10 11
 * object allocations/deallocations for types instrumented for this
 * via the proc fs.
 *
 * The SCTP reference implementation is free software;
 * you can redistribute it and/or modify it under the terms of
L
Linus Torvalds 已提交
12 13 14
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
15 16
 *
 * The SCTP reference implementation is distributed in the hope that it
L
Linus Torvalds 已提交
17 18 19 20
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
21
 *
L
Linus Torvalds 已提交
22 23 24
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
25 26
 * Boston, MA 02111-1307, USA.
 *
L
Linus Torvalds 已提交
27 28 29
 * Please send any bug reports or fixes you make to the
 * email address(es):
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
30
 *
L
Linus Torvalds 已提交
31 32 33
 * Or submit a bug report through the following website:
 *    http://www.sf.net/projects/lksctp
 *
34
 * Written or modified by:
L
Linus Torvalds 已提交
35
 *    Jon Grimm             <jgrimm@us.ibm.com>
36
 *
L
Linus Torvalds 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release.
 */

#include <linux/kernel.h>
#include <net/sctp/sctp.h>

/*
 * Global counters to count raw object allocation counts.
 * To add new counters, choose a unique suffix for the variable
 * name as the helper macros key off this suffix to make
 * life easier for the programmer.
 */

SCTP_DBG_OBJCNT(sock);
SCTP_DBG_OBJCNT(ep);
SCTP_DBG_OBJCNT(transport);
SCTP_DBG_OBJCNT(assoc);
SCTP_DBG_OBJCNT(bind_addr);
SCTP_DBG_OBJCNT(bind_bucket);
SCTP_DBG_OBJCNT(chunk);
SCTP_DBG_OBJCNT(addr);
SCTP_DBG_OBJCNT(ssnmap);
SCTP_DBG_OBJCNT(datamsg);

/* An array to make it easy to pretty print the debug information
 * to the proc fs.
 */
static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
	SCTP_DBG_OBJCNT_ENTRY(sock),
	SCTP_DBG_OBJCNT_ENTRY(ep),
	SCTP_DBG_OBJCNT_ENTRY(assoc),
	SCTP_DBG_OBJCNT_ENTRY(transport),
	SCTP_DBG_OBJCNT_ENTRY(chunk),
	SCTP_DBG_OBJCNT_ENTRY(bind_addr),
	SCTP_DBG_OBJCNT_ENTRY(bind_bucket),
	SCTP_DBG_OBJCNT_ENTRY(addr),
	SCTP_DBG_OBJCNT_ENTRY(ssnmap),
	SCTP_DBG_OBJCNT_ENTRY(datamsg),
};

/* Callback from procfs to read out objcount information.
 * Walk through the entries in the sctp_dbg_objcnt array, dumping
 * the raw object counts for each monitored type.
 *
 * This code was modified from similar code in route.c
 */
static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset,
				int length, int *eof, void *data)
{
	int len = 0;
	off_t pos = 0;
	int entries;
	int i;
	char temp[128];

	/* How many entries? */
	entries = ARRAY_SIZE(sctp_dbg_objcnt);

	/* Walk the entries and print out the debug information
	 * for proc fs.
	 */
	for (i = 0; i < entries; i++) {
		pos += 128;

		/* Skip ahead. */
		if (pos <= offset) {
			len = 0;
			continue;
		}
		/* Print out each entry. */
		sprintf(temp, "%s: %d",
			sctp_dbg_objcnt[i].label,
			atomic_read(sctp_dbg_objcnt[i].counter));

		sprintf(buffer + len, "%-127s\n", temp);
		len += 128;
		if (pos >= offset+length)
			goto done;
	}

done:
	*start = buffer + len - (pos - offset);
	len = pos - offset;
	if (len > length)
		len = length;

124
	return len;
L
Linus Torvalds 已提交
125 126 127 128 129
}

/* Initialize the objcount in the proc filesystem.  */
void sctp_dbg_objcnt_init(void)
{
130 131
	struct proc_dir_entry *ent;
	ent = create_proc_read_entry("sctp_dbg_objcnt", 0, proc_net_sctp,
L
Linus Torvalds 已提交
132
			       sctp_dbg_objcnt_read, NULL);
133
	if (!ent)
134
		printk(KERN_WARNING
135
			"sctp_dbg_objcnt: Unable to create /proc entry.\n");
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143 144
}

/* Cleanup the objcount entry in the proc filesystem.  */
void sctp_dbg_objcnt_exit(void)
{
	remove_proc_entry("sctp_dbg_objcnt", proc_net_sctp);
}