time_cmd.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gpxe/command.h>
#include <gpxe/nap.h>
#include <gpxe/timer.h>

Go to the source code of this file.

Functions

static int time_exec (int argc, char **argv)
static int sleep_exec (int argc, char **argv)

Variables

struct command time_command __command


Function Documentation

static int time_exec ( int  argc,
char **  argv 
) [static]

Definition at line 30 of file time_cmd.c.

References currticks(), execv(), printf(), strcmp(), and ticks_per_sec().

00030                                                {
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 }

static int sleep_exec ( int  argc,
char **  argv 
) [static]

Definition at line 60 of file time_cmd.c.

References cpu_nap(), currticks(), delay, NULL, printf(), strcmp(), strtoul(), and ticks_per_sec().

00060                                                 {
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 }


Variable Documentation

struct command sleep_command __command [read]

Initial value:

 {
        .name = "time",
        .exec = time_exec,
}

Definition at line 55 of file time_cmd.c.


Generated on Tue Apr 6 20:01:46 2010 for gPXE by  doxygen 1.5.7.1