You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time_cmd.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2009 Daniel Verkamp <daniel@drv.nu>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * March-19-2009 @ 02:44: Added sleep command.
  20. * Shao Miller <shao.miller@yrdsb.edu.on.ca>.
  21. */
  22. FILE_LICENCE ( GPL2_OR_LATER );
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <unistd.h>
  27. #include <ipxe/command.h>
  28. #include <ipxe/parseopt.h>
  29. #include <ipxe/timer.h>
  30. /** @file
  31. *
  32. * Time commands
  33. *
  34. */
  35. /** "time" options */
  36. struct time_options {};
  37. /** "time" option list */
  38. static struct option_descriptor time_opts[] = {};
  39. /** "time" command descriptor */
  40. static struct command_descriptor time_cmd =
  41. COMMAND_DESC ( struct time_options, time_opts, 1, MAX_ARGUMENTS,
  42. "<command>" );
  43. /**
  44. * "time" command
  45. *
  46. * @v argc Argument count
  47. * @v argv Argument list
  48. * @ret rc Return status code
  49. */
  50. static int time_exec ( int argc, char **argv ) {
  51. struct time_options opts;
  52. unsigned long start;
  53. unsigned long elapsed;
  54. int decisecs;
  55. int rc;
  56. /* Parse options */
  57. if ( ( rc = parse_options ( argc, argv, &time_cmd, &opts ) ) != 0 )
  58. return rc;
  59. start = currticks();
  60. rc = execv ( argv[1], argv + 1 );
  61. elapsed = ( currticks() - start );
  62. decisecs = ( 10 * elapsed / TICKS_PER_SEC );
  63. printf ( "%s: %d.%ds\n", argv[0],
  64. ( decisecs / 10 ), ( decisecs % 10 ) );
  65. return rc;
  66. }
  67. /** "time" command */
  68. struct command time_command __command = {
  69. .name = "time",
  70. .exec = time_exec,
  71. };