Skip to content

Commit

Permalink
Merge pull request #96 from tontechio/develop
Browse files Browse the repository at this point in the history
mining json stats fix
  • Loading branch information
tontechio authored Nov 25, 2021
2 parents b61a1d6 + e445997 commit b39a599
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 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
4 changes: 2 additions & 2 deletions crypto/util/opencl/opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void OpenCL::set_source(unsigned char *source, unsigned int length) {
}
}

void OpenCL::print_devices(bool count) {
void OpenCL::print_devices() {
cl_int cl_err = CL_SUCCESS;

// platform
Expand All @@ -59,7 +59,7 @@ void OpenCL::print_devices(bool count) {
CL_WRAPPER(clGetDeviceIDs(platforms_[p], CL_DEVICE_TYPE_ALL, device_count_, devices_, NULL));
for (uint i = 0; i < device_count_; i++) {
CL_WRAPPER(clGetDeviceInfo(devices_[i], CL_DEVICE_NAME, sizeof(buf), buf, NULL));
if (!count && GET_VERBOSITY_LEVEL() >= VERBOSITY_NAME(INFO)) {
if (GET_VERBOSITY_LEVEL() >= VERBOSITY_NAME(INFO)) {
LOG(PLAIN) << "[ OpenCL: platform #" << p << " device #" << i << " " << buf << " ]";
}
num_devices_++;
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/opencl/opencl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OpenCL {
OpenCL() = default;
void load_source(const char *filename);
void set_source(unsigned char *source, unsigned int length);
void print_devices(bool count = false);
void print_devices();
int get_num_devices();
void create_context(cl_uint platform_idx, cl_uint device_idx);
void create_kernel();
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/pow-miner-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ It will save the data in the following format:
{"timestamp":"1637264251.112240","giver":"Ef-FV4QTxLl-7Ct3E6MqOtMt-RGXMxi27g4I645lw6MTWg0f","seed":"B2A077AA6FCFE63FB0C8AAAEE1397A49","complexity":"000000000000E3C331D02EA44D1582443748E77D3997E69B37C5FD95D818D972","passed":"44.829463","hashes_computed":"13740539904","speed":"306.507","instant_passed":"4.981751","instant_hashes_computed":"1275068416","instant_speed":"255.948"}
```

Log rotation is an automated process. To force rotate logs send the HANGUP to the tonlib-*-cli process. Log rotate threshold is 1Mb.
Log rotation is an automated process. To force rotate logs send the HANGUP to the tonlib-*-cli process. Log rotate threshold is 1MB.

## TONLIB CLI automation

Expand Down
2 changes: 1 addition & 1 deletion crypto/util/pow-miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ int main(int argc, char* const argv[]) {

#if defined MINEROPENCL
auto opencl = opencl::OpenCL();
opencl.print_devices(true);
opencl.print_devices();
if (opencl.get_num_devices() == 0) {
std::cerr << "No OpenCL-capable devices is detected!" << std::endl;
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -2698,7 +2698,7 @@ int main(int argc, char* argv[]) {
});
p.add_option('l', "logname", "log to file", [&](td::Slice fname) {
options.logfile = fname.str();
// 1 Mb log threshold
// 1MB log threshold
logger_ = td::TsFileLog::create(fname.str(), 1 * (1 << 20), true, true).move_as_ok();
td::set_signal_handler(td::SignalType::HangUp, force_rotate_logs).ensure();
td::log_interface = logger_.get();
Expand Down

0 comments on commit b39a599

Please sign in to comment.