histogram.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 RETRV DLY RETRIEVLS\n");
  31. return 0;
  32. case 2:
  33. seq_puts(m, "===== ===== ========= ========= ========= ========= =========\n");
  34. return 0;
  35. default:
  36. index = (unsigned long) v - 3;
  37. n[0] = atomic_read(&fscache_obj_instantiate_histogram[index]);
  38. n[1] = atomic_read(&fscache_ops_histogram[index]);
  39. n[2] = atomic_read(&fscache_objs_histogram[index]);
  40. n[3] = atomic_read(&fscache_retrieval_delay_histogram[index]);
  41. n[4] = atomic_read(&fscache_retrieval_histogram[index]);
  42. if (!(n[0] | n[1] | n[2] | n[3] | n[4]))
  43. return 0;
  44. t = (index * 1000) / HZ;
  45. seq_printf(m, "%4lu 0.%03u %9u %9u %9u %9u %9u\n",
  46. index, t, n[0], n[1], n[2], n[3], n[4]);
  47. return 0;
  48. }
  49. }
  50. /*
  51. * set up the iterator to start reading from the first line
  52. */
  53. static void *fscache_histogram_start(struct seq_file *m, loff_t *_pos)
  54. {
  55. if ((unsigned long long)*_pos >= HZ + 2)
  56. return NULL;
  57. if (*_pos == 0)
  58. *_pos = 1;
  59. return (void *)(unsigned long) *_pos;
  60. }
  61. /*
  62. * move to the next line
  63. */
  64. static void *fscache_histogram_next(struct seq_file *m, void *v, loff_t *pos)
  65. {
  66. (*pos)++;
  67. return (unsigned long long)*pos > HZ + 2 ?
  68. NULL : (void *)(unsigned long) *pos;
  69. }
  70. /*
  71. * clean up after reading
  72. */
  73. static void fscache_histogram_stop(struct seq_file *m, void *v)
  74. {
  75. }
  76. const struct seq_operations fscache_histogram_ops = {
  77. .start = fscache_histogram_start,
  78. .stop = fscache_histogram_stop,
  79. .next = fscache_histogram_next,
  80. .show = fscache_histogram_show,
  81. };