cacheinfo.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* cacheinfo.c - disk cache statistics */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2008,2010 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/dl.h>
  20. #include <grub/misc.h>
  21. #include <grub/command.h>
  22. #include <grub/i18n.h>
  23. #include <grub/disk.h>
  24. GRUB_MOD_LICENSE ("GPLv3+");
  25. static grub_err_t
  26. grub_rescue_cmd_info (struct grub_command *cmd __attribute__ ((unused)),
  27. int argc __attribute__ ((unused)),
  28. char *argv[] __attribute__ ((unused)))
  29. {
  30. unsigned long hits, misses;
  31. grub_disk_cache_get_performance (&hits, &misses);
  32. if (hits + misses)
  33. {
  34. unsigned long ratio = hits * 10000 / (hits + misses);
  35. grub_printf ("(%lu.%lu%%)\n", ratio / 100, ratio % 100);
  36. grub_printf_ (N_("Disk cache statistics: hits = %lu (%lu.%02lu%%),"
  37. " misses = %lu\n"), ratio / 100, ratio % 100,
  38. hits, misses);
  39. }
  40. else
  41. grub_printf ("%s\n", _("No disk cache statistics available\n"));
  42. return 0;
  43. }
  44. static grub_command_t cmd_cacheinfo;
  45. GRUB_MOD_INIT(cacheinfo)
  46. {
  47. cmd_cacheinfo =
  48. grub_register_command ("cacheinfo", grub_rescue_cmd_info,
  49. 0, N_("Get disk cache info."));
  50. }
  51. GRUB_MOD_FINI(cacheinfo)
  52. {
  53. grub_unregister_command (cmd_cacheinfo);
  54. }