Added logfile hash to statistics footer
authorClifford Wolf <clifford@clifford.at>
Fri, 1 Aug 2014 17:43:28 +0000 (19:43 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 1 Aug 2014 17:43:28 +0000 (19:43 +0200)
kernel/driver.cc
kernel/log.cc
kernel/log.h
kernel/yosys.cc
kernel/yosys.h

index 273be7ce1c74e266e0b230fd5513b5d2e35912a4..6f97642381b8dcbcb018bd9d9388442c6750c915 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "kernel/yosys.h"
+#include "libs/sha1/sha1.h"
 
 #include <readline/readline.h>
 #include <readline/history.h>
@@ -233,6 +234,9 @@ int main(int argc, char **argv)
                log("\n");
        }
 
+       if (print_stats)
+               log_hasher = new SHA1;
+
        yosys_setup();
 
        if (optind == argc && passes_commands.size() == 0 && scriptfile.empty()) {
@@ -262,43 +266,18 @@ int main(int argc, char **argv)
        if (!backend_command.empty())
                run_backend(output_filename, backend_command, yosys_design);
 
-       delete yosys_design;
-       yosys_design = NULL;
-
-#ifdef COVER_ACTIVE
-       if (getenv("YOSYS_COVER_DIR") || getenv("YOSYS_COVER_FILE"))
-       {
-               char filename_buffer[4096];
-               FILE *f;
-
-               if (getenv("YOSYS_COVER_DIR")) {
-                       snprintf(filename_buffer, 4096, "%s/yosys_cover_%d_XXXXXX.txt", getenv("YOSYS_COVER_DIR"), getpid());
-                       f = fdopen(mkstemps(filename_buffer, 4), "w");
-               } else {
-                       snprintf(filename_buffer, 4096, "%s", getenv("YOSYS_COVER_FILE"));
-                       f = fopen(filename_buffer, "a+");
-               }
-
-               if (f == NULL)
-                       log_error("Can't create coverage file `%s'.\n", filename_buffer);
-
-               log("<writing coverage file \"%s\">\n", filename_buffer);
-
-               for (auto &it : get_coverage_data())
-                       fprintf(f, "%-60s %10d %s\n", it.second.first.c_str(), it.second.second, it.first.c_str());
-
-               fclose(f);
-       }
-#endif
-
        if (print_stats)
        {
+               std::string hash = log_hasher->final().substr(0, 10);
+               delete log_hasher;
+               log_hasher = nullptr;
+
                struct rusage ru_buffer;
                getrusage(RUSAGE_SELF, &ru_buffer);
-               log("\nEnd of script. Logfile hash: xxxxxxxxxx, CPU: user %.2fs system %.2fs\n",
+               log("\nEnd of script. Logfile hash: %s, CPU: user %.2fs system %.2fs\n", hash.c_str(),
                                ru_buffer.ru_utime.tv_sec + 1e-6 * ru_buffer.ru_utime.tv_usec,
                                ru_buffer.ru_stime.tv_sec + 1e-6 * ru_buffer.ru_stime.tv_usec);
-               log("%s\nTime spent:", yosys_version_str);
+               log("%s\n", yosys_version_str);
 
                int64_t total_ns = 0;
                std::set<std::tuple<int64_t, int, std::string>> timedat;
@@ -310,6 +289,7 @@ int main(int argc, char **argv)
                        }
 
                int out_count = 0;
+               log("Time spent:");
                for (auto it = timedat.rbegin(); it != timedat.rend() && out_count < 4; it++, out_count++) {
                        if (out_count >= 2 && (std::get<0>(*it) < 1000000000 || int(100*std::get<0>(*it) / total_ns) < 20)) {
                                log(", ...");
@@ -321,6 +301,32 @@ int main(int argc, char **argv)
                log("%s\n", out_count ? "" : " no commands executed");
        }
 
+#ifdef COVER_ACTIVE
+       if (getenv("YOSYS_COVER_DIR") || getenv("YOSYS_COVER_FILE"))
+       {
+               char filename_buffer[4096];
+               FILE *f;
+
+               if (getenv("YOSYS_COVER_DIR")) {
+                       snprintf(filename_buffer, 4096, "%s/yosys_cover_%d_XXXXXX.txt", getenv("YOSYS_COVER_DIR"), getpid());
+                       f = fdopen(mkstemps(filename_buffer, 4), "w");
+               } else {
+                       snprintf(filename_buffer, 4096, "%s", getenv("YOSYS_COVER_FILE"));
+                       f = fopen(filename_buffer, "a+");
+               }
+
+               if (f == NULL)
+                       log_error("Can't create coverage file `%s'.\n", filename_buffer);
+
+               log("<writing coverage file \"%s\">\n", filename_buffer);
+
+               for (auto &it : get_coverage_data())
+                       fprintf(f, "%-60s %10d %s\n", it.second.first.c_str(), it.second.second, it.first.c_str());
+
+               fclose(f);
+       }
+#endif
+
        if (call_abort)
                abort();
 
index 64dd7a92a850ce3ca2a6dd975e6ee7411ebfc65c..10eb2563c5571f9466b17abf3f5955aa7f3521f6 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "kernel/yosys.h"
+#include "libs/sha1/sha1.h"
 #include "backends/ilang/ilang_backend.h"
 
 #include <sys/time.h>
@@ -32,6 +33,8 @@ YOSYS_NAMESPACE_BEGIN
 
 std::vector<FILE*> log_files;
 FILE *log_errfile = NULL;
+SHA1 *log_hasher = NULL;
+
 bool log_time = false;
 bool log_cmd_error_throw = false;
 int log_verbose_level;
@@ -44,11 +47,20 @@ static bool next_print_log = false;
 
 void logv(const char *format, va_list ap)
 {
-       if (log_time) {
-               while (format[0] == '\n' && format[1] != 0) {
-                       format++;
-                       log("\n");
-               }
+       while (format[0] == '\n' && format[1] != 0) {
+               log("\n");
+               format++;
+       }
+
+       std::string str = vstringf(format, ap);
+
+       if (log_hasher)
+               log_hasher->update(str);
+
+       if (log_time)
+       {
+               std::string time_str;
+
                if (next_print_log || initial_tv.tv_sec == 0) {
                        next_print_log = false;
                        struct timeval tv;
@@ -61,18 +73,18 @@ void logv(const char *format, va_list ap)
                        }
                        tv.tv_sec -= initial_tv.tv_sec;
                        tv.tv_usec -= initial_tv.tv_usec;
-                       log("[%05d.%06d] ", int(tv.tv_sec), int(tv.tv_usec));
+                       time_str += stringf("[%05d.%06d] ", int(tv.tv_sec), int(tv.tv_usec));
                }
+
                if (format[0] && format[strlen(format)-1] == '\n')
                        next_print_log = true;
-       }
 
-       for (auto f : log_files) {
-               va_list aq;
-               va_copy(aq, ap);
-               vfprintf(f, format, aq);
-               va_end(aq);
+               for (auto f : log_files)
+                       fputs(time_str.c_str(), f);
        }
+
+       for (auto f : log_files)
+               fputs(str.c_str(), f);
 }
 
 void logv_header(const char *format, va_list ap)
index 8e46ad493acdeecbdb020489f7136886b53db6d8..2e968039ff4d4554ac3f780356f4bc29eb87ee40 100644 (file)
@@ -38,6 +38,8 @@ struct log_cmd_error_expection { };
 
 extern std::vector<FILE*> log_files;
 extern FILE *log_errfile;
+extern class SHA1 *log_hasher;
+
 extern bool log_time;
 extern bool log_cmd_error_throw;
 extern int log_verbose_level;
index 6719456312259b1a3d046e2371f909bb5f94fa96..89a9cdf7f36cea8f1d7dac99a11403d383b0ef97 100644 (file)
@@ -37,13 +37,22 @@ Tcl_Interp *yosys_tcl_interp = NULL;
 std::string stringf(const char *fmt, ...)
 {
        std::string string;
-       char *str = NULL;
        va_list ap;
 
        va_start(ap, fmt);
+       string = vstringf(fmt, ap);
+       va_end(ap);
+
+       return string;
+}
+
+std::string vstringf(const char *fmt, va_list ap)
+{
+       std::string string;
+       char *str = NULL;
+
        if (vasprintf(&str, fmt, ap) < 0)
                str = NULL;
-       va_end(ap);
 
        if (str != NULL) {
                string = str;
@@ -71,6 +80,9 @@ void yosys_shutdown()
 {
        log_pop();
 
+       delete yosys_design;
+       yosys_design = NULL;
+
        for (auto f : log_files)
                if (f != stderr)
                        fclose(f);
index d9db57c5162384549838a9900a8bf53ca6d8e3de..e90dcc46e4768c1b2e3127e5d9d87e07797b2260 100644 (file)
@@ -43,6 +43,7 @@
 #include <string>
 #include <algorithm>
 #include <initializer_list>
+#include <stdarg.h>
 
 #define PRIVATE_NAMESPACE_BEGIN  namespace {
 #define PRIVATE_NAMESPACE_END    }
@@ -68,6 +69,7 @@ namespace RTLIL {
 }
 
 std::string stringf(const char *fmt, ...);
+std::string vstringf(const char *fmt, va_list ap);
 template<typename T> int SIZE(const T &obj) { return obj.size(); }
 int SIZE(RTLIL::Wire *wire);