more changes on original files
[linux-2.4.git] / fs / xfs / linux-2.4 / xfs_stats.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "xfs.h"
34 #include <linux/proc_fs.h>
35
36 struct xfsstats xfsstats;
37
38 STATIC int
39 xfs_read_xfsstats(
40         char            *buffer,
41         char            **start,
42         off_t           offset,
43         int             count,
44         int             *eof,
45         void            *data)
46 {
47         int             i, j, len;
48         static struct xstats_entry {
49                 char    *desc;
50                 int     endpoint;
51         } xstats[] = {
52                 { "extent_alloc",       XFSSTAT_END_EXTENT_ALLOC        },
53                 { "abt",                XFSSTAT_END_ALLOC_BTREE         },
54                 { "blk_map",            XFSSTAT_END_BLOCK_MAPPING       },
55                 { "bmbt",               XFSSTAT_END_BLOCK_MAP_BTREE     },
56                 { "dir",                XFSSTAT_END_DIRECTORY_OPS       },
57                 { "trans",              XFSSTAT_END_TRANSACTIONS        },
58                 { "ig",                 XFSSTAT_END_INODE_OPS           },
59                 { "log",                XFSSTAT_END_LOG_OPS             },
60                 { "push_ail",           XFSSTAT_END_TAIL_PUSHING        },
61                 { "xstrat",             XFSSTAT_END_WRITE_CONVERT       },
62                 { "rw",                 XFSSTAT_END_READ_WRITE_OPS      },
63                 { "attr",               XFSSTAT_END_ATTRIBUTE_OPS       },
64                 { "icluster",           XFSSTAT_END_INODE_CLUSTER       },
65                 { "vnodes",             XFSSTAT_END_VNODE_OPS           },
66                 { "buf",                XFSSTAT_END_BUF                 },
67         };
68
69         for (i=j=len = 0; i < sizeof(xstats)/sizeof(struct xstats_entry); i++) {
70                 len += sprintf(buffer + len, xstats[i].desc);
71                 /* inner loop does each group */
72                 while (j < xstats[i].endpoint) {
73                         len += sprintf(buffer + len, " %u",
74                                         *(((__u32*)&xfsstats) + j));
75                         j++;
76                 }
77                 buffer[len++] = '\n';
78         }
79         /* extra precision counters */
80         len += sprintf(buffer + len, "xpc %Lu %Lu %Lu\n",
81                         xfsstats.xs_xstrat_bytes,
82                         xfsstats.xs_write_bytes,
83                         xfsstats.xs_read_bytes);
84         len += sprintf(buffer + len, "debug %u\n",
85 #if defined(DEBUG)
86                 1);
87 #else
88                 0);
89 #endif
90
91         if (offset >= len) {
92                 *start = buffer;
93                 *eof = 1;
94                 return 0;
95         }
96         *start = buffer + offset;
97         if ((len -= offset) > count)
98                 return count;
99         *eof = 1;
100
101         return len;
102 }
103
104 void
105 xfs_init_procfs(void)
106 {
107         if (!proc_mkdir("fs/xfs", 0))
108                 return;
109         create_proc_read_entry("fs/xfs/stat", 0, 0, xfs_read_xfsstats, NULL);
110 }
111
112 void
113 xfs_cleanup_procfs(void)
114 {
115         remove_proc_entry("fs/xfs/stat", NULL);
116         remove_proc_entry("fs/xfs", NULL);
117 }