proc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* CacheFiles statistics
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/seq_file.h>
  14. #include "internal.h"
  15. atomic_t cachefiles_lookup_histogram[HZ];
  16. atomic_t cachefiles_mkdir_histogram[HZ];
  17. atomic_t cachefiles_create_histogram[HZ];
  18. /*
  19. * display the latency histogram
  20. */
  21. static int cachefiles_histogram_show(struct seq_file *m, void *v)
  22. {
  23. unsigned long index;
  24. unsigned x, y, z, t;
  25. switch ((unsigned long) v) {
  26. case 1:
  27. seq_puts(m, "JIFS SECS LOOKUPS MKDIRS CREATES\n");
  28. return 0;
  29. case 2:
  30. seq_puts(m, "===== ===== ========= ========= =========\n");
  31. return 0;
  32. default:
  33. index = (unsigned long) v - 3;
  34. x = atomic_read(&cachefiles_lookup_histogram[index]);
  35. y = atomic_read(&cachefiles_mkdir_histogram[index]);
  36. z = atomic_read(&cachefiles_create_histogram[index]);
  37. if (x == 0 && y == 0 && z == 0)
  38. return 0;
  39. t = (index * 1000) / HZ;
  40. seq_printf(m, "%4lu 0.%03u %9u %9u %9u\n", index, t, x, y, z);
  41. return 0;
  42. }
  43. }
  44. /*
  45. * set up the iterator to start reading from the first line
  46. */
  47. static void *cachefiles_histogram_start(struct seq_file *m, loff_t *_pos)
  48. {
  49. if ((unsigned long long)*_pos >= HZ + 2)
  50. return NULL;
  51. if (*_pos == 0)
  52. *_pos = 1;
  53. return (void *)(unsigned long) *_pos;
  54. }
  55. /*
  56. * move to the next line
  57. */
  58. static void *cachefiles_histogram_next(struct seq_file *m, void *v, loff_t *pos)
  59. {
  60. (*pos)++;
  61. return (unsigned long long)*pos > HZ + 2 ?
  62. NULL : (void *)(unsigned long) *pos;
  63. }
  64. /*
  65. * clean up after reading
  66. */
  67. static void cachefiles_histogram_stop(struct seq_file *m, void *v)
  68. {
  69. }
  70. static const struct seq_operations cachefiles_histogram_ops = {
  71. .start = cachefiles_histogram_start,
  72. .stop = cachefiles_histogram_stop,
  73. .next = cachefiles_histogram_next,
  74. .show = cachefiles_histogram_show,
  75. };
  76. /*
  77. * open "/proc/fs/cachefiles/XXX" which provide statistics summaries
  78. */
  79. static int cachefiles_histogram_open(struct inode *inode, struct file *file)
  80. {
  81. return seq_open(file, &cachefiles_histogram_ops);
  82. }
  83. static const struct file_operations cachefiles_histogram_fops = {
  84. .owner = THIS_MODULE,
  85. .open = cachefiles_histogram_open,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. .release = seq_release,
  89. };
  90. /*
  91. * initialise the /proc/fs/cachefiles/ directory
  92. */
  93. int __init cachefiles_proc_init(void)
  94. {
  95. _enter("");
  96. if (!proc_mkdir("fs/cachefiles", NULL))
  97. goto error_dir;
  98. if (!proc_create("fs/cachefiles/histogram", S_IFREG | 0444, NULL,
  99. &cachefiles_histogram_fops))
  100. goto error_histogram;
  101. _leave(" = 0");
  102. return 0;
  103. error_histogram:
  104. remove_proc_entry("fs/cachefiles", NULL);
  105. error_dir:
  106. _leave(" = -ENOMEM");
  107. return -ENOMEM;
  108. }
  109. /*
  110. * clean up the /proc/fs/cachefiles/ directory
  111. */
  112. void cachefiles_proc_cleanup(void)
  113. {
  114. remove_proc_entry("fs/cachefiles/histogram", NULL);
  115. remove_proc_entry("fs/cachefiles", NULL);
  116. }