Json::Value ConnectNode::updateNodeProcess4Timestamp()

in nlsCppSdk/transport/connectNode.cpp [4301:4359]


Json::Value ConnectNode::updateNodeProcess4Timestamp() {
  Json::Value timestamp(Json::objectValue);
  try {
    timestamp["create"] =
        utility::TextUtils::GetTimeFromMs(_nodeProcess.create_timestamp_ms);
    if (_nodeProcess.start_timestamp_ms > 0) {
      timestamp["start"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.start_timestamp_ms);
    }
    if (_nodeProcess.started_timestamp_ms > 0) {
      timestamp["started"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.started_timestamp_ms);
    }
    if (_nodeProcess.stop_timestamp_ms > 0) {
      timestamp["stop"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.stop_timestamp_ms);
    }
    if (_nodeProcess.cancel_timestamp_ms > 0) {
      timestamp["cancel"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.cancel_timestamp_ms);
    }
    if (_nodeProcess.failed_timestamp_ms > 0) {
      timestamp["failed"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.failed_timestamp_ms);
    }
    if (_nodeProcess.completed_timestamp_ms > 0) {
      timestamp["completed"] = utility::TextUtils::GetTimeFromMs(
          _nodeProcess.completed_timestamp_ms);
      timestamp["completed_latency"] =
          (Json::UInt64)(_nodeProcess.completed_timestamp_ms -
                         _nodeProcess.start_timestamp_ms);
    }
    if (_nodeProcess.closed_timestamp_ms > 0) {
      timestamp["closed"] =
          utility::TextUtils::GetTimeFromMs(_nodeProcess.closed_timestamp_ms);
    }
    if (_nodeProcess.first_binary_timestamp_ms > 0) {
      timestamp["first_binary"] = utility::TextUtils::GetTimeFromMs(
          _nodeProcess.first_binary_timestamp_ms);
      uint64_t first_binary_ms = _nodeProcess.first_binary_timestamp_ms -
                                 _nodeProcess.start_timestamp_ms;
      timestamp["first_binary_latency"] = (Json::UInt64)(first_binary_ms);
      if (first_binary_ms > 1000) {
        LOG_WARN("Request(%p) Node(%p) include abnormal first_binary:%llums",
                 _request, this, first_binary_ms);
#ifdef ENABLE_NLS_DEBUG_2
      } else if (first_binary_ms > 500) {
        LOG_DEBUG(
            "Request(%p) Node(%p) include poor health first_binary:%llums",
            _request, this, first_binary_ms);
#endif
      }
    }
  } catch (const std::exception &e) {
    LOG_ERROR("Json failed: %s", e.what());
    return timestamp;
  }
  return timestamp;
}