-
Notifications
You must be signed in to change notification settings - Fork 89
/
palDbgLogHelper.h
180 lines (165 loc) · 9.03 KB
/
palDbgLogHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
***********************************************************************************************************************
*
* Copyright (c) 2021-2024 Advanced Micro Devices, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************************************************************/
/**
***********************************************************************************************************************
* @file palDbgLogHelper.h
* @brief Contains definitions used by DbgLogMgr.
***********************************************************************************************************************
*/
#pragma once
#include "palUtil.h"
#if defined(__unix__)
#include <stdarg.h>
#endif
namespace Util
{
/// The SeverityLevel and OriginationType are used by the debug loggers to filter
/// incoming messages. For example, a file logger may allow all messages of all
/// severity and origination whereas an AMDLOG logger may only allow messages that
/// have SeverityLevel >= Critical and OriginationType >= Telemetry. Default cutoff
/// values for these will be set in the IDgbLogger class and derived loggers are
/// supposed to override the cutoffs according to their needs.
/// Specifies the severity level for each log message
enum class SeverityLevel : uint32
{
Debug = 0, ///< Information useful to developers for debugging.
Info, ///< Normal operational messages that require no action.
Warning, ///< Indicates that an error might occur if action is not taken.
Error, ///< Error conditions that are cause for concern.
Critical, ///< Critical conditions which indicate catastrophic failure is imminent.
Count
};
/// Look up table for SeverityLevel. The order of entries in this table must match the order of enums in
/// SeverityLevel and this table should be updated whenever there is a change to SeverityLevel enums.
constexpr const char* SeverityLevelTable[] =
{
"Debug",
"Info",
"Warning",
"Error",
"Critical",
};
/// Catch any mismatch between SeverityLevel and SeverityLevelTable entries
constexpr uint32 SeverityLevelTableSize = sizeof(SeverityLevelTable) / sizeof(SeverityLevelTable[0]);
static_assert(SeverityLevelTableSize == static_cast<uint32>(SeverityLevel::Count),
"SeverityLevel and SeverityLevelTable are out of sync!");
/// Specifies the origination type (source) of each log message.
enum class OriginationType : uint32
{
Unknown = 0, ///< Originating from an unknown source
DebugPrint, ///< Originating from PAL_DPINFO, PAL_DPERROR, etc. .
Alert, ///< Originating from PAL_ALERT* macros.
Assert, ///< Originating from PAL_ASSERT* macros.
Telemetry, ///< Used for msgs regarding crash dump and offline analysis
PipelineCompiler,///< Originating from pipeline compiler
GpuProfiler, ///< Originating from the GpuProfiler PAL layer
Count
};
/// Specifies the flag, or the bit position of each origination type used to turn
/// on/off this origination type. The number of enumerators here must match the
/// number of enumerators in the OriginationType enum.
/// A debug logger may be interested in logging msgs from multiple sources. Hence, these
/// can be used to create a mask of origination types to be used as a filter by the
/// debug loggers.
/// Example: If a client wants to create a debug logger to log debug prints, alerts and
/// asserts, then it should create the following bit mask:
///
/// uint32 mask = uint32(OriginationTypeFlags::OriginationTypeFlagDebugPrint) |
/// uint32(OriginationTypeFlags::OriginationTypeFlagAlert) |
/// uint32(OriginationTypeFlags::OriginationTypeFlagAssert);
///
/// and pass this mask in the constructor of the debug logger.
enum OriginationTypeFlags : uint32
{
OriginationTypeFlagUnknown = (1ul << uint32(OriginationType::Unknown)),
OriginationTypeFlagDebugPrint = (1ul << uint32(OriginationType::DebugPrint)),
OriginationTypeFlagAlert = (1ul << uint32(OriginationType::Alert)),
OriginationTypeFlagAssert = (1ul << uint32(OriginationType::Assert)),
OriginationTypeFlagTelemetry = (1ul << uint32(OriginationType::Telemetry)),
OriginationTypeFlagPipelineCompiler = (1ul << uint32(OriginationType::PipelineCompiler)),
OriginationTypeFlagGpuProfiler = (1ul << uint32(OriginationType::GpuProfiler))
};
constexpr uint32 AllOriginationTypes = uint32(OriginationTypeFlags::OriginationTypeFlagUnknown) |
uint32(OriginationTypeFlags::OriginationTypeFlagDebugPrint) |
uint32(OriginationTypeFlags::OriginationTypeFlagAlert) |
uint32(OriginationTypeFlags::OriginationTypeFlagAssert) |
uint32(OriginationTypeFlags::OriginationTypeFlagTelemetry) |
uint32(OriginationTypeFlags::OriginationTypeFlagPipelineCompiler) |
uint32(OriginationTypeFlags::OriginationTypeFlagGpuProfiler);
/// Expected maximum number of characters in the client tag.
/// A client tag indicates the client that logs a message.
constexpr uint32 ClientTagSize = 8;
/// Base structure for debug log settings. Loggers specific settings
/// structure can be found in their headers.
struct DbgLogBaseSettings
{
SeverityLevel severityLevel; ///< All messages below this SeverityLevel get filtered out.
uint32 origTypeMask; ///< A mask of acceptable origination types
};
/// Checks to see if incoming severity and source can be accepted based on the incoming base settings.
/// Messages will only get logged if they pass through this check.
///
/// @param [in] severity Specifies the log message's severity level.
/// @param [in] source Specifies the log message's origination type (source).
/// @param [in] severityBase Specifies the receiving object's base severity level.
/// @param [in] sourceBase Specifies the receiving object's base origination type (source) mask.
/// @returns true if log message's severity is above the base cutoff level and source is in the base mask.
/// Otherwise, returns false.
extern bool AcceptMessage(
SeverityLevel severity,
OriginationType source,
SeverityLevel severityBase,
uint32 sourceBase);
/// Generic debug log function called by PAL_DPF macros - variable args version.
/// Clients should use the PAL_DPF macros instead of calling this function directly.
///
/// @param [in] severity Specifies the severity level of the log message
/// @param [in] source Specifies the origination type (source) of the log message
/// @param [in] pClientTag Indicates the client that logs a message. Only the first 'ClientTagSize'
/// number of characters will be used to identify the client.
/// @param [in] pFormat Format string for the log message.
/// @param [in] ... Variable arguments that correspond to the format string.
extern void DbgLog(
SeverityLevel severity,
OriginationType source,
const char* pClientTag,
const char* pFormat,
...);
/// Generic debug log function for debug prints - va_list version
/// Clients should use the PAL_DPF macros instead of calling this function directly.
///
/// @param [in] severity Specifies the severity level of the log message
/// @param [in] source Specifies the origination type (source) of the log message
/// @param [in] pClientTag Indicates the client that logs a message. Only the first 'ClientTagSize'
/// number of characters will be used to identify the client.
/// @param [in] pFormat Format string for the log message.
/// @param [in] argList Printf-style argument list.
extern void DbgVLog(
SeverityLevel severity,
OriginationType source,
const char* pClientTag,
const char* pFormat,
va_list argList);
} // Util