diff --git a/Shell/main.cpp b/Shell/main.cpp index 4abdc73165..8c236416f6 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -25,6 +25,8 @@ GlobalState g; static LineEditor editor; +static int run_command(const String&); + static String prompt() { if (g.uid == 0) @@ -133,6 +135,25 @@ static int sh_history(int, char**) return 0; } +static int sh_time(int argc, char** argv) +{ + if (argc == 1) { + printf("usage: time \n"); + return 0; + } + StringBuilder builder; + for (int i = 1; i < argc; ++i) { + builder.append(argv[i]); + if (i != argc - 1) + builder.append(' '); + } + CElapsedTimer timer; + timer.start(); + int exit_code = run_command(builder.to_string()); + printf("Time: %d ms\n", timer.elapsed()); + return exit_code; +} + static int sh_umask(int argc, char** argv) { if (argc == 1) { @@ -392,6 +413,10 @@ static bool handle_builtin(int argc, char** argv, int& retval) retval = sh_popd(argc, argv); return true; } + if (!strcmp(argv[0], "time")) { + retval = sh_time(argc, argv); + return true; + } return false; }