| 227 | } |
| 228 | |
| 229 | void LogLines(int sev, absl::string_view text, const char* fname, int lineno) { |
| 230 | const int orig_sev = sev; |
| 231 | if (sev == tensorflow::FATAL) { |
| 232 | sev = tensorflow::ERROR; |
| 233 | } |
| 234 | |
| 235 | // Protect calls with a mutex so we don't interleave calls to LogLines from |
| 236 | // multiple threads. |
| 237 | static tensorflow::mutex log_lines_mu(tensorflow::LINKER_INITIALIZED); |
| 238 | tensorflow::mutex_lock lock(log_lines_mu); |
| 239 | |
| 240 | size_t cur = 0; |
| 241 | while (cur < text.size()) { |
| 242 | size_t eol = text.find('\n', cur); |
| 243 | if (eol == absl::string_view::npos) { |
| 244 | eol = text.size(); |
| 245 | } |
| 246 | auto msg = text.substr(cur, eol - cur); |
| 247 | tensorflow::internal::LogString(fname, lineno, sev, |
| 248 | string(msg.data(), msg.size())); |
| 249 | cur = eol + 1; |
| 250 | } |
| 251 | |
| 252 | if (orig_sev == tensorflow::FATAL) { |
| 253 | tensorflow::internal::LogString(fname, lineno, orig_sev, |
| 254 | "Aborting due to errors."); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | int64 Product(absl::Span<const int64> xs) { |
| 259 | return std::accumulate(xs.begin(), xs.end(), static_cast<int64>(1), |