histogram.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* FS-Cache latency histogram
  3. *
  4. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #define FSCACHE_DEBUG_LEVEL THREAD
  8. #include <linux/module.h>
  9. #include <linux/proc_fs.h>
  10. #include <linux/seq_file.h>
  11. #include "internal.h"
  12. atomic_t fscache_obj_instantiate_histogram[HZ];
  13. atomic_t fscache_objs_histogram[HZ];
  14. atomic_t fscache_ops_histogram[HZ];
  15. atomic_t fscache_retrieval_delay_histogram[HZ];
  16. atomic_t fscache_retrieval_histogram[HZ];
  17. /*
  18. * display the time-taken histogram
  19. */
  20. static int fscache_histogram_show(struct seq_file *m, void *v)
  21. {
  22. unsigned long index;
  23. unsigned n[5], t;
  24. switch ((unsigned long) v) {
  25. case 1:
  26. seq_puts(m, "JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS\n");
  27. return 0;
  28. case 2:
  29. seq_puts(m, "===== ===== ========= ========= ========= ========= =========\n");
  30. return 0;
  31. default:
  32. index = (unsigned long) v - 3;
  33. n[0] = atomic_read(&fscache_obj_instantiate_histogram[index]);
  34. n[1] = atomic_read(&fscache_ops_histogram[index]);
  35. n[2] = atomic_read(&fscache_objs_histogram[index]);
  36. n[3] = atomic_read(&fscache_retrieval_delay_histogram[index]);
  37. n[4] = atomic_read(&fscache_retrieval_histogram[index]);
  38. if (!(n[0] | n[1] | n[2] | n[3] | n[4]))
  39. return 0;
  40. t = (index * 1000) / HZ;
  41. seq_printf(m, "%4lu 0.%03u %9u %9u %9u %9u %9u\n",
  42. index, t, n[0], n[1], n[2], n[3], n[4]);
  43. return 0;
  44. }
  45. }
  46. /*
  47. * set up the iterator to start reading from the first line
  48. */
  49. static void *fscache_histogram_start(struct seq_file *m, loff_t *_pos)
  50. {
  51. if ((unsigned long long)*_pos >= HZ + 2)
  52. return NULL;
  53. if (*_pos == 0)
  54. *_pos = 1;
  55. return (void *)(unsigned long) *_pos;
  56. }
  57. /*
  58. * move to the next line
  59. */
  60. static void *fscache_histogram_next(struct seq_file *m, void *v, loff_t *pos)
  61. {
  62. (*pos)++;
  63. return (unsigned long long)*pos > HZ + 2 ?
  64. NULL : (void *)(unsigned long) *pos;
  65. }
  66. /*
  67. * clean up after reading
  68. */
  69. static void fscache_histogram_stop(struct seq_file *m, void *v)
  70. {
  71. }
  72. const struct seq_operations fscache_histogram_ops = {
  73. .start = fscache_histogram_start,
  74. .stop = fscache_histogram_stop,
  75. .next = fscache_histogram_next,
  76. .show = fscache_histogram_show,
  77. };