History

Use a macro for conditionally logging based on ENABLE_TRACE_MT

This avoids having an extra ifdef around every single WelsLog call.

Martin Storsjö committed 12 years ago

Commit fd6f8a81 parent 54c63e21 file · +44 −75Browse files

Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+44−75
@@ -63,6 +63,13 @@ · 62 unmodified lines
6363 #include "cpu.h"
6464
6565 #include "measure_time.h"
66+
67+#if defined(ENABLE_TRACE_MT)
68+#define MT_TRACE_LOG(x, ...) WelsLog(x, __VA_ARGS__)
69+#else
70+#define MT_TRACE_LOG(x, ...)
71+#endif
72+
6673 namespace WelsSVCEnc {
6774 void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx,
6875 SMB* pMbList,
@@ -126,10 +133,8 @@ void CalcSliceComplexRatio (void* pRatio, SSliceCtx* pSliceCtx, uint32_t* pSlice · 57 unmodified lines
126133
127134 while (iSliceIdx < kiSliceCount) {
128135 fAvI[iSliceIdx] = 1.0f * pCountMbInSlice[iSliceIdx] / pSliceTime[iSliceIdx];
129−#if defined(ENABLE_TRACE_MT)
130− WelsLog (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx,
131− pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
132−#endif//ENABLE_TRACE_MT
136+ MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] CalcSliceComplexRatio(), pSliceConsumeTime[%d]= %d us, slice_run= %d\n", iSliceIdx,
137+ pSliceTime[iSliceIdx], pCountMbInSlice[iSliceIdx]);
133138 fSumAv += fAvI[iSliceIdx];
134139
135140 ++ iSliceIdx;
@@ -153,10 +158,8 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 17 unmodified lines
153158 iSliceIdx += 2;
154159 }
155160 if (uiTotalConsume == 0) {
156−#if defined(ENABLE_TRACE_MT)
157− WelsLog (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
158− iSliceNum);
159−#endif//ENABLE_TRACE_MT
161+ MT_TRACE_LOG (NULL, WELS_LOG_DEBUG, "[MT] NeedDynamicAdjust(), herein do no adjust due first picture, iCountSliceNum= %d\n",
162+ iSliceNum);
160163 return false;
161164 }
162165
@@ -181,11 +184,9 @@ int32_t NeedDynamicAdjust (void* pConsumeTime, const int32_t iSliceNum) { · 18 unmodified lines
181184 fThr = 1.0f;
182185 if (fRmse > fThr)
183186 iNeedAdj = true;
184−#if defined(ENABLE_TRACE_MT)
185− WelsLog (NULL, WELS_LOG_DEBUG,
186− "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
187− iNeedAdj, fRmse, fThr, iSliceNum);
188−#endif//ENABLE_TRACE_MT
187+ MT_TRACE_LOG (NULL, WELS_LOG_DEBUG,
188+ "[MT] NeedDynamicAdjust(), herein adjustment decision is made (iNeedAdj= %d) by: fRmse of pSlice complexity ratios %.6f, the corresponding threshold %.6f, iCountSliceNum %d\n",
189+ iNeedAdj, fRmse, fThr, iSliceNum);
189190
190191 return iNeedAdj;
191192 }
@@ -232,9 +233,7 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 40 unmodified lines
232233
233234 WelsEmms();
234235
235−#if defined(ENABLE_TRACE_MT)
236− WelsLog (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d\n", iCurDid, kiCountNumMb);
237−#endif//ENABLE_TRACE_MT
236+ MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG, "[MT] DynamicAdjustSlicing(), iDid= %d, iCountNumMb= %d\n", iCurDid, kiCountNumMb);
238237
239238 iSliceIdx = 0;
240239 while (iSliceIdx + 1 < kiCountSliceNum) {
@@ -259,20 +258,16 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 18 unmodified lines
259258 return;
260259 }
261260 iRunLen[iSliceIdx] = iNumMbAssigning;
262−#if defined(ENABLE_TRACE_MT)
263− WelsLog (pCtx, WELS_LOG_DEBUG,
261+ MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
264262 "[MT] DynamicAdjustSlicing(), uiSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
265263 iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iNumMbAssigning);
266−#endif//ENABLE_TRACE_MT
267264 ++ iSliceIdx;
268265 iMaximalMbNum = iMbNumLeft - (kiCountSliceNum - iSliceIdx - 1) * iMinimalMbNum; // get maximal num_mb in left parts
269266 }
270267 iRunLen[iSliceIdx] = iMbNumLeft;
271−#if defined(ENABLE_TRACE_MT)
272− WelsLog (pCtx, WELS_LOG_DEBUG,
273− "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
274− iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
275−#endif//ENABLE_TRACE_MT
268+ MT_TRACE_LOG (pCtx, WELS_LOG_DEBUG,
269+ "[MT] DynamicAdjustSlicing(), iSliceIdx= %d, pSliceComplexRatio= %.2f, slice_run_org= %d, slice_run_adj= %d\n",
270+ iSliceIdx, pSliceComplexRatio[iSliceIdx], pSliceCtx->pCountMbNumInSlice[iSliceIdx], iMbNumLeft);
276271
277272
278273 if (DynamicAdjustSlicePEncCtxAll (pSliceCtx, iRunLen) == 0) {
@@ -354,9 +349,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 75 unmodified lines
354349 pSmt->pFSliceDiff = fopen ("slice_time.txt", "wt+");
355350 #endif//MT_DEBUG
356351
357−#if defined(ENABLE_TRACE_MT)
358− WelsLog ((*ppCtx), WELS_LOG_INFO, "encpEncCtx= 0x%p\n", (void*) (*ppCtx));
359−#endif//ENABLE_TRACE_MT
352+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "encpEncCtx= 0x%p\n", (void*) (*ppCtx));
360353
361354 iIdx = 0;
362355 while (iIdx < iThreadNum) {
@@ -370,37 +363,25 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 7 unmodified lines
370363 #ifdef _WIN32
371364 WelsSnprintf (name, SEM_NAME_MAX, "fs%d%s", iIdx, pSmt->eventNamespace);
372365 err = WelsEventOpen (&pSmt->pFinSliceCodingEvent[iIdx], name);
373−#if defined(ENABLE_TRACE_MT)
374− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
375−#endif
366+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinSliceCodingEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
376367 WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace);
377368 err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name);
378−#if defined(ENABLE_TRACE_MT)
379− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
380−#endif
369+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pExitEncodeEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
381370 #endif//_WIN32
382371 // length of semaphore name should be system constrained at least on mac 10.7
383372 WelsSnprintf (name, SEM_NAME_MAX, "ud%d%s", iIdx, pSmt->eventNamespace);
384373 err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
385−#if defined(ENABLE_TRACE_MT)
386− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
387−#endif
374+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
388375 WelsSnprintf (name, SEM_NAME_MAX, "fu%d%s", iIdx, pSmt->eventNamespace);
389376 err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
390−#if defined(ENABLE_TRACE_MT)
391− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
392−#endif
377+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
393378 WelsSnprintf (name, SEM_NAME_MAX, "sc%d%s", iIdx, pSmt->eventNamespace);
394379 err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
395−#if defined(ENABLE_TRACE_MT)
396− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
397−#endif
380+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
398381 WelsSnprintf (name, SEM_NAME_MAX, "rc%d%s", iIdx, pSmt->eventNamespace);
399382 err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name);
400−#if defined(ENABLE_TRACE_MT)
401− WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
402− (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
403−#endif
383+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
384+ (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
404385
405386 ++ iIdx;
406387 }
@@ -436,10 +417,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 29 unmodified lines
436417 iReturn = WelsMutexInit (&(*ppCtx)->mutexEncoderError);
437418 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
438419
439−#if defined(ENABLE_TRACE_MT)
440− WelsLog ((*ppCtx), WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum,
441− iMaxSliceNum);
442−#endif
420+ MT_TRACE_LOG ((*ppCtx), WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iCountSliceNum= %d\n", pPara->iCountThreadsNum,
421+ iMaxSliceNum);
443422
444423 return 0;
445424 }
@@ -708,10 +687,8 @@ WELS_THREAD_ROUTINE_TYPE UpdateMbListThreadProc (void* arg) { · 262 unmodified lines
708687 iEventIdx = pPrivateData->iThreadIndex;
709688
710689 do {
711−#if defined(ENABLE_TRACE_MT)
712− WelsLog (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n",
713− iEventIdx);
714−#endif
690+ MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO, "[MT] UpdateMbListThreadProc(), try to wait (pUpdateMbListEvent[%d])!\n",
691+ iEventIdx);
715692 iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pUpdateMbListEvent[iEventIdx]);
716693 if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) {
717694 pCurDq = pEncPEncCtx->pCurDqLayer;
@@ -775,11 +752,9 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 57 unmodified lines
775752 &pEventsList[0],
776753 (uint32_t) - 1); // blocking until at least one event is
777754 #else
778−#if defined(ENABLE_TRACE_MT)
779− WelsLog (pEncPEncCtx, WELS_LOG_INFO,
780− "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n",
781− iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx);
782−#endif
755+ MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO,
756+ "[MT] CodingSliceThreadProc(), try to call WelsEventWait(pReadySliceCodingEvent[%d]= 0x%p), pEncPEncCtx= 0x%p!\n",
757+ iEventIdx, (void*) (pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]), (void*)pEncPEncCtx);
783758 iWaitRet = WelsEventWait (&pEncPEncCtx->pSliceThreading->pReadySliceCodingEvent[iEventIdx]);
784759 #endif//WIN32
785760 if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited
@@ -867,13 +842,11 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 81 unmodified lines
867842 if (bDsaFlag) {
868843 pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx] = (uint32_t) (
869844 WelsTime() - iSliceStart);
870−#if defined(ENABLE_TRACE_MT)
871− WelsLog (pEncPEncCtx, WELS_LOG_INFO,
872− "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d\n",
873− pEncPEncCtx->iCodingIndex, iSliceIdx,
874− pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize,
875− pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]);
876−#endif//ENABLE_TRACE_MT
845+ MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO,
846+ "[MT] CodingSliceThreadProc(), coding_idx %d, uiSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d\n",
847+ pEncPEncCtx->iCodingIndex, iSliceIdx,
848+ pEncPEncCtx->pSliceThreading->pSliceConsumeTime[pEncPEncCtx->uiDependencyId][iSliceIdx], iSliceSize,
849+ pCurDq->pSliceEncCtx->pFirstMbInSlice[iSliceIdx], pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx]);
877850 }
878851
879852 #if defined(SLICE_INFO_OUTPUT)
@@ -982,12 +955,10 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 102 unmodified lines
982955 );
983956 #endif//SLICE_INFO_OUTPUT
984957
985−#if defined(ENABLE_TRACE_MT)
986− WelsLog (pEncPEncCtx, WELS_LOG_INFO,
987− "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n",
988− pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx],
989− kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
990−#endif//ENABLE_TRACE_MT
958+ MT_TRACE_LOG (pEncPEncCtx, WELS_LOG_INFO,
959+ "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, uiSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n",
960+ pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize, pCurDq->pSliceEncCtx->pCountMbNumInSlice[iSliceIdx],
961+ kiEndMbInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
991962
992963 iAnyMbLeftInPartition = kiEndMbInPartition - (1 + pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
993964 iSliceIdx += kiSliceIdxStep;
@@ -1070,9 +1041,7 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 76 unmodified lines
10701041
10711042 ++ iIdx;
10721043 }
1073−#if defined(ENABLE_TRACE_MT)
1074− WelsLog (pCtx, WELS_LOG_INFO, "CreateSliceThreads() exit..\n");
1075−#endif
1044+ MT_TRACE_LOG (pCtx, WELS_LOG_INFO, "CreateSliceThreads() exit..\n");
10761045 return 0;
10771046 }
10781047

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t