Skip to content

Commit 4a638ca

Browse files
committed
feature: Improve API Call Tracing and add ults
- Updated API Call Tracing to dereference [out] parameters when the api call succeeds for tracking output structures. - Updated spdlog trace to output the thread id in the log string and have the log string to be configurable. - Add ULTs for the validation layer api tracing to ensure stability. Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent b3567ec commit 4a638ca

9 files changed

Lines changed: 5428 additions & 1330 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,26 @@ The Level Zero Loader uses spdlog logging and can be controlled via environment
5858

5959
`ZEL_ENABLE_LOADER_LOGGING=1`
6060

61-
[DEPRECATED] `ZEL_LOADER_LOG_FILE=/path/to/logfile`
62-
6361
`ZEL_LOADER_LOG_DIR='/directory/path'`
6462

6563
`ZEL_LOADER_LOGGING_LEVEL=debug`
6664

65+
Default Log Pattern (Does not need to be set, please see below):
66+
`ZEL_LOADER_LOG_PATTERN='[%Y-%m-%d %H:%M:%S.%e] [thread-id: %t] [%^%l%$] %v'`
67+
6768
Valid logging levels are trace, debug, info, warn, error, critical, off.
6869
Logging is disabled by default but when enabled the default level is 'warn'.
6970
The default log file is 'ze_loader.log' in '.oneapi_logs' in the current
7071
user's home directory.
7172

73+
The default log pattern includes timestamps, thread IDs, log levels, and messages.
74+
You can customize the pattern using `ZEL_LOADER_LOG_PATTERN`. Common pattern flags:
75+
- `%t` - thread id
76+
- `%Y-%m-%d %H:%M:%S.%e` - timestamp with milliseconds
77+
- `%l` - log level
78+
- `%v` - the actual log message
79+
See spdlog documentation for more pattern options.
80+
7281
This feature is in early development and is preview only.
7382

7483
# Logging API calls

scripts/templates/validation/valddi.cpp.mako

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,32 @@ namespace validation_layer
7171
%else:
7272
std::ostringstream oss;
7373
oss << status << " (" << loader::to_string(result) << ") in ${func_name}(";
74-
%for i, param in enumerate([p for p in th.make_param_lines(n, tags, obj, format=['name'])]):
74+
<%
75+
params_list = obj.get('params', [])
76+
%>
77+
%for i, param_name in enumerate([p for p in th.make_param_lines(n, tags, obj, format=['name'])]):
78+
<%
79+
# Get parameter metadata
80+
param_obj = params_list[i] if i < len(params_list) else None
81+
param_type = param_obj.get('type', '') if param_obj else ''
82+
param_desc = param_obj.get('desc', '') if param_obj else ''
83+
is_output_param = '[out]' in param_desc
84+
is_pointer = '*' in param_type and param_type.strip().endswith('*')
85+
%>
7586
%if i > 0:
7687
oss << ", ";
7788
%endif
78-
oss << "${param}=" << loader::to_string(${param});
89+
oss << "${param_name}=";
90+
%if is_output_param and is_pointer:
91+
// Dereference output parameter if not null and result is success
92+
if (result == ${X}_RESULT_SUCCESS && ${param_name} != nullptr) {
93+
oss << loader::to_string(*${param_name});
94+
} else {
95+
oss << loader::to_string(${param_name});
96+
}
97+
%else:
98+
oss << loader::to_string(${param_name});
99+
%endif
79100
%endfor
80101
oss << ")";
81102
context.logger->log_trace(oss.str());
@@ -102,7 +123,14 @@ namespace validation_layer
102123
<< "hContext=" << static_cast<const void*>(hContext) << ", "
103124
<< "hDevice=" << static_cast<const void*>(hDevice) << ", "
104125
<< "desc=" << desc << ", "
105-
<< "phEvent=" << static_cast<const void*>(phEvent) << ")";
126+
<< "phEvent=";
127+
// Dereference output parameter if not null and result is success
128+
if (result == ${X}_RESULT_SUCCESS && phEvent != nullptr) {
129+
oss << loader::to_string(*phEvent);
130+
} else {
131+
oss << static_cast<const void*>(phEvent);
132+
}
133+
oss << ")";
106134
context.logger->log_trace(oss.str());
107135
return result;
108136
}

0 commit comments

Comments
 (0)