Skip to content

Commit

Permalink
write mining stats to json fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tontechio committed Nov 25, 2021
1 parent abae4e2 commit e445997
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions crypto/util/Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,21 @@ void Miner::write_stats(std::string filename, const ton::Miner::Options &options
if (passed < 1e-9) {
passed = 1;
}
double speed = static_cast<double>(*options.hashes_computed) / passed;
double hashes_computed = options.hashes_computed ? static_cast<double>(*options.hashes_computed) : 0;
double speed = hashes_computed / passed;
std::stringstream ss, ss2;
ss << std::fixed << std::setprecision(3) << speed / 1e+6;

double instant_passed = *options.instant_passed;
double instant_passed = 1;
if (options.instant_passed) {
instant_passed = *options.instant_passed;
}
if (instant_passed < 1e-9) {
instant_passed = 1;
}
double instant_speed = static_cast<double>(*options.instant_hashes_computed) / instant_passed;

double instant_hashes_computed = options.instant_hashes_computed ? static_cast<double>(*options.instant_hashes_computed) : 0;
double instant_speed = instant_hashes_computed / instant_passed;
ss2 << std::fixed << std::setprecision(3) << instant_speed / 1e+6;

td::JsonBuilder jb;
Expand All @@ -135,10 +141,10 @@ void Miner::write_stats(std::string filename, const ton::Miner::Options &options
jo("seed", hex_encode(td::Slice(options.seed.data(), options.seed.size())));
jo("complexity", hex_encode(td::Slice(options.complexity.data(), options.complexity.size())));
jo("passed", std::to_string(passed));
jo("hashes_computed", std::to_string(*options.hashes_computed));
jo("hashes_computed", std::to_string(hashes_computed));
jo("speed", ss.str());
jo("instant_passed", std::to_string(instant_passed));
jo("instant_hashes_computed", std::to_string(*options.instant_hashes_computed));
jo("instant_hashes_computed", std::to_string(instant_hashes_computed));
jo("instant_speed", ss2.str());
jo.leave();
auto s = jb.string_builder().as_cslice();
Expand Down
2 changes: 1 addition & 1 deletion tonlib/tonlib/tonlib-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ class TonlibCli : public td::actor::Actor {
next_options_query_at_ = {};

// show status
if (miner_options_copy_.verbosity >= 2) {
if (miner_options_copy_.verbosity >= 2 && options_.giver_address.address) {
ton::Miner::print_stats("mining in progress", miner_options_copy_.start_at, hashes_computed_,
instant_passed_, instant_hashes_computed_);
ton::Miner::write_stats(options_.statfile, miner_options_copy_,
Expand Down

0 comments on commit e445997

Please sign in to comment.