std::string LogHelper::formatStatus()

in recipes/local_prior_match/src/runtime/Logging.cpp [148:234]


std::string LogHelper::formatStatus(
    SSLTrainMeters& meters,
    int64_t epoch,
    const std::unordered_map<std::string, double>& logFields,
    bool verbose /* = false */,
    bool date /* = false */,
    const std::string& separator /* = " " */,
    bool headerOnly /* = false */) {
  std::string header, status;

  auto insertItem = [&](std::string key, std::string val) {
    if (verbose) {
      val = key + ": " + val;
    }
    header = header + (header.empty() ? "" : separator) + key;
    status = status + (status.empty() ? "" : separator) + val;
  };

  auto insertSSLDatasetMeters = [&insertItem](
                                    SSLDatasetMeters& meter, std::string tag) {
    for (auto& m : meter.values) {
      insertItem(tag + "-" + m.first, format("%10.5f", m.second.value()[0]));
    }
    for (auto& m : meter.edits) {
      insertItem(
          tag + "-" + m.first + "ER", format("%5.2f", m.second.value()[0]));
    }
  };

  if (date) {
    insertItem("date", format("%s", getCurrentDate().c_str()));
    insertItem("time", format("%s", getCurrentTime().c_str()));
  }

  if (logOnEpoch_) {
    insertItem("epoch", format("%8d", epoch));
  } else {
    insertItem("iter", format("%8d", epoch));
  }

  insertItem("lr", headerOnly ? "" : format("%4.6lf", logFields.at("lr")));

  int rt = meters.timer[kRuntime].value();
  insertItem(
      kRuntime,
      format("%02d:%02d:%02d", (rt / 60 / 60), (rt / 60) % 60, rt % 60));

  for (auto& m : meters.timer) {
    if (m.first == kRuntime) {
      continue;
    }
    insertItem(m.first + "(ms)", format("%.2f", m.second.value() * 1000));
  }

  for (auto& m : meters.values) {
    insertItem("train-" + m.first, format("%10.5f", m.second.value()[0]));
  }

  insertSSLDatasetMeters(meters.train, "train");
  for (auto& v : meters.valid) {
    insertSSLDatasetMeters(v.second, v.first);
  }

  auto stats = meters.stats.value();
  auto numsamples = std::max<int64_t>(stats[4], 1);
  auto isztotal = stats[0];
  auto tsztotal = stats[1];
  auto tszmax = stats[3];
  insertItem("avg-isz", format("%03d", isztotal / numsamples));
  insertItem("avg-tsz", format("%03d", tsztotal / numsamples));
  insertItem("max-tsz", format("%03d", tszmax));

  double audioProcSec = isztotal * FLAGS_batchsize;
  if (FLAGS_pow || FLAGS_mfcc || FLAGS_mfsc) {
    audioProcSec = audioProcSec * FLAGS_framestridems / 1000.0;
  } else {
    audioProcSec /= FLAGS_samplerate;
  }
  auto worldSize = fl::getWorldSize();
  double timeTakenSec = meters.timer[kTimer].value() * numsamples / worldSize;

  insertItem("hrs", format("%7.2f", audioProcSec / 3600.0));
  insertItem(
      "thrpt(sec/sec)",
      timeTakenSec > 0.0 ? format("%.2f", audioProcSec / timeTakenSec) : "n/a");
  return headerOnly ? header : status;
}