| 78 | |
| 79 | template <class T> |
| 80 | string WriteTextProtoToUniqueFile(Env* env, const string& name, |
| 81 | const char* proto_type, T& proto, |
| 82 | const string& dirname) { |
| 83 | string dir; |
| 84 | if (!dirname.empty()) { |
| 85 | dir = dirname; |
| 86 | } else { |
| 87 | const char* prefix = getenv("TF_DUMP_GRAPH_PREFIX"); |
| 88 | if (prefix != nullptr) dir = prefix; |
| 89 | } |
| 90 | if (dir.empty()) { |
| 91 | LOG(WARNING) |
| 92 | << "Failed to dump " << name << " because dump location is not " |
| 93 | << " specified through either TF_DUMP_GRAPH_PREFIX environment " |
| 94 | << "variable or function argument."; |
| 95 | return "(TF_DUMP_GRAPH_PREFIX not specified)"; |
| 96 | } |
| 97 | |
| 98 | if (absl::EqualsIgnoreCase(dir, "sponge") || |
| 99 | absl::EqualsIgnoreCase(dir, "test_undeclared_outputs_dir")) { |
| 100 | if (!io::GetTestUndeclaredOutputsDir(&dir)) { |
| 101 | LOG(WARNING) << "TF_DUMP_GRAPH_PREFIX=sponge, but " |
| 102 | "TEST_UNDECLARED_OUTPUT_DIRS is not set, dumping to log"; |
| 103 | dir = "-"; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | string filepath = "NULL"; |
| 108 | if (dir == "-") { |
| 109 | LOG(INFO) << proto.DebugString(); |
| 110 | filepath = "LOG(INFO)"; |
| 111 | } else { |
| 112 | Status status = env->RecursivelyCreateDir(dir); |
| 113 | if (!status.ok()) { |
| 114 | LOG(WARNING) << "Failed to create " << dir << " for dumping " |
| 115 | << proto_type << ": " << status; |
| 116 | return "(unavailable)"; |
| 117 | } |
| 118 | filepath = io::JoinPath(dir, MakeUniqueFilename(name)); |
| 119 | status = WriteToFile(filepath, proto); |
| 120 | if (!status.ok()) { |
| 121 | LOG(WARNING) << "Failed to dump " << proto_type |
| 122 | << " to file: " << filepath << " : " << status; |
| 123 | return "(unavailable)"; |
| 124 | } |
| 125 | } |
| 126 | LOG(INFO) << "Dumped " << proto_type << " to " << filepath; |
| 127 | return filepath; |
| 128 | } |
| 129 | |
| 130 | } // anonymous namespace |
| 131 |
no test coverage detected