stats.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * linux/fs/nfsd/stats.c
  3. *
  4. * procfs-based user access to knfsd statistics
  5. *
  6. * /proc/net/rpc/nfsd
  7. *
  8. * Format:
  9. * rc <hits> <misses> <nocache>
  10. * Statistsics for the reply cache
  11. * fh <stale> <total-lookups> <anonlookups> <dir-not-in-dcache> <nondir-not-in-dcache>
  12. * statistics for filehandle lookup
  13. * io <bytes-read> <bytes-writtten>
  14. * statistics for IO throughput
  15. * th <threads> <fullcnt> <10%-20%> <20%-30%> ... <90%-100%> <100%>
  16. * time (seconds) when nfsd thread usage above thresholds
  17. * and number of times that all threads were in use
  18. * ra cache-size <10% <20% <30% ... <100% not-found
  19. * number of times that read-ahead entry was found that deep in
  20. * the cache.
  21. * plus generic RPC stats (see net/sunrpc/stats.c)
  22. *
  23. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/time.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/stat.h>
  30. #include <linux/module.h>
  31. #include <linux/sunrpc/svc.h>
  32. #include <linux/sunrpc/stats.h>
  33. #include <linux/nfsd/nfsd.h>
  34. #include <linux/nfsd/stats.h>
  35. struct nfsd_stats nfsdstats;
  36. struct svc_stat nfsd_svcstats = {
  37. .program = &nfsd_program,
  38. };
  39. static int nfsd_proc_show(struct seq_file *seq, void *v)
  40. {
  41. int i;
  42. seq_printf(seq, "rc %u %u %u\nfh %u %u %u %u %u\nio %u %u\n",
  43. nfsdstats.rchits,
  44. nfsdstats.rcmisses,
  45. nfsdstats.rcnocache,
  46. nfsdstats.fh_stale,
  47. nfsdstats.fh_lookup,
  48. nfsdstats.fh_anon,
  49. nfsdstats.fh_nocache_dir,
  50. nfsdstats.fh_nocache_nondir,
  51. nfsdstats.io_read,
  52. nfsdstats.io_write);
  53. /* thread usage: */
  54. seq_printf(seq, "th %u %u", nfsdstats.th_cnt, nfsdstats.th_fullcnt);
  55. for (i=0; i<10; i++) {
  56. unsigned int jifs = nfsdstats.th_usage[i];
  57. unsigned int sec = jifs / HZ, msec = (jifs % HZ)*1000/HZ;
  58. seq_printf(seq, " %u.%03u", sec, msec);
  59. }
  60. /* newline and ra-cache */
  61. seq_printf(seq, "\nra %u", nfsdstats.ra_size);
  62. for (i=0; i<11; i++)
  63. seq_printf(seq, " %u", nfsdstats.ra_depth[i]);
  64. seq_putc(seq, '\n');
  65. /* show my rpc info */
  66. svc_seq_show(seq, &nfsd_svcstats);
  67. #ifdef CONFIG_NFSD_V4
  68. /* Show count for individual nfsv4 operations */
  69. /* Writing operation numbers 0 1 2 also for maintaining uniformity */
  70. seq_printf(seq,"proc4ops %u", LAST_NFS4_OP + 1);
  71. for (i = 0; i <= LAST_NFS4_OP; i++)
  72. seq_printf(seq, " %u", nfsdstats.nfs4_opcount[i]);
  73. seq_putc(seq, '\n');
  74. #endif
  75. return 0;
  76. }
  77. static int nfsd_proc_open(struct inode *inode, struct file *file)
  78. {
  79. return single_open(file, nfsd_proc_show, NULL);
  80. }
  81. static const struct file_operations nfsd_proc_fops = {
  82. .owner = THIS_MODULE,
  83. .open = nfsd_proc_open,
  84. .read = seq_read,
  85. .llseek = seq_lseek,
  86. .release = single_release,
  87. };
  88. void
  89. nfsd_stat_init(void)
  90. {
  91. svc_proc_register(&nfsd_svcstats, &nfsd_proc_fops);
  92. }
  93. void
  94. nfsd_stat_shutdown(void)
  95. {
  96. svc_proc_unregister("nfsd");
  97. }