|  | @@ -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 | +
 |