xfs_stats.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. { "fibt2", XFSSTAT_END_FIBT_V2 },
  58. /* we print both series of quota information together */
  59. { "qm", XFSSTAT_END_QM },
  60. };
  61. /* Loop over all stats groups */
  62. for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
  63. seq_printf(m, "%s", xstats[i].desc);
  64. /* inner loop does each group */
  65. for (; j < xstats[i].endpoint; j++)
  66. seq_printf(m, " %u", counter_val(j));
  67. seq_putc(m, '\n');
  68. }
  69. /* extra precision counters */
  70. for_each_possible_cpu(i) {
  71. xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
  72. xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
  73. xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
  74. }
  75. seq_printf(m, "xpc %Lu %Lu %Lu\n",
  76. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  77. seq_printf(m, "debug %u\n",
  78. #if defined(DEBUG)
  79. 1);
  80. #else
  81. 0);
  82. #endif
  83. return 0;
  84. }
  85. static int xfs_stat_proc_open(struct inode *inode, struct file *file)
  86. {
  87. return single_open(file, xfs_stat_proc_show, NULL);
  88. }
  89. static const struct file_operations xfs_stat_proc_fops = {
  90. .owner = THIS_MODULE,
  91. .open = xfs_stat_proc_open,
  92. .read = seq_read,
  93. .llseek = seq_lseek,
  94. .release = single_release,
  95. };
  96. /* legacy quota interfaces */
  97. #ifdef CONFIG_XFS_QUOTA
  98. static int xqm_proc_show(struct seq_file *m, void *v)
  99. {
  100. /* maximum; incore; ratio free to inuse; freelist */
  101. seq_printf(m, "%d\t%d\t%d\t%u\n",
  102. 0,
  103. counter_val(XFSSTAT_END_XQMSTAT),
  104. 0,
  105. counter_val(XFSSTAT_END_XQMSTAT + 1));
  106. return 0;
  107. }
  108. static int xqm_proc_open(struct inode *inode, struct file *file)
  109. {
  110. return single_open(file, xqm_proc_show, NULL);
  111. }
  112. static const struct file_operations xqm_proc_fops = {
  113. .owner = THIS_MODULE,
  114. .open = xqm_proc_open,
  115. .read = seq_read,
  116. .llseek = seq_lseek,
  117. .release = single_release,
  118. };
  119. /* legacy quota stats interface no 2 */
  120. static int xqmstat_proc_show(struct seq_file *m, void *v)
  121. {
  122. int j;
  123. seq_printf(m, "qm");
  124. for (j = XFSSTAT_END_IBT_V2; j < XFSSTAT_END_XQMSTAT; j++)
  125. seq_printf(m, " %u", counter_val(j));
  126. seq_putc(m, '\n');
  127. return 0;
  128. }
  129. static int xqmstat_proc_open(struct inode *inode, struct file *file)
  130. {
  131. return single_open(file, xqmstat_proc_show, NULL);
  132. }
  133. static const struct file_operations xqmstat_proc_fops = {
  134. .owner = THIS_MODULE,
  135. .open = xqmstat_proc_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = single_release,
  139. };
  140. #endif /* CONFIG_XFS_QUOTA */
  141. int
  142. xfs_init_procfs(void)
  143. {
  144. if (!proc_mkdir("fs/xfs", NULL))
  145. goto out;
  146. if (!proc_create("fs/xfs/stat", 0, NULL,
  147. &xfs_stat_proc_fops))
  148. goto out_remove_xfs_dir;
  149. #ifdef CONFIG_XFS_QUOTA
  150. if (!proc_create("fs/xfs/xqmstat", 0, NULL,
  151. &xqmstat_proc_fops))
  152. goto out_remove_stat_file;
  153. if (!proc_create("fs/xfs/xqm", 0, NULL,
  154. &xqm_proc_fops))
  155. goto out_remove_xqmstat_file;
  156. #endif
  157. return 0;
  158. #ifdef CONFIG_XFS_QUOTA
  159. out_remove_xqmstat_file:
  160. remove_proc_entry("fs/xfs/xqmstat", NULL);
  161. out_remove_stat_file:
  162. remove_proc_entry("fs/xfs/stat", NULL);
  163. #endif
  164. out_remove_xfs_dir:
  165. remove_proc_entry("fs/xfs", NULL);
  166. out:
  167. return -ENOMEM;
  168. }
  169. void
  170. xfs_cleanup_procfs(void)
  171. {
  172. #ifdef CONFIG_XFS_QUOTA
  173. remove_proc_entry("fs/xfs/xqm", NULL);
  174. remove_proc_entry("fs/xfs/xqmstat", NULL);
  175. #endif
  176. remove_proc_entry("fs/xfs/stat", NULL);
  177. remove_proc_entry("fs/xfs", NULL);
  178. }