From 82d041d9f7881fa23e2999dad636eedaa20217a5 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 7 Sep 2018 21:50:19 -0400 Subject: create new branch alt-cli --- src/hotstuff_client.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/hotstuff_client.cpp') diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index 62b13ed..31c6c0a 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "salticidae/type.h" #include "salticidae/netaddr.h" #include "salticidae/network.h" @@ -42,6 +43,7 @@ struct Request { std::unordered_map::conn_t> conns; std::unordered_map waiting; std::vector replicas; +std::vector> elapsed; MsgNetwork mn(eb, 10, 10, 4096); void set_proposer(ReplicaID rid) { @@ -97,7 +99,10 @@ void client_resp_cmd_handler(MsgRespCmd &&msg, MsgNetwork::Conn &) { std::string(fin).c_str(), et.elapsed_sec, et.cpu_elapsed_sec); #else - HOTSTUFF_LOG_INFO("%.6f %.6f", et.elapsed_sec, et.cpu_elapsed_sec); + struct timeval tv; + gettimeofday(&tv, nullptr); + elapsed.push_back(std::make_pair(tv, et.elapsed_sec)); + //HOTSTUFF_LOG_INFO("%.6f %.6f", et.elapsed_sec, et.cpu_elapsed_sec); #endif waiting.erase(it); try_send(); @@ -108,8 +113,16 @@ std::pair split_ip_port_cport(const std::string &s) { return std::make_pair(ret[0], ret[1]); } +void signal_handler(int) { + throw HotStuffError("got terminal signal"); +} + int main(int argc, char **argv) { Config config("hotstuff.conf"); + + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + auto opt_idx = Config::OptValInt::create(0); auto opt_replicas = Config::OptValStrVec::create(); auto opt_max_iter_num = Config::OptValInt::create(100); @@ -152,6 +165,13 @@ int main(int argc, char **argv) { eb.dispatch(); } catch (HotStuffError &e) { HOTSTUFF_LOG_ERROR("exception: %s", std::string(e).c_str()); + for (const auto &e: elapsed) + { + char fmt[64]; + struct tm *tmp = localtime(&e.first.tv_sec); + strftime(fmt, sizeof fmt, "%Y-%m-%d %H:%M:%S.%%06u [hotstuff info] %%.6f\n", tmp); + fprintf(stderr, fmt, e.first.tv_usec, e.second); + } } return 0; } -- cgit v1.2.3