xfs_stats.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 xfs_stat_proc_show(struct seq_file *m, void *v)
  22. {
  23. int c, i, j, val;
  24. __uint64_t xs_xstrat_bytes = 0;
  25. __uint64_t xs_write_bytes = 0;
  26. __uint64_t xs_read_bytes = 0;
  27. static const struct xstats_entry {
  28. char *desc;
  29. int endpoint;
  30. } xstats[] = {
  31. { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
  32. { "abt", XFSSTAT_END_ALLOC_BTREE },
  33. { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
  34. { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
  35. { "dir", XFSSTAT_END_DIRECTORY_OPS },
  36. { "trans", XFSSTAT_END_TRANSACTIONS },
  37. { "ig", XFSSTAT_END_INODE_OPS },
  38. { "log", XFSSTAT_END_LOG_OPS },
  39. { "push_ail", XFSSTAT_END_TAIL_PUSHING },
  40. { "xstrat", XFSSTAT_END_WRITE_CONVERT },
  41. { "rw", XFSSTAT_END_READ_WRITE_OPS },
  42. { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
  43. { "icluster", XFSSTAT_END_INODE_CLUSTER },
  44. { "vnodes", XFSSTAT_END_VNODE_OPS },
  45. { "buf", XFSSTAT_END_BUF },
  46. { "abtb2", XFSSTAT_END_ABTB_V2 },
  47. { "abtc2", XFSSTAT_END_ABTC_V2 },
  48. { "bmbt2", XFSSTAT_END_BMBT_V2 },
  49. { "ibt2", XFSSTAT_END_IBT_V2 },
  50. };
  51. /* Loop over all stats groups */
  52. for (i=j = 0; i < ARRAY_SIZE(xstats); i++) {
  53. seq_printf(m, "%s", xstats[i].desc);
  54. /* inner loop does each group */
  55. while (j < xstats[i].endpoint) {
  56. val = 0;
  57. /* sum over all cpus */
  58. for_each_possible_cpu(c)
  59. val += *(((__u32*)&per_cpu(xfsstats, c) + j));
  60. seq_printf(m, " %u", val);
  61. j++;
  62. }
  63. seq_putc(m, '\n');
  64. }
  65. /* extra precision counters */
  66. for_each_possible_cpu(i) {
  67. xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
  68. xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
  69. xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
  70. }
  71. seq_printf(m, "xpc %Lu %Lu %Lu\n",
  72. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  73. seq_printf(m, "debug %u\n",
  74. #if defined(DEBUG)
  75. 1);
  76. #else
  77. 0);
  78. #endif
  79. return 0;
  80. }
  81. static int xfs_stat_proc_open(struct inode *inode, struct file *file)
  82. {
  83. return single_open(file, xfs_stat_proc_show, NULL);
  84. }
  85. static const struct file_operations xfs_stat_proc_fops = {
  86. .owner = THIS_MODULE,
  87. .open = xfs_stat_proc_open,
  88. .read = seq_read,
  89. .llseek = seq_lseek,
  90. .release = single_release,
  91. };
  92. int
  93. xfs_init_procfs(void)
  94. {
  95. if (!proc_mkdir("fs/xfs", NULL))
  96. goto out;
  97. if (!proc_create("fs/xfs/stat", 0, NULL,
  98. &xfs_stat_proc_fops))
  99. goto out_remove_entry;
  100. return 0;
  101. out_remove_entry:
  102. remove_proc_entry("fs/xfs", NULL);
  103. out:
  104. return -ENOMEM;
  105. }
  106. void
  107. xfs_cleanup_procfs(void)
  108. {
  109. remove_proc_entry("fs/xfs/stat", NULL);
  110. remove_proc_entry("fs/xfs", NULL);
  111. }