mirror of https://github.com/YosysHQ/yosys.git
Added logfile hash to statistics footer
This commit is contained in:
parent
bd74ed7da4
commit
75ffd1643c
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kernel/yosys.h"
|
#include "kernel/yosys.h"
|
||||||
|
#include "libs/sha1/sha1.h"
|
||||||
|
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
@ -233,6 +234,9 @@ int main(int argc, char **argv)
|
||||||
log("\n");
|
log("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (print_stats)
|
||||||
|
log_hasher = new SHA1;
|
||||||
|
|
||||||
yosys_setup();
|
yosys_setup();
|
||||||
|
|
||||||
if (optind == argc && passes_commands.size() == 0 && scriptfile.empty()) {
|
if (optind == argc && passes_commands.size() == 0 && scriptfile.empty()) {
|
||||||
|
@ -262,8 +266,40 @@ int main(int argc, char **argv)
|
||||||
if (!backend_command.empty())
|
if (!backend_command.empty())
|
||||||
run_backend(output_filename, backend_command, yosys_design);
|
run_backend(output_filename, backend_command, yosys_design);
|
||||||
|
|
||||||
delete yosys_design;
|
if (print_stats)
|
||||||
yosys_design = NULL;
|
{
|
||||||
|
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: %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\n", yosys_version_str);
|
||||||
|
|
||||||
|
int64_t total_ns = 0;
|
||||||
|
std::set<std::tuple<int64_t, int, std::string>> timedat;
|
||||||
|
|
||||||
|
for (auto &it : pass_register)
|
||||||
|
if (it.second->call_counter) {
|
||||||
|
total_ns += it.second->runtime_ns + 1;
|
||||||
|
timedat.insert(make_tuple(it.second->runtime_ns + 1, it.second->call_counter, it.first));
|
||||||
|
}
|
||||||
|
|
||||||
|
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(", ...");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log("%s %d%% %dx %s (%d sec)", out_count ? "," : "", int(100*std::get<0>(*it) / total_ns),
|
||||||
|
std::get<1>(*it), std::get<2>(*it).c_str(), int(std::get<0>(*it) / 1000000000));
|
||||||
|
}
|
||||||
|
log("%s\n", out_count ? "" : " no commands executed");
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef COVER_ACTIVE
|
#ifdef COVER_ACTIVE
|
||||||
if (getenv("YOSYS_COVER_DIR") || getenv("YOSYS_COVER_FILE"))
|
if (getenv("YOSYS_COVER_DIR") || getenv("YOSYS_COVER_FILE"))
|
||||||
|
@ -291,36 +327,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (print_stats)
|
|
||||||
{
|
|
||||||
struct rusage ru_buffer;
|
|
||||||
getrusage(RUSAGE_SELF, &ru_buffer);
|
|
||||||
log("\nEnd of script. Logfile hash: xxxxxxxxxx, CPU: user %.2fs system %.2fs\n",
|
|
||||||
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);
|
|
||||||
|
|
||||||
int64_t total_ns = 0;
|
|
||||||
std::set<std::tuple<int64_t, int, std::string>> timedat;
|
|
||||||
|
|
||||||
for (auto &it : pass_register)
|
|
||||||
if (it.second->call_counter) {
|
|
||||||
total_ns += it.second->runtime_ns + 1;
|
|
||||||
timedat.insert(make_tuple(it.second->runtime_ns + 1, it.second->call_counter, it.first));
|
|
||||||
}
|
|
||||||
|
|
||||||
int out_count = 0;
|
|
||||||
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(", ...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
log("%s %d%% %dx %s (%d sec)", out_count ? "," : "", int(100*std::get<0>(*it) / total_ns),
|
|
||||||
std::get<1>(*it), std::get<2>(*it).c_str(), int(std::get<0>(*it) / 1000000000));
|
|
||||||
}
|
|
||||||
log("%s\n", out_count ? "" : " no commands executed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (call_abort)
|
if (call_abort)
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kernel/yosys.h"
|
#include "kernel/yosys.h"
|
||||||
|
#include "libs/sha1/sha1.h"
|
||||||
#include "backends/ilang/ilang_backend.h"
|
#include "backends/ilang/ilang_backend.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -32,6 +33,8 @@ YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
std::vector<FILE*> log_files;
|
std::vector<FILE*> log_files;
|
||||||
FILE *log_errfile = NULL;
|
FILE *log_errfile = NULL;
|
||||||
|
SHA1 *log_hasher = NULL;
|
||||||
|
|
||||||
bool log_time = false;
|
bool log_time = false;
|
||||||
bool log_cmd_error_throw = false;
|
bool log_cmd_error_throw = false;
|
||||||
int log_verbose_level;
|
int log_verbose_level;
|
||||||
|
@ -44,11 +47,20 @@ static bool next_print_log = false;
|
||||||
|
|
||||||
void logv(const char *format, va_list ap)
|
void logv(const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
if (log_time) {
|
|
||||||
while (format[0] == '\n' && format[1] != 0) {
|
while (format[0] == '\n' && format[1] != 0) {
|
||||||
format++;
|
|
||||||
log("\n");
|
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) {
|
if (next_print_log || initial_tv.tv_sec == 0) {
|
||||||
next_print_log = false;
|
next_print_log = false;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -61,18 +73,18 @@ void logv(const char *format, va_list ap)
|
||||||
}
|
}
|
||||||
tv.tv_sec -= initial_tv.tv_sec;
|
tv.tv_sec -= initial_tv.tv_sec;
|
||||||
tv.tv_usec -= initial_tv.tv_usec;
|
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) {
|
if (format[0] && format[strlen(format)-1] == '\n')
|
||||||
va_list aq;
|
next_print_log = true;
|
||||||
va_copy(aq, ap);
|
|
||||||
vfprintf(f, format, aq);
|
for (auto f : log_files)
|
||||||
va_end(aq);
|
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)
|
void logv_header(const char *format, va_list ap)
|
||||||
|
|
|
@ -38,6 +38,8 @@ struct log_cmd_error_expection { };
|
||||||
|
|
||||||
extern std::vector<FILE*> log_files;
|
extern std::vector<FILE*> log_files;
|
||||||
extern FILE *log_errfile;
|
extern FILE *log_errfile;
|
||||||
|
extern class SHA1 *log_hasher;
|
||||||
|
|
||||||
extern bool log_time;
|
extern bool log_time;
|
||||||
extern bool log_cmd_error_throw;
|
extern bool log_cmd_error_throw;
|
||||||
extern int log_verbose_level;
|
extern int log_verbose_level;
|
||||||
|
|
|
@ -37,13 +37,22 @@ Tcl_Interp *yosys_tcl_interp = NULL;
|
||||||
std::string stringf(const char *fmt, ...)
|
std::string stringf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
std::string string;
|
std::string string;
|
||||||
char *str = NULL;
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
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)
|
if (vasprintf(&str, fmt, ap) < 0)
|
||||||
str = NULL;
|
str = NULL;
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
string = str;
|
string = str;
|
||||||
|
@ -71,6 +80,9 @@ void yosys_shutdown()
|
||||||
{
|
{
|
||||||
log_pop();
|
log_pop();
|
||||||
|
|
||||||
|
delete yosys_design;
|
||||||
|
yosys_design = NULL;
|
||||||
|
|
||||||
for (auto f : log_files)
|
for (auto f : log_files)
|
||||||
if (f != stderr)
|
if (f != stderr)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define PRIVATE_NAMESPACE_BEGIN namespace {
|
#define PRIVATE_NAMESPACE_BEGIN namespace {
|
||||||
#define PRIVATE_NAMESPACE_END }
|
#define PRIVATE_NAMESPACE_END }
|
||||||
|
@ -68,6 +69,7 @@ namespace RTLIL {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stringf(const char *fmt, ...);
|
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(); }
|
template<typename T> int SIZE(const T &obj) { return obj.size(); }
|
||||||
int SIZE(RTLIL::Wire *wire);
|
int SIZE(RTLIL::Wire *wire);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue