From f97e3bfba62583a2c177fec882b30a2b879d7519 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Thu, 2 Jul 2020 18:02:33 -0600 Subject: [PATCH] add timer to openfpga shell --- libopenfpga/libopenfpgashell/src/shell.h | 4 ++++ libopenfpga/libopenfpgashell/src/shell.tpp | 9 +++++++++ openfpga/src/main.cpp | 3 +-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libopenfpga/libopenfpgashell/src/shell.h b/libopenfpga/libopenfpgashell/src/shell.h index 1a49b313c..67dd4356d 100644 --- a/libopenfpga/libopenfpgashell/src/shell.h +++ b/libopenfpga/libopenfpgashell/src/shell.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "vtr_vector.h" #include "vtr_range.h" @@ -211,6 +212,9 @@ class Shell { std::map command_name2ids_; std::map command_class2ids_; vtr::vector> commands_by_classes_; + + /* Timer */ + std::clock_t time_start_; }; } /* End namespace openfpga */ diff --git a/libopenfpga/libopenfpgashell/src/shell.tpp b/libopenfpga/libopenfpgashell/src/shell.tpp index 219287ee1..7c0ff7ce6 100644 --- a/libopenfpga/libopenfpgashell/src/shell.tpp +++ b/libopenfpga/libopenfpgashell/src/shell.tpp @@ -28,6 +28,7 @@ namespace openfpga { template Shell::Shell(const char* name) { name_ = std::string(name); + time_start_ = 0; } /************************************************************************ @@ -241,6 +242,9 @@ ShellCommandClassId Shell::add_command_class(const char* name) { template void Shell::run_interactive_mode(T& context, const bool& quiet_mode) { if (false == quiet_mode) { + /* Reset timer since it does not come from another mode */ + time_start_ = std::clock(); + VTR_LOG("Start interactive mode of %s...\n", name().c_str()); @@ -270,6 +274,8 @@ void Shell::run_interactive_mode(T& context, const bool& quiet_mode) { template void Shell::run_script_mode(const char* script_file_name, T& context) { + time_start_ = std::clock(); + VTR_LOG("Reading script file %s...\n", script_file_name); /* Print the title of the shell */ @@ -419,6 +425,9 @@ void Shell::exit() const { VTR_LOG("\nFinish execution with %d errors\n", num_err); + VTR_LOG("\nThe entire OpenFPGA flow took %g seconds\n", + (double)(std::clock() - time_start_) / (double)CLOCKS_PER_SEC); + VTR_LOG("\nThank you for using %s!\n", name().c_str()); diff --git a/openfpga/src/main.cpp b/openfpga/src/main.cpp index e1f813e9b..9f332263c 100644 --- a/openfpga/src/main.cpp +++ b/openfpga/src/main.cpp @@ -25,6 +25,7 @@ * Main function to start OpenFPGA shell interface *******************************************************************/ int main(int argc, char** argv) { + /* Create the command to launch shell in different modes */ openfpga::Command start_cmd("OpenFPGA"); /* Add two options: @@ -89,13 +90,11 @@ int main(int argc, char** argv) { /* Parse succeed. Start a shell */ if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) { - vtr::ScopedStartFinishTimer timer("OpenFPGA operating"); shell.run_interactive_mode(openfpga_context); return 0; } if (true == start_cmd_context.option_enable(start_cmd, opt_script_mode)) { - vtr::ScopedStartFinishTimer timer("OpenFPGA operating"); shell.run_script_mode(start_cmd_context.option_value(start_cmd, opt_script_mode).c_str(), openfpga_context); return 0;