time_cmd.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <unistd.h>
00026 #include <gpxe/command.h>
00027 #include <gpxe/nap.h>
00028 #include <gpxe/timer.h>
00029
00030 static int time_exec ( int argc, char **argv ) {
00031 unsigned long start;
00032 int rc, secs;
00033
00034 if ( argc == 1 ||
00035 !strcmp ( argv[1], "--help" ) ||
00036 !strcmp ( argv[1], "-h" ) )
00037 {
00038 printf ( "Usage:\n"
00039 " %s <command>\n"
00040 "\n"
00041 "Time a command\n",
00042 argv[0] );
00043 return 1;
00044 }
00045
00046 start = currticks();
00047 rc = execv ( argv[1], argv + 1 );
00048 secs = (currticks() - start) / ticks_per_sec();
00049
00050 printf ( "%s: %ds\n", argv[0], secs );
00051
00052 return rc;
00053 }
00054
00055 struct command time_command __command = {
00056 .name = "time",
00057 .exec = time_exec,
00058 };
00059
00060 static int sleep_exec ( int argc, char **argv ) {
00061 unsigned long start, delay;
00062
00063 if ( argc == 1 ||
00064 !strcmp ( argv[1], "--help" ) ||
00065 !strcmp ( argv[1], "-h" ))
00066 {
00067 printf ( "Usage:\n"
00068 " %s <seconds>\n"
00069 "\n"
00070 "Sleep for <seconds> seconds\n",
00071 argv[0] );
00072 return 1;
00073 }
00074 start = currticks();
00075 delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
00076 while ( ( currticks() - start ) <= delay )
00077 cpu_nap();
00078 return 0;
00079 }
00080
00081 struct command sleep_command __command = {
00082 .name = "sleep",
00083 .exec = sleep_exec,
00084 };