Skip to content

Commit

Permalink
Shell: Disable SH_DEBUG by default and tidy up command timing logging
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Jan 21, 2020
1 parent f38cfb3 commit 41716ae
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <termios.h>
#include <unistd.h>

#define SH_DEBUG
//#define SH_DEBUG

GlobalState g;
static LineEditor editor;
Expand Down Expand Up @@ -301,8 +301,7 @@ static int sh_pushd(int argc, char** argv)
g.directory_stack.append(g.cwd.characters());
if (argv[1][0] == '/') {
path_builder.append(argv[1]);
}
else {
} else {
path_builder.appendf("%s/%s", g.cwd.characters(), argv[1]);
}
} else if (argc == 3) {
Expand All @@ -313,8 +312,7 @@ static int sh_pushd(int argc, char** argv)
if (arg[0] != '-') {
if (arg[0] == '/') {
path_builder.append(arg);
}
else
} else
path_builder.appendf("%s/%s", g.cwd.characters(), arg);
}

Expand Down Expand Up @@ -468,17 +466,21 @@ class FileDescriptionCollector {
Vector<int, 32> m_fds;
};

struct CommandTimer {
CommandTimer()
class CommandTimer {
public:
explicit CommandTimer(const String& command)
: m_command(command)
{
timer.start();
m_timer.start();
}
~CommandTimer()
{
dbgprintf("sh: command finished in %d ms\n", timer.elapsed());
dbg() << "Command \"" << m_command << "\" finished in " << m_timer.elapsed() << " ms";
}

CElapsedTimer timer;
private:
CElapsedTimer m_timer;
String m_command;
};

static bool is_glob(const StringView& s)
Expand Down Expand Up @@ -733,7 +735,7 @@ static int run_command(const String& cmd)

Vector<SpawnedProcess> children;

CommandTimer timer;
CommandTimer timer(cmd);

for (int i = 0; i < command.subcommands.size(); ++i) {
auto& subcommand = command.subcommands[i];
Expand Down

0 comments on commit 41716ae

Please sign in to comment.