xfs_stats.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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
  22. xfs_read_xfsstats(
  23. char *buffer,
  24. char **start,
  25. off_t offset,
  26. int count,
  27. int *eof,
  28. void *data)
  29. {
  30. int c, i, j, len, val;
  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. };
  58. /* Loop over all stats groups */
  59. for (i=j=len = 0; i < ARRAY_SIZE(xstats); i++) {
  60. len += sprintf(buffer + len, "%s", xstats[i].desc);
  61. /* inner loop does each group */
  62. while (j < xstats[i].endpoint) {
  63. val = 0;
  64. /* sum over all cpus */
  65. for_each_possible_cpu(c)
  66. val += *(((__u32*)&per_cpu(xfsstats, c) + j));
  67. len += sprintf(buffer + len, " %u", val);
  68. j++;
  69. }
  70. buffer[len++] = '\n';
  71. }
  72. /* extra precision counters */
  73. for_each_possible_cpu(i) {
  74. 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. len += sprintf(buffer + len, "xpc %Lu %Lu %Lu\n",
  79. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  80. len += sprintf(buffer + len, "debug %u\n",
  81. #if defined(DEBUG)
  82. 1);
  83. #else
  84. 0);
  85. #endif
  86. if (offset >= len) {
  87. *start = buffer;
  88. *eof = 1;
  89. return 0;
  90. }
  91. *start = buffer + offset;
  92. if ((len -= offset) > count)
  93. return count;
  94. *eof = 1;
  95. return len;
  96. }
  97. int
  98. xfs_init_procfs(void)
  99. {
  100. if (!proc_mkdir("fs/xfs", NULL))
  101. goto out;
  102. if (!create_proc_read_entry("fs/xfs/stat", 0, NULL,
  103. xfs_read_xfsstats, NULL))
  104. goto out_remove_entry;
  105. return 0;
  106. out_remove_entry:
  107. remove_proc_entry("fs/xfs", NULL);
  108. out:
  109. return -ENOMEM;
  110. }
  111. void
  112. xfs_cleanup_procfs(void)
  113. {
  114. remove_proc_entry("fs/xfs/stat", NULL);
  115. remove_proc_entry("fs/xfs", NULL);
  116. }