histogram.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* FS-Cache latency histogram
  2. *
  3. * Copyright (C) 2008 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. #define FSCACHE_DEBUG_LEVEL THREAD
  12. #include <linux/module.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/seq_file.h>
  15. #include "internal.h"
  16. atomic_t fscache_obj_instantiate_histogram[HZ];
  17. atomic_t fscache_objs_histogram[HZ];
  18. atomic_t fscache_ops_histogram[HZ];
  19. atomic_t fscache_retrieval_delay_histogram[HZ];
  20. atomic_t fscache_retrieval_histogram[HZ];
  21. /*
  22. * display the time-taken histogram
  23. */
  24. static int fscache_histogram_show(struct seq_file *m, void *v)
  25. {
  26. unsigned long index;
  27. unsigned n[5], t;
  28. switch ((unsigned long) v) {
  29. case 1:
  30. seq_puts(m, "JIFS SECS OBJ INST OP RUNS OBJ RUNS "
  31. " RETRV DLY RETRIEVLS\n");
  32. return 0;
  33. case 2:
  34. seq_puts(m, "===== ===== ========= ========= ========="
  35. " ========= =========\n");
  36. return 0;
  37. default:
  38. index = (unsigned long) v - 3;
  39. n[0] = atomic_read(&fscache_obj_instantiate_histogram[index]);
  40. n[1] = atomic_read(&fscache_ops_histogram[index]);
  41. n[2] = atomic_read(&fscache_objs_histogram[index]);
  42. n[3] = atomic_read(&fscache_retrieval_delay_histogram[index]);
  43. n[4] = atomic_read(&fscache_retrieval_histogram[index]);
  44. if (!(n[0] | n[1] | n[2] | n[3] | n[4]))
  45. return 0;
  46. t = (index * 1000) / HZ;
  47. seq_printf(m, "%4lu 0.%03u %9u %9u %9u %9u %9u\n",
  48. index, t, n[0], n[1], n[2], n[3], n[4]);
  49. return 0;
  50. }
  51. }
  52. /*
  53. * set up the iterator to start reading from the first line
  54. */
  55. static void *fscache_histogram_start(struct seq_file *m, loff_t *_pos)
  56. {
  57. if ((unsigned long long)*_pos >= HZ + 2)
  58. return NULL;
  59. if (*_pos == 0)
  60. *_pos = 1;
  61. return (void *)(unsigned long) *_pos;
  62. }
  63. /*
  64. * move to the next line
  65. */
  66. static void *fscache_histogram_next(struct seq_file *m, void *v, loff_t *pos)
  67. {
  68. (*pos)++;
  69. return (unsigned long long)*pos > HZ + 2 ?
  70. NULL : (void *)(unsigned long) *pos;
  71. }
  72. /*
  73. * clean up after reading
  74. */
  75. static void fscache_histogram_stop(struct seq_file *m, void *v)
  76. {
  77. }
  78. static const struct seq_operations fscache_histogram_ops = {
  79. .start = fscache_histogram_start,
  80. .stop = fscache_histogram_stop,
  81. .next = fscache_histogram_next,
  82. .show = fscache_histogram_show,
  83. };
  84. /*
  85. * open "/proc/fs/fscache/histogram" to provide latency data
  86. */
  87. static int fscache_histogram_open(struct inode *inode, struct file *file)
  88. {
  89. return seq_open(file, &fscache_histogram_ops);
  90. }
  91. const struct file_operations fscache_histogram_fops = {
  92. .owner = THIS_MODULE,
  93. .open = fscache_histogram_open,
  94. .read = seq_read,
  95. .llseek = seq_lseek,
  96. .release = seq_release,
  97. };