OrionUserland
Barry Importing existing Orion Userland 19aefaa (2 years, 4 months ago)diff --git a/time/Makefile b/time/Makefile new file mode 100644 index 0000000..5254c7c --- /dev/null +++ b/time/Makefile @@ -0,0 +1,46 @@ +PRODUCT=$(notdir $(abspath $(CURDIR))) + +CC=i686-orion-gcc +CFLAGS= + +AS=i686-orion-as +AFLAGS= + +LD=i686-orion-gcc +LFLAGS= + +AS_SOURCES := $(shell find . -name '*.S') +OBJS = $(sort $(subst ./,build/,$(subst .S,.o,$(AS_SOURCES)))) + +C_SOURCES := $(shell find . -name '*.c') +OBJS += $(sort $(subst ./,build/,$(subst .c,.o,$(C_SOURCES)))) + +.PHONY: clean all install + +all: $(PRODUCT) + +clean: + @echo "REMOVING OBJECT FILES" + @mkdir -p build + @rm -rf build + @touch $(PRODUCT) + @rm $(PRODUCT) + +install: $(PRODUCT) + @echo "INSTALLING $^" + @mkdir -p ${SYSROOT}/bin/ + @install -Dm 755 $(PRODUCT) -t ${SYSROOT}/bin/ + +$(PRODUCT): $(OBJS) + @echo "LINKING $@" + @$(LD) -o $@ $^ $(LFLAGS) + +build/%.o: %.c + @echo "COMPILING $<" + @mkdir -p $(@D) + @$(CC) -c $< -o $@ $(CFLAGS) + +build/%.o: %.S + @echo "ASSEMBLING $<" + @mkdir -p $(@D) + @$(AS) $< -o $@ $(AFLAGS) diff --git a/time/main.c b/time/main.c new file mode 100644 index 0000000..89ef9ab --- /dev/null +++ b/time/main.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/times.h> +#include <sys/wait.h> +#include <errno.h> + +/* Main function */ +int +main(int argc, char *argv[]) +{ + pid_t pid; + Times tms; + clock_t r0, r1; + int status, ret = 0; + + if (argc < 2) + return 0; + + r0 = times(&tms); + + pid = fork(); + if (!pid) { + execv(argv[1], argv + 1); + printf("exec: %s: ", argv[1]); + perror(NULL); + exit(EXIT_FAILURE); + } + waitpid(pid, &status, 0); + + if ((r1 = times(&tms)) == (clock_t) -1) { + perror("times"); + exit(EXIT_FAILURE); + } + + printf("\nreal %dms\nuser %dms\nsys %dms\n", + (r1 - r0), tms.cutime, tms.cstime); +// printf("\nreal %f\nuser %f\nsys %f\n", +// (r1 - r0) / (double) 1000, +// tms.cutime / (double) 1000, +// tms.cstime / (double) 1000); + + return 0; +} diff --git a/time/time b/time/time new file mode 100755 index 0000000..cf03725 Binary files /dev/null and b/time/time differ