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
23 FILE_LICENCE ( GPL2_OR_LATER );
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <ipxe/command.h>
30 #include <ipxe/parseopt.h>
31 #include <ipxe/timer.h>
32
33 /** @file
34 *
35 * Time commands
36 *
37 */
38
39 /** "time" options */
40 struct time_options {};
41
42 /** "time" option list */
43 static struct option_descriptor time_opts[] = {};
44
45 /** "time" command descriptor */
46 static struct command_descriptor time_cmd =
47 COMMAND_DESC ( struct time_options, time_opts, 1, MAX_ARGUMENTS,
48 "<command>" );
49
50 /**
51 * "time" command
52 *
53 * @v argc Argument count
54 * @v argv Argument list
55 * @ret rc Return status code
56 */
time_exec(int argc,char ** argv)57 static int time_exec ( int argc, char **argv ) {
58 struct time_options opts;
59 unsigned long start;
60 unsigned long elapsed;
61 int decisecs;
62 int rc;
63
64 /* Parse options */
65 if ( ( rc = parse_options ( argc, argv, &time_cmd, &opts ) ) != 0 )
66 return rc;
67
68 start = currticks();
69 rc = execv ( argv[1], argv + 1 );
70 elapsed = ( currticks() - start );
71 decisecs = ( 10 * elapsed / TICKS_PER_SEC );
72
73 printf ( "%s: %d.%ds\n", argv[0],
74 ( decisecs / 10 ), ( decisecs % 10 ) );
75
76 return rc;
77 }
78
79 /** "time" command */
80 struct command time_command __command = {
81 .name = "time",
82 .exec = time_exec,
83 };
84