Skip to content

Commit 74a1a2d

Browse files
committed
fix: log successful apis in the validation layer only if verbose is set
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 230d371 commit 74a1a2d

8 files changed

Lines changed: 1774 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ validation layer is enabled. Following variables need to be set to enable API lo
9090

9191
`ZE_ENABLE_VALIDATION_LAYER=1`
9292

93+
To print successful API call results, set
94+
`ZEL_LOADER_LOGGING_VERBOSE=1`
95+
Otherwise, only error results will be printed in the API trace output.
96+
9397
By default logs will be written to the log file, as described above. To print the logs
9498
to stderr instead, `ZEL_LOADER_LOG_CONSOLE=1` needs to be set.
9599

scripts/templates/validation/valddi.cpp.mako

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ namespace validation_layer
6565
%endfor
6666
%endif
6767
) {
68+
// Only log success results if verbose logging is enabled
69+
if (result == ${X}_RESULT_SUCCESS && !context.verboseLogging) {
70+
return result;
71+
}
6872
std::string status = (result == ${X}_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
6973
%if is_void_params:
7074
context.logger->log_trace(status + " (" + loader::to_string(result) + ") in ${func_name}()");
@@ -117,6 +121,10 @@ namespace validation_layer
117121
const void* desc,
118122
ze_event_handle_t* phEvent
119123
) {
124+
// Only log success results if verbose logging is enabled
125+
if (result == ${X}_RESULT_SUCCESS && !context.verboseLogging) {
126+
return result;
127+
}
120128
std::string status = (result == ${X}_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
121129
std::ostringstream oss;
122130
oss << status << " (" << loader::to_string(result) << ") in zexCounterBasedEventCreate2("

source/layers/validation/ze_valddi.cpp

Lines changed: 868 additions & 0 deletions
Large diffs are not rendered by default.

source/layers/validation/ze_validation_layer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace validation_layer
2323
handleLifetime = std::make_unique<HandleLifetimeValidation>();
2424
}
2525
enableThreadingValidation = getenv_tobool( "ZE_ENABLE_THREADING_VALIDATION" );
26+
verboseLogging = getenv_tobool( "ZEL_LOADER_LOGGING_VERBOSE" );
2627

2728
logger = loader::createLogger();
2829
}

source/layers/validation/ze_validation_layer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace validation_layer
4747

4848
bool enableHandleLifetime = false;
4949
bool enableThreadingValidation = false;
50+
bool verboseLogging = false;
5051

5152
ze_dditable_t zeDdiTable = {};
5253
zet_dditable_t zetDdiTable = {};

source/layers/validation/zer_valddi.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ namespace validation_layer
3131
const char** ppString ///< [in,out] pointer to a null-terminated array of characters describing
3232
///< cause of error.
3333
) {
34+
// Only log success results if verbose logging is enabled
35+
if (result == ZE_RESULT_SUCCESS && !context.verboseLogging) {
36+
return result;
37+
}
3438
std::string status = (result == ZE_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
3539
std::ostringstream oss;
3640
oss << status << " (" << loader::to_string(result) << ") in zerGetLastErrorDescription(";
@@ -46,6 +50,10 @@ namespace validation_layer
4650
ze_result_t result,
4751
ze_device_handle_t hDevice ///< [in] handle of the device
4852
) {
53+
// Only log success results if verbose logging is enabled
54+
if (result == ZE_RESULT_SUCCESS && !context.verboseLogging) {
55+
return result;
56+
}
4957
std::string status = (result == ZE_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
5058
std::ostringstream oss;
5159
oss << status << " (" << loader::to_string(result) << ") in zerTranslateDeviceHandleToIdentifier(";
@@ -61,6 +69,10 @@ namespace validation_layer
6169
ze_result_t result,
6270
uint32_t identifier ///< [in] integer identifier of the device
6371
) {
72+
// Only log success results if verbose logging is enabled
73+
if (result == ZE_RESULT_SUCCESS && !context.verboseLogging) {
74+
return result;
75+
}
6476
std::string status = (result == ZE_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
6577
std::ostringstream oss;
6678
oss << status << " (" << loader::to_string(result) << ") in zerTranslateIdentifierToDeviceHandle(";
@@ -74,6 +86,10 @@ namespace validation_layer
7486
}
7587
VALIDATION_MAYBE_UNUSED static ze_result_t logAndPropagateResult_zerGetDefaultContext(
7688
ze_result_t result) {
89+
// Only log success results if verbose logging is enabled
90+
if (result == ZE_RESULT_SUCCESS && !context.verboseLogging) {
91+
return result;
92+
}
7793
std::string status = (result == ZE_RESULT_SUCCESS) ? "SUCCESS" : "ERROR";
7894
context.logger->log_trace(status + " (" + loader::to_string(result) + ") in zerGetDefaultContext()");
7995
return result;

source/layers/validation/zes_valddi.cpp

Lines changed: 600 additions & 0 deletions
Large diffs are not rendered by default.

source/layers/validation/zet_valddi.cpp

Lines changed: 276 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)