time.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* echo.c - Command to display a line of text */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2011 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/time.h>
  20. #include <grub/misc.h>
  21. #include <grub/dl.h>
  22. #include <grub/command.h>
  23. #include <grub/i18n.h>
  24. GRUB_MOD_LICENSE ("GPLv3+");
  25. static grub_err_t
  26. grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)),
  27. int argc, char **args)
  28. {
  29. grub_command_t cmd;
  30. grub_uint32_t start;
  31. grub_uint32_t end;
  32. if (argc == 0)
  33. return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no command is specified"));
  34. cmd = grub_command_find (args[0]);
  35. if (!cmd)
  36. return grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("can't find command `%s'"),
  37. args[0]);
  38. start = grub_get_time_ms ();
  39. (cmd->func) (cmd, argc - 1, &args[1]);
  40. end = grub_get_time_ms ();
  41. grub_printf_ (N_("Elapsed time: %d.%03d seconds \n"), (end - start) / 1000,
  42. (end - start) % 1000);
  43. return grub_errno;
  44. }
  45. static grub_command_t cmd;
  46. GRUB_MOD_INIT(time)
  47. {
  48. cmd = grub_register_command ("time", grub_cmd_time,
  49. N_("COMMAND [ARGS]"),
  50. N_("Measure time used by COMMAND"));
  51. }
  52. GRUB_MOD_FINI(time)
  53. {
  54. grub_unregister_command (cmd);
  55. }