add timer to openfpga shell

This commit is contained in:
tangxifan 2020-07-02 18:02:33 -06:00
parent 1c634e4600
commit f97e3bfba6
3 changed files with 14 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <map>
#include <vector>
#include <functional>
#include <ctime>
#include "vtr_vector.h"
#include "vtr_range.h"
@ -211,6 +212,9 @@ class Shell {
std::map<std::string, ShellCommandId> command_name2ids_;
std::map<std::string, ShellCommandClassId> command_class2ids_;
vtr::vector<ShellCommandClassId, std::vector<ShellCommandId>> commands_by_classes_;
/* Timer */
std::clock_t time_start_;
};
} /* End namespace openfpga */

View File

@ -28,6 +28,7 @@ namespace openfpga {
template<class T>
Shell<T>::Shell(const char* name) {
name_ = std::string(name);
time_start_ = 0;
}
/************************************************************************
@ -241,6 +242,9 @@ ShellCommandClassId Shell<T>::add_command_class(const char* name) {
template <class T>
void Shell<T>::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<T>::run_interactive_mode(T& context, const bool& quiet_mode) {
template <class T>
void Shell<T>::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<T>::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());

View File

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