blob: e480b610205198db045d49c623f39578eca1636a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
19#include <linux/proc_fs.h>
20
21DEFINE_PER_CPU(struct xfsstats, xfsstats);
22
23STATIC int
24xfs_read_xfsstats(
25 char *buffer,
26 char **start,
27 off_t offset,
28 int count,
29 int *eof,
30 void *data)
31{
32 int c, i, j, len, val;
33 __uint64_t xs_xstrat_bytes = 0;
34 __uint64_t xs_write_bytes = 0;
35 __uint64_t xs_read_bytes = 0;
36
Christoph Hellwig1df84c92006-01-11 15:29:52 +110037 static const struct xstats_entry {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 char *desc;
39 int endpoint;
40 } xstats[] = {
41 { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
42 { "abt", XFSSTAT_END_ALLOC_BTREE },
43 { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
44 { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
45 { "dir", XFSSTAT_END_DIRECTORY_OPS },
46 { "trans", XFSSTAT_END_TRANSACTIONS },
47 { "ig", XFSSTAT_END_INODE_OPS },
48 { "log", XFSSTAT_END_LOG_OPS },
49 { "push_ail", XFSSTAT_END_TAIL_PUSHING },
50 { "xstrat", XFSSTAT_END_WRITE_CONVERT },
51 { "rw", XFSSTAT_END_READ_WRITE_OPS },
52 { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
53 { "icluster", XFSSTAT_END_INODE_CLUSTER },
54 { "vnodes", XFSSTAT_END_VNODE_OPS },
55 { "buf", XFSSTAT_END_BUF },
56 };
57
58 /* Loop over all stats groups */
Tobias Klausere8c96f82006-03-24 03:15:34 -080059 for (i=j=len = 0; i < ARRAY_SIZE(xstats); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 len += sprintf(buffer + len, xstats[i].desc);
61 /* inner loop does each group */
62 while (j < xstats[i].endpoint) {
63 val = 0;
64 /* sum over all cpus */
KAMEZAWA Hiroyuki6f0419e2006-06-23 02:03:00 -070065 for_each_possible_cpu(c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 val += *(((__u32*)&per_cpu(xfsstats, c) + j));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 len += sprintf(buffer + len, " %u", val);
68 j++;
69 }
70 buffer[len++] = '\n';
71 }
72 /* extra precision counters */
KAMEZAWA Hiroyuki6f0419e2006-06-23 02:03:00 -070073 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
75 xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
76 xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
77 }
78
79 len += sprintf(buffer + len, "xpc %Lu %Lu %Lu\n",
80 xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
81 len += sprintf(buffer + len, "debug %u\n",
82#if defined(DEBUG)
83 1);
84#else
85 0);
86#endif
87
88 if (offset >= len) {
89 *start = buffer;
90 *eof = 1;
91 return 0;
92 }
93 *start = buffer + offset;
94 if ((len -= offset) > count)
95 return count;
96 *eof = 1;
97
98 return len;
99}
100
101void
102xfs_init_procfs(void)
103{
104 if (!proc_mkdir("fs/xfs", NULL))
105 return;
106 create_proc_read_entry("fs/xfs/stat", 0, NULL, xfs_read_xfsstats, NULL);
107}
108
109void
110xfs_cleanup_procfs(void)
111{
112 remove_proc_entry("fs/xfs/stat", NULL);
113 remove_proc_entry("fs/xfs", NULL);
114}