Skip to content

Commit cf54209

Browse files
committed
add a logging functionality that only logs a certain number of times before increasing the log level that it reports at
1 parent b747462 commit cf54209

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/core/ebmcore/AttributeCombinationInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AttributeCombinationCore final {
2020
size_t m_cItemsPerBitPackDataUnit;
2121
size_t m_cAttributes;
2222
size_t m_iInputData;
23+
unsigned int m_cLogMessages;
2324
AttributeCombinationEntry m_AttributeCombinationEntry[1];
2425

2526
TML_INLINE static AttributeCombinationCore * Allocate(const size_t cAttributes, const size_t iAttributeCombination) {
@@ -32,6 +33,7 @@ class AttributeCombinationCore final {
3233
}
3334
pAttributeCombination->m_cAttributes = cAttributes;
3435
pAttributeCombination->m_iInputData = iAttributeCombination;
36+
pAttributeCombination->m_cLogMessages = 2;
3537
return pAttributeCombination;
3638
}
3739

src/core/ebmcore/InteractionDetection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ class TmlInteractionState {
3131
AttributeInternalCore * const m_aAttributes;
3232
DataSetInternalCore * m_pDataSet;
3333

34+
unsigned int m_cLogMessages;
35+
3436
TmlInteractionState(const bool bRegression, const size_t cTargetStates, const size_t cAttributes)
3537
: m_bRegression(bRegression)
3638
, m_cTargetStates(cTargetStates)
3739
, m_cAttributes(cAttributes)
3840
, m_aAttributes(IsMultiplyError(sizeof(AttributeInternalCore), cAttributes) ? nullptr : static_cast<AttributeInternalCore *>(malloc(sizeof(AttributeInternalCore) * cAttributes)))
39-
, m_pDataSet(nullptr) {
41+
, m_pDataSet(nullptr)
42+
, m_cLogMessages (1000) {
4043
assert(0 < cAttributes); // we can't allocate zero byte arrays. This is checked when we were initially called, but I'm leaving it here again as documentation
4144
}
4245

@@ -203,11 +206,13 @@ TML_INLINE IntegerDataType CompilerRecursiveGetInteractionScore<k_cCompilerOptim
203206
}
204207

205208
EBMCORE_IMPORT_EXPORT IntegerDataType EBMCORE_CALLING_CONVENTION GetInteractionScore(PEbmInteraction ebmInteraction, IntegerDataType countAttributesInCombination, const IntegerDataType * attributeIndexes, FractionalDataType * interactionScoreReturn) {
206-
LOG(TraceLevelVerbose, "Entered GetInteractionScore");
207209
LOG(TraceLevelVerbose, "GetInteractionScore parameters: ebmInteraction=%p, countAttributesInCombination=%" IntegerDataTypePrintf ", attributeIndexes=%p, interactionScoreReturn=%p", static_cast<void *>(ebmInteraction), countAttributesInCombination, static_cast<const void *>(attributeIndexes), static_cast<void *>(interactionScoreReturn));
208210

209211
assert(nullptr != ebmInteraction);
210212
TmlInteractionState * pEbmInteractionState = reinterpret_cast<TmlInteractionState *>(ebmInteraction);
213+
214+
LOG_COUNTED(&pEbmInteractionState->m_cLogMessages, TraceLevelInfo, TraceLevelVerbose, "Entered GetInteractionScore");
215+
211216
assert(1 <= countAttributesInCombination);
212217
assert(nullptr != attributeIndexes);
213218

src/core/ebmcore/Logging.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern void InteralLogWithArguments(signed char traceLevel, const char * const p
2424
do { /* using a do loop here gives us a nice look to the macro where the caller needs to use a semi-colon to call it, and it can be used after a single if statement without curly braces */ \
2525
constexpr signed char LOG__traceLevel = (traceLevel); /* we only use traceLevel once, which avoids pre and post decrement issues with macros */ \
2626
static_assert(TraceLevelOff < LOG__traceLevel, "traceLevel can't be TraceLevelOff or lower for call to LOG(traceLevel, pLogMessage, ...)"); \
27-
static_assert(LOG__traceLevel <= TraceLevelVerbose, "traceLevel can't be higher than TraceLevelDebug for call to LOG(traceLevel, pLogMessage, ...)"); \
27+
static_assert(LOG__traceLevel <= TraceLevelVerbose, "traceLevel can't be higher than TraceLevelVerbose for call to LOG(traceLevel, pLogMessage, ...)"); \
2828
if(UNLIKELY(LOG__traceLevel <= g_traceLevel)) { \
2929
assert(nullptr != g_pLogMessageFunc); \
3030
constexpr size_t LOG__cArguments = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
@@ -38,22 +38,35 @@ extern void InteralLogWithArguments(signed char traceLevel, const char * const p
3838
/* the "(void)0, 0" part supresses the conditional expression is constant compiler warning */ \
3939
} while((void)0, 0)
4040

41-
#define LOG_COUNTED(pLogCount, traceLevelBefore, pLogMessage, ...) \
41+
#define LOG_COUNTED(pLogCountDecrement, traceLevelBefore, traceLevelAfter, pLogMessage, ...) \
4242
do { /* using a do loop here gives us a nice look to the macro where the caller needs to use a semi-colon to call it, and it can be used after a single if statement without curly braces */ \
43-
constexpr signed char LOG__traceLevel = (traceLevel); /* we only use traceLevel once, which avoids pre and post decrement issues with macros */ \
44-
static_assert(TraceLevelOff < LOG__traceLevel, "traceLevel can't be TraceLevelOff or lower for call to LOG(traceLevel, pLogMessage, ...)"); \
45-
static_assert(LOG__traceLevel <= TraceLevelVerbose, "traceLevel can't be higher than TraceLevelDebug for call to LOG(traceLevel, pLogMessage, ...)"); \
46-
if(UNLIKELY(LOG__traceLevel <= g_traceLevel)) { \
47-
unsigned int * const LOG__pLogCount = (pLogCount); \
48-
if(0 < *LOG__pLogCount) { \
49-
--(*LOG__pLogCount); \
43+
constexpr signed char LOG__traceLevelBefore = (traceLevelBefore); /* we only use traceLevelBefore once, which avoids pre and post decrement issues with macros */ \
44+
static_assert(TraceLevelOff < LOG__traceLevelBefore, "traceLevelBefore can't be TraceLevelOff or lower for call to LOG_COUNTED(pLogCount, traceLevelBefore, traceLevelAfter, pLogMessage, ...)"); \
45+
static_assert(LOG__traceLevelBefore <= TraceLevelVerbose, "traceLevelBefore can't be higher than TraceLevelVerbose for call to LOG_COUNTED(pLogCount, traceLevelBefore, traceLevelAfter, pLogMessage, ...)"); \
46+
constexpr signed char LOG__traceLevelAfter = (traceLevelAfter); /* we only use traceLevelAfter once, which avoids pre and post decrement issues with macros */ \
47+
static_assert(TraceLevelOff < LOG__traceLevelAfter, "traceLevelAfter can't be TraceLevelOff or lower for call to LOG_COUNTED(pLogCount, traceLevelBefore, traceLevelAfter, pLogMessage, ...)"); \
48+
static_assert(LOG__traceLevelAfter <= TraceLevelVerbose, "traceLevelAfter can't be higher than TraceLevelVerbose for call to LOG_COUNTED(pLogCount, traceLevelBefore, traceLevelAfter, pLogMessage, ...)"); \
49+
static_assert(LOG__traceLevelBefore < LOG__traceLevelAfter, "We only support increasing the required trace level after N iterations and it doesn't make sense to have equal values, otherwise just use LOG(..)"); \
50+
if(UNLIKELY(LOG__traceLevelBefore <= g_traceLevel)) { \
51+
constexpr size_t LOG__cArguments = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
52+
constexpr static char LOG__originalMessage[] = (pLogMessage); /* we only use pLogMessage once, which avoids pre and post decrement issues with macros */ \
53+
unsigned int * const LOG__pLogCountDecrement = (pLogCountDecrement); /* we only use pLogCountDecrement once, which avoids pre and post decrement issues with macros */ \
54+
if(0 < *LOG__pLogCountDecrement) { \
55+
--(*LOG__pLogCountDecrement); \
5056
assert(nullptr != g_pLogMessageFunc); \
51-
constexpr size_t LOG__cArguments = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
52-
constexpr static char LOG__originalMessage[] = (pLogMessage); /* we only use pLogMessage once, which avoids pre and post decrement issues with macros */ \
5357
if(0 == LOG__cArguments) { /* if there are no arguments we might as well send the log directly without reserving stack space for vsnprintf and without log length limitations for stack allocation */ \
54-
(*g_pLogMessageFunc)(LOG__traceLevel, LOG__originalMessage); \
58+
(*g_pLogMessageFunc)(LOG__traceLevelBefore, LOG__originalMessage); \
5559
} else { \
56-
InteralLogWithArguments(LOG__traceLevel, LOG__originalMessage, ##__VA_ARGS__); \
60+
InteralLogWithArguments(LOG__traceLevelBefore, LOG__originalMessage, ##__VA_ARGS__); \
61+
} \
62+
} else { \
63+
if(UNLIKELY(LOG__traceLevelAfter <= g_traceLevel)) { \
64+
assert(nullptr != g_pLogMessageFunc); \
65+
if(0 == LOG__cArguments) { /* if there are no arguments we might as well send the log directly without reserving stack space for vsnprintf and without log length limitations for stack allocation */ \
66+
(*g_pLogMessageFunc)(LOG__traceLevelAfter, LOG__originalMessage); \
67+
} else { \
68+
InteralLogWithArguments(LOG__traceLevelAfter, LOG__originalMessage, ##__VA_ARGS__); \
69+
} \
5770
} \
5871
} \
5972
} \

src/core/ebmcore/Training.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ union CachedThreadResourcesUnion {
518518
}
519519

520520
~CachedThreadResourcesUnion() {
521-
LOG(TraceLevelError, "ERROR ~CachedThreadResourcesUnion called. It's union destructors should be called explicitly");
521+
// TODO: figure out why this is being called, and if that is bad!
522+
//LOG(TraceLevelError, "ERROR ~CachedThreadResourcesUnion called. It's union destructors should be called explicitly");
522523

523524
// we don't have enough information here to delete this object, so we do it from our caller
524525
// we still need this destructor for a technicality that it might be called
@@ -994,7 +995,6 @@ TML_INLINE IntegerDataType CompilerRecursiveTrainingStep<k_cCompilerOptimizedTar
994995
}
995996

996997
EBMCORE_IMPORT_EXPORT IntegerDataType EBMCORE_CALLING_CONVENTION TrainingStep(PEbmTraining ebmTraining, IntegerDataType indexAttributeCombination, FractionalDataType learningRate, IntegerDataType countTreeSplitsMax, IntegerDataType countCasesRequiredForSplitParentMin, const FractionalDataType * trainingWeights, const FractionalDataType * validationWeights, FractionalDataType * validationMetricReturn) {
997-
LOG(TraceLevelVerbose, "Entered TrainingStep");
998998
LOG(TraceLevelVerbose, "TrainingStep parameters: ebmTraining=%p, indexAttributeCombination=%" IntegerDataTypePrintf ", learningRate=%" FractionalDataTypePrintf ", countTreeSplitsMax=%" IntegerDataTypePrintf ", countCasesRequiredForSplitParentMin=%" IntegerDataTypePrintf ", trainingWeights=%p, validationWeights=%p, validationMetricReturn=%p", static_cast<void *>(ebmTraining), indexAttributeCombination, learningRate, countTreeSplitsMax, countCasesRequiredForSplitParentMin, static_cast<const void *>(trainingWeights), static_cast<const void *>(validationWeights), static_cast<void *>(validationMetricReturn));
999999

10001000
TmlState * pTmlState = reinterpret_cast<TmlState *>(ebmTraining);
@@ -1004,6 +1004,8 @@ EBMCORE_IMPORT_EXPORT IntegerDataType EBMCORE_CALLING_CONVENTION TrainingStep(PE
10041004
size_t iAttributeCombination = static_cast<size_t>(indexAttributeCombination);
10051005
assert(iAttributeCombination < pTmlState->m_cAttributeCombinations);
10061006

1007+
LOG_COUNTED(&pTmlState->m_apAttributeCombinations[iAttributeCombination]->m_cLogMessages, TraceLevelInfo, TraceLevelVerbose, "Entered TrainingStep");
1008+
10071009
assert(!std::isnan(learningRate));
10081010
assert(!std::isinf(learningRate));
10091011
assert(0 < learningRate);

0 commit comments

Comments
 (0)