Skip to content

Commit df4003f

Browse files
authored
add UUID in LOG() in decoder (#3080)
* add UUID in LOG() in decoder * Fix lint * More lint
1 parent 9fc6522 commit df4003f

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

torchvision/csrc/cpu/decoder/decoder.cpp

+28-15
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ bool Decoder::enableLogLevel(int level) const {
149149
}
150150

151151
void Decoder::logCallback(int level, const std::string& message) {
152-
LOG(INFO) << "Msg, level: " << level << ", msg: " << message;
152+
LOG(INFO) << "Msg, uuid=" << params_.loggingUuid << " level=" << level
153+
<< " msg=" << message;
153154
}
154155

155156
/* static */
@@ -221,16 +222,18 @@ bool Decoder::init(
221222
cleanUp();
222223

223224
if ((params.uri.empty() || in) && (!params.uri.empty() || !in)) {
224-
LOG(ERROR) << "Either external URI gets provided"
225-
<< " or explicit input callback";
225+
LOG(ERROR)
226+
<< "uuid=" << params_.loggingUuid
227+
<< " either external URI gets provided or explicit input callback";
226228
return false;
227229
}
228230

229231
// set callback and params
230232
params_ = params;
231233

232234
if (!(inputCtx_ = avformat_alloc_context())) {
233-
LOG(ERROR) << "Cannot allocate format context";
235+
LOG(ERROR) << "uuid=" << params_.loggingUuid
236+
<< " cannot allocate format context";
234237
return false;
235238
}
236239

@@ -243,7 +246,8 @@ bool Decoder::init(
243246
params_.timeoutMs,
244247
params_.maxSeekableBytes,
245248
params_.isImage ? &type : nullptr)) < 0) {
246-
LOG(ERROR) << "can't initiate seekable buffer";
249+
LOG(ERROR) << "uuid=" << params_.loggingUuid
250+
<< " can't initiate seekable buffer";
247251
cleanUp();
248252
return false;
249253
}
@@ -271,7 +275,8 @@ bool Decoder::init(
271275
uint8_t* avioCtxBuffer =
272276
(uint8_t*)av_malloc(avioCtxBufferSize + kIoPaddingSize);
273277
if (!avioCtxBuffer) {
274-
LOG(ERROR) << "av_malloc cannot allocate " << avioCtxBufferSize
278+
LOG(ERROR) << "uuid=" << params_.loggingUuid
279+
<< " av_malloc cannot allocate " << avioCtxBufferSize
275280
<< " bytes";
276281
cleanUp();
277282
return false;
@@ -285,7 +290,8 @@ bool Decoder::init(
285290
&Decoder::readFunction,
286291
nullptr,
287292
result == 1 ? &Decoder::seekFunction : nullptr))) {
288-
LOG(ERROR) << "avio_alloc_context failed";
293+
LOG(ERROR) << "uuid=" << params_.loggingUuid
294+
<< " avio_alloc_context failed";
289295
av_free(avioCtxBuffer);
290296
cleanUp();
291297
return false;
@@ -323,7 +329,8 @@ bool Decoder::init(
323329
guard = std::make_unique<std::thread>([&f, this]() {
324330
auto timeout = std::chrono::milliseconds(params_.timeoutMs);
325331
if (std::future_status::timeout == f.wait_for(timeout)) {
326-
LOG(ERROR) << "Cannot open stream within " << params_.timeoutMs
332+
LOG(ERROR) << "uuid=" << params_.loggingUuid
333+
<< " cannot open stream within " << params_.timeoutMs
327334
<< " ms";
328335
interrupted_ = true;
329336
}
@@ -346,7 +353,8 @@ bool Decoder::init(
346353
}
347354

348355
if (result < 0 || interrupted_) {
349-
LOG(ERROR) << "avformat_open_input failed, error: "
356+
LOG(ERROR) << "uuid=" << params_.loggingUuid
357+
<< " avformat_open_input failed, error="
350358
<< Util::generateErrorDesc(result);
351359
cleanUp();
352360
return false;
@@ -355,14 +363,15 @@ bool Decoder::init(
355363
result = avformat_find_stream_info(inputCtx_, nullptr);
356364

357365
if (result < 0) {
358-
LOG(ERROR) << "avformat_find_stream_info failed, error: "
366+
LOG(ERROR) << "uuid=" << params_.loggingUuid
367+
<< " avformat_find_stream_info failed, error="
359368
<< Util::generateErrorDesc(result);
360369
cleanUp();
361370
return false;
362371
}
363372

364373
if (!openStreams(metadata)) {
365-
LOG(ERROR) << "Cannot activate streams";
374+
LOG(ERROR) << "uuid=" << params_.loggingUuid << " cannot activate streams";
366375
cleanUp();
367376
return false;
368377
}
@@ -418,7 +427,8 @@ bool Decoder::openStreams(std::vector<DecoderMetadata>* metadata) {
418427
params_.loggingUuid);
419428
CHECK(stream);
420429
if (stream->openCodec(metadata) < 0) {
421-
LOG(ERROR) << "Cannot open codec " << i;
430+
LOG(ERROR) << "uuid=" << params_.loggingUuid
431+
<< " open codec failed, stream_idx=" << i;
422432
return false;
423433
}
424434
streams_.emplace(i, std::move(stream));
@@ -518,13 +528,15 @@ int Decoder::getFrame(size_t workingTimeInMs) {
518528
bool hasMsg = false;
519529
// packet either got consumed completely or not at all
520530
if ((result = processPacket(stream, &avPacket, &gotFrame, &hasMsg)) < 0) {
521-
LOG(ERROR) << "processPacket failed with code: " << result;
531+
LOG(ERROR) << "uuid=" << params_.loggingUuid
532+
<< " processPacket failed with code=" << result;
522533
break;
523534
}
524535

525536
if (!gotFrame && params_.maxProcessNoBytes != 0 &&
526537
++numConsecutiveNoBytes > params_.maxProcessNoBytes) {
527-
LOG(ERROR) << "Exceeding max amount of consecutive no bytes";
538+
LOG(ERROR) << "uuid=" << params_.loggingUuid
539+
<< " exceeding max amount of consecutive no bytes";
528540
break;
529541
}
530542
if (result > 0) {
@@ -538,7 +550,8 @@ int Decoder::getFrame(size_t workingTimeInMs) {
538550
if (result < 0) {
539551
if (params_.maxPackageErrors != 0 && // check errors
540552
++decodingErrors >= params_.maxPackageErrors) { // reached the limit
541-
LOG(ERROR) << "Exceeding max amount of consecutive package errors";
553+
LOG(ERROR) << "uuid=" << params_.loggingUuid
554+
<< " exceeding max amount of consecutive package errors";
542555
break;
543556
}
544557
} else {

0 commit comments

Comments
 (0)