tensorflow/core/debug/debug_io_utils.cc
// Publishes debug metadata to a set of debug URLs.
Publishes debug metadata to a set of debug URLs.
Publishes debug metadata to a set of debug URLs .
Status DebugIO::PublishDebugMetadata(
    const int64_t global_step, const int64_t session_run_index,
    const int64_t executor_step_index, const std::vector<string>& input_names,
    const std::vector<string>& output_names,
    const std::vector<string>& target_nodes,
    const std::unordered_set<string>& debug_urls) {
  std::ostringstream oss;
  oss << "{";
  oss << "\"global_step\":" << global_step << ",";
  oss << "\"session_run_index\":" << session_run_index << ",";
  oss << "\"executor_step_index\":" << executor_step_index << ",";
  oss << "\"input_names\":[";
  for (size_t i = 0; i < input_names.size(); ++i) {
    oss << "\"" << input_names[i] << "\"";
    if (i < input_names.size() - 1) {
      oss << ",";
    }
  }
  oss << "],";
  oss << "\"output_names\":[";
  for (size_t i = 0; i < output_names.size(); ++i) {
    oss << "\"" << output_names[i] << "\"";
    if (i < output_names.size() - 1) {
      oss << ",";
    }
  }
  oss << "],";
  oss << "\"target_nodes\":[";
  for (size_t i = 0; i < target_nodes.size(); ++i) {
    oss << "\"" << target_nodes[i] << "\"";
    if (i < target_nodes.size() - 1) {
      oss << ",";
    }
  }
  oss << "]";
  oss << "}";
  const string json_metadata = oss.str();
  Event event;
  event.set_wall_time(static_cast<double>(Env::Default()->NowMicros()));
  LogMessage* log_message = event.mutable_log_message();
  log_message->set_message(json_metadata);
  Status status;
  for (const string& url : debug_urls) {
    if (absl::StartsWith(absl::AsciiStrToLower(url), kGrpcURLScheme)) {
#ifndef PLATFORM_WINDOWS
      Event grpc_event;
      const string address = url.substr(strlen(DebugIO::kFileURLScheme));
      const string path = address.find('/') == string::npos
                              ? ""
                              : address.substr(address.find('/'));
      grpc_event.set_wall_time(event.wall_time());
      LogMessage* log_message_grpc = grpc_event.mutable_log_message();
      log_message_grpc->set_message(
          strings::StrCat(json_metadata.substr(0, json_metadata.size() - 1),
                          ",\"grpc_path\":\"", path, "\"}"));
      status.Update(
          DebugGrpcIO::SendEventProtoThroughGrpcStream(grpc_event, url, true));
#else
      GRPC_OSS_WINDOWS_UNIMPLEMENTED_ERROR;
#endif
    } else if (absl::StartsWith(absl::AsciiStrToLower(url), kFileURLScheme)) {
      const string dump_root_dir = url.substr(strlen(kFileURLScheme));
      const string core_metadata_path = AppendTimestampToFilePath(
          io::JoinPath(dump_root_dir,
                       strings::StrCat(
                           DebugNodeKey::kMetadataFilePrefix,
                           DebugIO::kCoreMetadataTag, "sessionrun",
                           strings::Printf("%.14lld", static_cast<long long>(
                                                          session_run_index)))),
          Env::Default()->NowMicros());
      status.Update(DebugFileIO::DumpEventProtoToFile(
          event, string(io::Dirname(core_metadata_path)),
          string(io::Basename(core_metadata_path))));
    }
  }
  return status;
}
Status DebugIO :: PublishDebugMetadata ( const int64_t global_step , const int64_t session_run_index , const int64_t executor_step_index , const std :: vector < string > & input_names , const std :: vector < string > & output_names , const std :: vector < string > & target_nodes , const std :: unordered_set < string > & debug_urls ) { std :: ostringstream oss ; oss << " " ; oss << " \" \" " << global_step << " " ; oss << " \" \" " << session_run_index << " " ; oss << " \" \" " << executor_step_index << " " ; oss << " \" \" " ; for ( size_t i = 0 ; i < input_names . size ( ) ; ++ i ) { oss << " \" " << input_names [ i ] << " \" " ; if ( i < input_names . size ( ) - 1 ) { oss << " " ; } } oss << " " ; oss << " \" \" " ; for ( size_t i = 0 ; i < output_names . size ( ) ; ++ i ) { oss << " \" " << output_names [ i ] << " \" " ; if ( i < output_names . size ( ) - 1 ) { oss << " " ; } } oss << " " ; oss << " \" \" " ; for ( size_t i = 0 ; i < target_nodes . size ( ) ; ++ i ) { oss << " \" " << target_nodes [ i ] << " \" " ; if ( i < target_nodes . size ( ) - 1 ) { oss << " " ; } } oss << " " ; oss << " " ; const string json_metadata = oss . str ( ) ; Event event ; event . set_wall_time ( static_cast < double > ( Env :: Default ( ) -> NowMicros ( ) ) ) ; LogMessage * log_message = event . mutable_log_message ( ) ; log_message -> set_message ( json_metadata ) ; Status status ; for ( const string & url : debug_urls ) { if ( absl :: StartsWith ( absl :: AsciiStrToLower ( url ) , kGrpcURLScheme ) ) { #ifndef PLATFORM_WINDOWS Event grpc_event ; const string address = url . substr ( strlen ( DebugIO :: kFileURLScheme ) ) ; const string path = address . find ( ' ' ) == string :: npos ? " " : address . substr ( address . find ( ' ' ) ) ; grpc_event . set_wall_time ( event . wall_time ( ) ) ; LogMessage * log_message_grpc = grpc_event . mutable_log_message ( ) ; log_message_grpc -> set_message ( strings :: StrCat ( json_metadata . substr ( 0 , json_metadata . size ( ) - 1 ) , " \" \" \" " , path , " \" " ) ) ; status . Update ( DebugGrpcIO :: SendEventProtoThroughGrpcStream ( grpc_event , url , true ) ) ; #else GRPC_OSS_WINDOWS_UNIMPLEMENTED_ERROR ; #endif } else if ( absl :: StartsWith ( absl :: AsciiStrToLower ( url ) , kFileURLScheme ) ) { const string dump_root_dir = url . substr ( strlen ( kFileURLScheme ) ) ; const string core_metadata_path = AppendTimestampToFilePath ( io :: JoinPath ( dump_root_dir , strings :: StrCat ( DebugNodeKey :: kMetadataFilePrefix , DebugIO :: kCoreMetadataTag , " " , strings :: Printf ( " " , static_cast < long long > ( session_run_index ) ) ) ) , Env :: Default ( ) -> NowMicros ( ) ) ; status . Update ( DebugFileIO :: DumpEventProtoToFile ( event , string ( io :: Dirname ( core_metadata_path ) ) , string ( io :: Basename ( core_metadata_path ) ) ) ) ; } } return status ; }
Publishes debug metadata to a set of debug URLs.
Publishes debug metadata to a set of debug URLs .
// Construct a JSON string to carry the metadata. // Determine the path (if any) in the grpc:// URL, and add it as a field // of the JSON string.