xfs_stats.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * 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.
  13. *
  14. * 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
  17. */
  18. #include "xfs.h"
  19. #include <linux/proc_fs.h>
  20. DEFINE_PER_CPU(struct xfsstats, xfsstats);
  21. static int counter_val(int idx)
  22. {
  23. int val = 0, cpu;
  24. for_each_possible_cpu(cpu)
  25. val += *(((__u32 *)&per_cpu(xfsstats, cpu) + idx));
  26. return val;
  27. }
  28. static int xfs_stat_proc_show(struct seq_file *m, void *v)
  29. {
  30. int i, j;
  31. __uint64_t xs_xstrat_bytes = 0;
  32. __uint64_t xs_write_bytes = 0;
  33. __uint64_t xs_read_bytes = 0;
  34. static const struct xstats_entry {
  35. char *desc;
  36. int endpoint;
  37. } xstats[] = {
  38. { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
  39. { "abt", XFSSTAT_END_ALLOC_BTREE },
  40. { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
  41. { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
  42. { "dir", XFSSTAT_END_DIRECTORY_OPS },
  43. { "trans", XFSSTAT_END_TRANSACTIONS },
  44. { "ig", XFSSTAT_END_INODE_OPS },
  45. { "log", XFSSTAT_END_LOG_OPS },
  46. { "push_ail", XFSSTAT_END_TAIL_PUSHING },
  47. { "xstrat", XFSSTAT_END_WRITE_CONVERT },
  48. { "rw", XFSSTAT_END_READ_WRITE_OPS },
  49. { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
  50. { "icluster", XFSSTAT_END_INODE_CLUSTER },
  51. { "vnodes", XFSSTAT_END_VNODE_OPS },
  52. { "buf", XFSSTAT_END_BUF },
  53. { "abtb2", XFSSTAT_END_ABTB_V2 },
  54. { "abtc2", XFSSTAT_END_ABTC_V2 },
  55. { "bmbt2", XFSSTAT_END_BMBT_V2 },
  56. { "ibt2", XFSSTAT_END_IBT_V2 },
  57. /* we print both series of quota information together */
  58. { "qm", XFSSTAT_END_QM },
  59. };
  60. /* Loop over all stats groups */
  61. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  62. seq_printf(m, "%s", xstats[i].desc);
  63. /* inner loop does each group */
  64. for (; j < xstats[i].endpoint; j++)
  65. seq_printf(m, " %u", counter_val(j));
  66. seq_putc(m, '\n');
  67. }
  68. /* extra precision counters */
  69. for_each_possible_cpu(i) {
  70. xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
  71. xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
  72. xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
  73. }
  74. seq_printf(m, "xpc %Lu %Lu %Lu\n",
  75. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  76. seq_printf(m, "debug %u\n",
  77. #if defined(DEBUG)
  78. 1);
  79. #else
  80. 0);
  81. #endif
  82. return 0;
  83. }
  84. static int xfs_stat_proc_open(struct inode *inode, struct file *file)
  85. {
  86. return single_open(file, xfs_stat_proc_show, NULL);
  87. }
  88. static const struct file_operations xfs_stat_proc_fops = {
  89. .owner = THIS_MODULE,
  90. .open = xfs_stat_proc_open,
  91. .read = seq_read,
  92. .llseek = seq_lseek,
  93. .release = single_release,
  94. };
  95. /* legacy quota interfaces */
  96. #ifdef CONFIG_XFS_QUOTA
  97. static int xqm_proc_show(struct seq_file *m, void *v)
  98. {
  99. /* maximum; incore; ratio free to inuse; freelist */
  100. seq_printf(m, "%d\t%d\t%d\t%u\n",
  101. 0,
  102. counter_val(XFSSTAT_END_XQMSTAT),
  103. 0,
  104. counter_val(XFSSTAT_END_XQMSTAT + 1));
  105. return 0;
  106. }
  107. static int xqm_proc_open(struct inode *inode, struct file *file)
  108. {
  109. return single_open(file, xqm_proc_show, NULL);
  110. }
  111. static const struct file_operations xqm_proc_fops = {
  112. .owner = THIS_MODULE,
  113. .open = xqm_proc_open,
  114. .read = seq_read,
  115. .llseek = seq_lseek,
  116. .release = single_release,
  117. };
  118. /* legacy quota stats interface no 2 */
  119. static int xqmstat_proc_show(struct seq_file *m, void *v)
  120. {
  121. int j;
  122. seq_printf(m, "qm");
  123. for (j = XFSSTAT_END_IBT_V2; j < XFSSTAT_END_XQMSTAT; j++)
  124. seq_printf(m, " %u", counter_val(j));
  125. seq_putc(m, '\n');
  126. return 0;
  127. }
  128. static int xqmstat_proc_open(struct inode *inode, struct file *file)
  129. {
  130. return single_open(file, xqmstat_proc_show, NULL);
  131. }
  132. static const struct file_operations xqmstat_proc_fops = {
  133. .owner = THIS_MODULE,
  134. .open = xqmstat_proc_open,
  135. .read = seq_read,
  136. .llseek = seq_lseek,
  137. .release = single_release,
  138. };
  139. #endif /* CONFIG_XFS_QUOTA */
  140. int
  141. xfs_init_procfs(void)
  142. {
  143. if (!proc_mkdir("fs/xfs", NULL))
  144. goto out;
  145. if (!proc_create("fs/xfs/stat", 0, NULL,
  146. &xfs_stat_proc_fops))
  147. goto out_remove_xfs_dir;
  148. #ifdef CONFIG_XFS_QUOTA
  149. if (!proc_create("fs/xfs/xqmstat", 0, NULL,
  150. &xqmstat_proc_fops))
  151. goto out_remove_stat_file;
  152. if (!proc_create("fs/xfs/xqm", 0, NULL,
  153. &xqm_proc_fops))
  154. goto out_remove_xqmstat_file;
  155. #endif
  156. return 0;
  157. #ifdef CONFIG_XFS_QUOTA
  158. out_remove_xqmstat_file:
  159. remove_proc_entry("fs/xfs/xqmstat", NULL);
  160. out_remove_stat_file:
  161. remove_proc_entry("fs/xfs/stat", NULL);
  162. #endif
  163. out_remove_xfs_dir:
  164. remove_proc_entry("fs/xfs", NULL);
  165. out:
  166. return -ENOMEM;
  167. }
  168. void
  169. xfs_cleanup_procfs(void)
  170. {
  171. #ifdef CONFIG_XFS_QUOTA
  172. remove_proc_entry("fs/xfs/xqm", NULL);
  173. remove_proc_entry("fs/xfs/xqmstat", NULL);
  174. #endif
  175. remove_proc_entry("fs/xfs/stat", NULL);
  176. remove_proc_entry("fs/xfs", NULL);
  177. }