xfs_stats.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include <linux/proc_fs.h>
  34. DEFINE_PER_CPU(struct xfsstats, xfsstats);
  35. STATIC int
  36. xfs_read_xfsstats(
  37. char *buffer,
  38. char **start,
  39. off_t offset,
  40. int count,
  41. int *eof,
  42. void *data)
  43. {
  44. int c, i, j, len, val;
  45. __uint64_t xs_xstrat_bytes = 0;
  46. __uint64_t xs_write_bytes = 0;
  47. __uint64_t xs_read_bytes = 0;
  48. static struct xstats_entry {
  49. char *desc;
  50. int endpoint;
  51. } xstats[] = {
  52. { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC },
  53. { "abt", XFSSTAT_END_ALLOC_BTREE },
  54. { "blk_map", XFSSTAT_END_BLOCK_MAPPING },
  55. { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE },
  56. { "dir", XFSSTAT_END_DIRECTORY_OPS },
  57. { "trans", XFSSTAT_END_TRANSACTIONS },
  58. { "ig", XFSSTAT_END_INODE_OPS },
  59. { "log", XFSSTAT_END_LOG_OPS },
  60. { "push_ail", XFSSTAT_END_TAIL_PUSHING },
  61. { "xstrat", XFSSTAT_END_WRITE_CONVERT },
  62. { "rw", XFSSTAT_END_READ_WRITE_OPS },
  63. { "attr", XFSSTAT_END_ATTRIBUTE_OPS },
  64. { "icluster", XFSSTAT_END_INODE_CLUSTER },
  65. { "vnodes", XFSSTAT_END_VNODE_OPS },
  66. { "buf", XFSSTAT_END_BUF },
  67. };
  68. /* Loop over all stats groups */
  69. for (i=j=len = 0; i < sizeof(xstats)/sizeof(struct xstats_entry); i++) {
  70. len += sprintf(buffer + len, xstats[i].desc);
  71. /* inner loop does each group */
  72. while (j < xstats[i].endpoint) {
  73. val = 0;
  74. /* sum over all cpus */
  75. for (c = 0; c < NR_CPUS; c++) {
  76. if (!cpu_possible(c)) continue;
  77. val += *(((__u32*)&per_cpu(xfsstats, c) + j));
  78. }
  79. len += sprintf(buffer + len, " %u", val);
  80. j++;
  81. }
  82. buffer[len++] = '\n';
  83. }
  84. /* extra precision counters */
  85. for (i = 0; i < NR_CPUS; i++) {
  86. if (!cpu_possible(i)) continue;
  87. xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
  88. xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
  89. xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
  90. }
  91. len += sprintf(buffer + len, "xpc %Lu %Lu %Lu\n",
  92. xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
  93. len += sprintf(buffer + len, "debug %u\n",
  94. #if defined(DEBUG)
  95. 1);
  96. #else
  97. 0);
  98. #endif
  99. if (offset >= len) {
  100. *start = buffer;
  101. *eof = 1;
  102. return 0;
  103. }
  104. *start = buffer + offset;
  105. if ((len -= offset) > count)
  106. return count;
  107. *eof = 1;
  108. return len;
  109. }
  110. void
  111. xfs_init_procfs(void)
  112. {
  113. if (!proc_mkdir("fs/xfs", NULL))
  114. return;
  115. create_proc_read_entry("fs/xfs/stat", 0, NULL, xfs_read_xfsstats, NULL);
  116. }
  117. void
  118. xfs_cleanup_procfs(void)
  119. {
  120. remove_proc_entry("fs/xfs/stat", NULL);
  121. remove_proc_entry("fs/xfs", NULL);
  122. }