Prints a log message to memory buffer. @param Timing TRUE to prepend timing to log. @param DebugMode DebugMode will be passed to Callback function if it is set. @param Format The format string for the debug message to print. @param Marker VA_LIST with variable arguments for Format. **/
| 228 | |
| 229 | **/ |
| 230 | VOID |
| 231 | EFIAPI |
| 232 | MemLogVA ( |
| 233 | IN CONST BOOLEAN Timing, |
| 234 | IN CONST INTN DebugMode, |
| 235 | IN CONST CHAR8 *Format, |
| 236 | IN VA_LIST Marker |
| 237 | ) |
| 238 | { |
| 239 | EFI_STATUS Status; |
| 240 | UINTN DataWritten; |
| 241 | CHAR8 *LastMessage; |
| 242 | |
| 243 | if (Format == NULL) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | if (mMemLog == NULL) { |
| 248 | Status = MemLogInit (); |
| 249 | if (EFI_ERROR(Status)) { |
| 250 | return; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // |
| 255 | // Check if buffer can accept MEM_LOG_MAX_LINE_SIZE chars. |
| 256 | // Increase buffer if not. |
| 257 | // |
| 258 | if ((UINTN)(mMemLog->Cursor - mMemLog->Buffer) + MEM_LOG_MAX_LINE_SIZE > mMemLog->BufferSize) { |
| 259 | UINTN Offset; |
| 260 | // not enough place for max line - make buffer bigger |
| 261 | // but not too big (if something gets out of controll) |
| 262 | if (mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE > MEM_LOG_MAX_SIZE) { |
| 263 | // Out of resources! |
| 264 | return; |
| 265 | } |
| 266 | Offset = mMemLog->Cursor - mMemLog->Buffer; |
| 267 | mMemLog->Buffer = ReallocatePool(mMemLog->BufferSize, mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE, mMemLog->Buffer); |
| 268 | mMemLog->BufferSize += MEM_LOG_INITIAL_SIZE; |
| 269 | mMemLog->Cursor = mMemLog->Buffer + Offset; |
| 270 | } |
| 271 | |
| 272 | // |
| 273 | // Add log to buffer |
| 274 | // |
| 275 | LastMessage = mMemLog->Cursor; |
| 276 | if (Timing) { |
| 277 | // |
| 278 | // Write timing only at the beginning of a new line |
| 279 | // |
| 280 | if ((mMemLog->Buffer[0] == '\0') || (mMemLog->Cursor[-1] == '\n')) { |
| 281 | DataWritten = AsciiSPrint( |
| 282 | mMemLog->Cursor, |
| 283 | mMemLog->BufferSize - (mMemLog->Cursor - mMemLog->Buffer), |
| 284 | "%a ", |
| 285 | GetTiming ()); |
| 286 | mMemLog->Cursor += DataWritten; |
| 287 | } |
no test coverage detected