iPXE
time_cmd.c
Go to the documentation of this file.
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 */
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  */
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 };
static struct command_descriptor time_cmd
"time" command descriptor
Definition: time_cmd.c:46
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct command time_command __command
"time" command
Definition: time_cmd.c:80
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
"time" options
Definition: time_cmd.c:40
A command-line command.
Definition: command.h:9
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
iPXE timers
A command descriptor.
Definition: parseopt.h:77
uint32_t start
Starting offset.
Definition: netvsc.h:12
static struct option_descriptor time_opts[]
"time" option list
Definition: time_cmd.c:43
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
Command line option parsing.
static int time_exec(int argc, char **argv)
"time" command
Definition: time_cmd.c:57
static union @437 opts
"cert<xxx>" option list
const char * name
Name of the command.
Definition: command.h:11
A command-line option descriptor.
Definition: parseopt.h:23
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
FILE_LICENCE(GPL2_OR_LATER)
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
String functions.
int execv(const char *command, char *const argv[])
Execute command.
Definition: exec.c:60