Skip to content

UCS/LOG: Print multi-line logs in a single operation#11082

Closed
guy-ealey-morag wants to merge 9 commits intoopenucx:masterfrom
guy-ealey-morag:ucs/improved-logging
Closed

UCS/LOG: Print multi-line logs in a single operation#11082
guy-ealey-morag wants to merge 9 commits intoopenucx:masterfrom
guy-ealey-morag:ucs/improved-logging

Conversation

@guy-ealey-morag
Copy link
Copy Markdown
Contributor

@guy-ealey-morag guy-ealey-morag commented Dec 24, 2025

What?

Print multi-line logs in a single operation to avoid other logs from being interleaved between them, and improve logging efficiency.

Why?

This is done to avoid any other logs from interleaving between multi-line logs, which until now were printed one-by-one.

How?

Every log is tested for \n, if it has at least one then it's printed with the multi-line logic, otherwise it's printed using the existing logic (the separation allows more efficient handling of the single line case).

Also, added detection for logs that don't require formatting (ones that use "%s" as their format string), in this case the argument is used as-is and there is no need to spend time and resources on formatting them.
This allows printing buffers that are larger than what ucs_alloca() allows.
Notice that this approach required removing the use of strtok_r because it is modifying the given string.

@guy-ealey-morag guy-ealey-morag marked this pull request as draft December 31, 2025 22:13
@guy-ealey-morag guy-ealey-morag marked this pull request as ready for review January 5, 2026 09:19
@guy-ealey-morag
Copy link
Copy Markdown
Contributor Author

guy-ealey-morag commented Jan 13, 2026

@iyastreb @brminich
I updated the multi-line printing logic to allocate 2048 bytes on the stack, and to use snprintf directly instead of string buffers.
When the log is too long, is it truncated to 2048 characters ending with > to indicate the truncation.

brminich
brminich previously approved these changes Jan 21, 2026
@guy-ealey-morag guy-ealey-morag force-pushed the ucs/improved-logging branch 2 times, most recently from 7baf385 to c05a638 Compare January 27, 2026 05:36
@guy-ealey-morag
Copy link
Copy Markdown
Contributor Author

I refactored the code to have a single printing logic that is reused for single line and multi line logs (UCS_LOG_PRINTF macro)

@guy-ealey-morag guy-ealey-morag marked this pull request as draft February 2, 2026 08:22
@guy-ealey-morag
Copy link
Copy Markdown
Contributor Author

A complete solution to this issue will be using write or writev with the downside of using more system calls compared to printf (perf testing showed logging time can double when using write over printf)

Closing until it's prioritized again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants