Browse Source

[time] Add the time command

Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v0.9.8
Daniel Verkamp 16 years ago
parent
commit
4397a2a4ca
3 changed files with 58 additions and 0 deletions
  1. 1
    0
      src/config/general.h
  2. 3
    0
      src/core/config.c
  3. 54
    0
      src/hci/commands/time_cmd.c

+ 1
- 0
src/config/general.h View File

@@ -101,6 +101,7 @@
101 101
 #define DHCP_CMD		/* DHCP management commands */
102 102
 #define SANBOOT_CMD		/* SAN boot commands */
103 103
 #define LOGIN_CMD		/* Login command */
104
+#undef	TIME_CMD		/* Time command */
104 105
 
105 106
 /*
106 107
  * Obscure configuration options

+ 3
- 0
src/core/config.c View File

@@ -196,6 +196,9 @@ REQUIRE_OBJECT ( sanboot_cmd );
196 196
 #ifdef LOGIN_CMD
197 197
 REQUIRE_OBJECT ( login_cmd );
198 198
 #endif
199
+#ifdef TIME_CMD
200
+REQUIRE_OBJECT ( time_cmd );
201
+#endif
199 202
 
200 203
 /*
201 204
  * Drag in miscellaneous objects

+ 54
- 0
src/hci/commands/time_cmd.c View File

@@ -0,0 +1,54 @@
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <stdio.h>
20
+#include <string.h>
21
+#include <unistd.h>
22
+#include <gpxe/command.h>
23
+#include <gpxe/timer.h>
24
+
25
+static int time_exec ( int argc, char **argv ) {
26
+	unsigned long start;
27
+	int rc, secs;
28
+
29
+	if ( argc == 1 ||
30
+	     !strcmp ( argv[1], "--help" ) ||
31
+	     !strcmp ( argv[1], "-h" ) )
32
+	{
33
+		printf ( "Usage:\n"
34
+			 "  %s <command>\n"
35
+			 "\n"
36
+			 "Time a command\n",
37
+			 argv[0] );
38
+		return 1;
39
+	}
40
+
41
+	start = currticks();
42
+	rc = execv ( argv[1], argv + 1 );
43
+	secs = (currticks() - start) / ticks_per_sec();
44
+
45
+	printf ( "%s: %ds\n", argv[0], secs );
46
+
47
+	return rc;
48
+}
49
+
50
+struct command time_command __command = {
51
+	.name = "time",
52
+	.exec = time_exec,
53
+};
54
+

Loading…
Cancel
Save