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
23FILE_LICENCE ( GPL2_OR_LATER );
24FILE_SECBOOT ( PERMITTED );
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <unistd.h>
30#include <ipxe/command.h>
31#include <ipxe/parseopt.h>
32#include <ipxe/timer.h>
33
34/** @file
35 *
36 * Time commands
37 *
38 */
39
40/** "time" options */
41struct time_options {};
42
43/** "time" option list */
44static struct option_descriptor time_opts[] = {};
45
46/** "time" command descriptor */
49 "<command>" );
50
51/**
52 * "time" command
53 *
54 * @v argc Argument count
55 * @v argv Argument list
56 * @ret rc Return status code
57 */
58static int time_exec ( int argc, char **argv ) {
59 struct time_options opts;
60 unsigned long start;
61 unsigned long elapsed;
62 int decisecs;
63 int rc;
64
65 /* Parse options */
66 if ( ( rc = parse_options ( argc, argv, &time_cmd, &opts ) ) != 0 )
67 return rc;
68
69 start = currticks();
70 rc = execv ( argv[1], argv + 1 );
71 elapsed = ( currticks() - start );
72 decisecs = ( 10 * elapsed / TICKS_PER_SEC );
73
74 printf ( "%s: %d.%ds\n", argv[0],
75 ( decisecs / 10 ), ( decisecs % 10 ) );
76
77 return rc;
78}
79
80/** "time" command */
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
int execv(const char *command, char *const argv[])
Execute command.
Definition exec.c:61
uint32_t start
Starting offset.
Definition netvsc.h:1
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
iPXE timers
#define TICKS_PER_SEC
Number of ticks per second.
Definition timer.h:16
String functions.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
A command descriptor.
Definition parseopt.h:78
A command-line option descriptor.
Definition parseopt.h:24
"time" options
Definition time_cmd.c:41
static struct option_descriptor time_opts[]
"time" option list
Definition time_cmd.c:44
static int time_exec(int argc, char **argv)
"time" command
Definition time_cmd.c:58
static struct command_descriptor time_cmd
"time" command descriptor
Definition time_cmd.c:47
unsigned long currticks(void)
Get current system time in ticks.
Definition timer.c:43
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465