xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/Utility/GmmLog/GmmLog.h (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 
23 #pragma once
24 
25 #if (_DEBUG || _RELEASE_INTERNAL) && !__GMM_KMD__
26     // Not doing #if__cplusplus >= 201103L check because partial C++11 support may
27     // work for this. We also want to catch C++11 unavailability due to not setting
28     // compiler options.
29     #if (_MSC_VER >= 1800) // VS 2013+
30         #define GMM_LOG_AVAILABLE 1
31     #elif((__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 5))) // clang 3.5+
32         #define GMM_LOG_AVAILABLE 1
33     #elif((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) // g++ 4.8+
34         #define GMM_LOG_AVAILABLE 1
35     #else
36         #define GMM_LOG_AVAILABLE 0
37         // Print out messages if GmmLog was disabled due to compiler issues
38         #define STRING2(x) #x
39         #define STRING(x) STRING2(x)
40 
41         #if (defined __GNUC__)
42             #pragma message "Detected g++ " STRING(__GNUC__) "." STRING(__GNUC_MINOR__) ". Minimum compiler version required for GmmLog is GCC 4.8.1. Disabling GmmLog."
43         #elif (defined __clang__)
44             #pragma message "Detected clang " STRING(__clang_major__) "." STRING(__clang_minor__) ". Minimum compiler version required for GmmLog is clang 3.5. Disabling GmmLog."
45         #elif (defined _MSC_VER)
46             #pragma message("Detected MSVC++ version " STRING(_MSC_VER) ". Minimum compiler version required for GmmLog is MSVC++ 1800. Disabling GmmLog")
47         #else
48             #pragma message "Unknown compiler. Disabling GmmLog."
49         #endif
50 
51         #undef STRING2
52         #undef STRING
53     #endif
54 #elif (_DEBUG || _RELEASE_INTERNAL) && __GMM_KMD__ && _WIN32
55 #define GMM_KMD_LOG_AVAILABLE 1
56 
57 /////////////////////////////////////////////////////////////////////////////////////
58 /// GMM_KMD_LOG
59 /// Gmm logging macro to log a message in KMD mode. Exmaple:
60 ///     GMM_KMD_LOG("Math Addition: %d + %d = %d \r\n", 1, 1, 2);
61 /////////////////////////////////////////////////////////////////////////////////////
62 #define GMM_KMD_LOG(message, ...)                                                                   \
63         {                                                                                           \
64             DWORD CurrentProcessId = (DWORD) (ULONG_PTR)PsGetCurrentProcessId();                    \
65             const WCHAR *format = L"%s%d.txt";                                                      \
66             WCHAR FileName[] = L"C:\\Intel\\IGfx\\GmmKmd_Proc_";                                    \
67             WCHAR FullFileName[KM_FILENAME_LENGTH];                                                 \
68                                                                                                     \
69             KmGenerateLogFileName(&FullFileName[0], format, FileName, CurrentProcessId);            \
70                                                                                                     \
71             KM_FILE_IO_OBJ *pGmmKmdLog = KmFileOpen(pHwDevExt, FullFileName, false, false, true);   \
72             if (pGmmKmdLog != NULL)                                                                 \
73             {                                                                                       \
74                 KmFilePrintf(pGmmKmdLog, message, __VA_ARGS__);                                     \
75                 KmFileClose(pGmmKmdLog, false);                                                     \
76             }                                                                                       \
77         }                                                                                           \
78 
79 #else // else if Release driver || KMD
80     #define GMM_LOG_AVAILABLE 0
81 #endif
82 
83 #if GMM_LOG_AVAILABLE
84 
85 typedef enum GmmLogLevel
86 {
87     Off = 0,
88     Trace,
89     Info,
90     Error, // default
91     Critical,
92 }GmmLogLevel;
93 
94 #ifdef __cplusplus
95 
96 #include <iostream>
97 
98 #define GMM_LOG_FILE_SIZE         1024 * 1024 * 5   // Once log reaches this size, it will start in new file
99 #define GMM_ROTATE_FILE_NUMBER    3                 // Once log is full, it'll save old log with .1/.2/.3 in name, and then start with .1
100 #define GMM_LOG_MASSAGE_MAX_SIZE  1024
101 #define GMM_LOGGER_NAME           "gmm_logger"
102 #define GMM_LOG_FILENAME          "gmm_log"
103 #define GMM_LOG_TAG               "GmmLib"
104 #define GMM_UNKNOWN_PROCESS       "Unknown_Proc"
105 #define GMM_PREFIX_STR            "INTC GMM SPD: "
106 
107 #if _WIN32
108     #define GMM_LOG_REG_KEY_SUB_PATH  "SOFTWARE\\Intel\\IGFX\\GMMLOG\\"
109     #define GMM_LOG_TO_FILE           "LogToFile"
110     #define GMM_LOG_LEVEL_REGKEY      "LogLevel" // GmmLogLevel
111 #endif //#if _WIN32
112 
113 extern "C" void GmmLibLogging(GmmLogLevel Level, const char* str, ...);
114 
115 #define GMM_LOG_TRACE(message, ...) GmmLibLogging(Trace, message, ##__VA_ARGS__)
116 #define GMM_LOG_TRACE_IF(expression, message, ...)  if(expression) { GmmLibLogging(Trace, message, ##__VA_ARGS__);}
117 
118 #define GMM_LOG_INFO(message, ...) GmmLibLogging(Info, message, ##__VA_ARGS__)
119 #define GMM_LOG_INFO_IF(expression, message, ...)  if(expression) { GmmLibLogging(Info, message, ##__VA_ARGS__);}
120 
121 #define GMM_LOG_ERROR(message, ...) GmmLibLogging(Error, message, ##__VA_ARGS__)
122 #define GMM_LOG_ERROR_IF(expression, message, ...)  if(expression) { GmmLibLogging(Error, message, ##__VA_ARGS__);}
123 
124 #else // else C
125 
126 // Fwd Declarations of C-wrapper functions used for Logging
127 void GmmLibLogging(GmmLogLevel Level, const char* str, ...);
128 
129 #define GMM_LOG_TRACE(message, ...) GmmLibLogging(Trace, message, ##__VA_ARGS__)
130 #define GMM_LOG_TRACE_IF(expression, message, ...)  if(expression) { GmmLibLogging(Trace, message, ##__VA_ARGS__);}
131 
132 #define GMM_LOG_INFO(message, ...) GmmLibLogging(Info, message, ##__VA_ARGS__)
133 #define GMM_LOG_INFO_IF(expression, message, ...)  if(expression) { GmmLibLogging(Info, message, ##__VA_ARGS__);}
134 
135 #define GMM_LOG_ERROR(message, ...) GmmLibLogging(Error, message, ##__VA_ARGS__)
136 #define GMM_LOG_ERROR_IF(expression, message, ...)  if(expression) { GmmLibLogging(Error, message, ##__VA_ARGS__);}
137 
138 #endif //#ifdef __cplusplus
139 
140 #else // else Gmm Log not available
141 
142 #define GMM_LOG_TRACE(message, ...)
143 #define GMM_LOG_TRACE_IF(expression, message, ...)
144 
145 #define GMM_LOG_INFO(message, ...)
146 #define GMM_LOG_INFO_IF(expression, message, ...)
147 
148 #define GMM_LOG_ERROR(message, ...)
149 #define GMM_LOG_ERROR_IF(expression, message, ...)
150 
151 #endif //#if _WIN32
152 
153 #if GMM_KMD_LOG_AVAILABLE
154 #else
155 
156 #define GMM_KMD_LOG(message, ...)
157 
158 #endif
159