From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: David Gow <davidgow@google.com>
Cc: <brendan.higgins@linux.dev>, <rmoar@google.com>,
<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>
Subject: Re: [PATCH v3 3/7] kunit: Handle logging of lines longer than the fragment buffer size
Date: Thu, 10 Aug 2023 16:09:15 +0100 [thread overview]
Message-ID: <1cba22b4-d8e2-e5bf-98b2-597dd1797304@opensource.cirrus.com> (raw)
In-Reply-To: <CABVgOSn4PWT6+TobiJd+ppmPXsL+0qtLdazgjuQmfymUfkYhnA@mail.gmail.com>
On 10/8/23 15:38, David Gow wrote:
> On Wed, 9 Aug 2023 at 23:54, Richard Fitzgerald
> <rf@opensource.cirrus.com> wrote:
>>
>> Add handling to kunit_log_append() for log messages that are longer than
>> a single buffer fragment.
>>
>> The initial implementation of fragmented buffers did not change the logic
>> of the original kunit_log_append(). A consequence was that it still had
>> the original assumption that a log line will fit into one buffer.
>>
>> This patch checks for log messages that are larger than one fragment
>> buffer. In that case, kvasprintf() is used to format it into a temporary
>> buffer and that content is then split across as many fragments as
>> necessary.
>>
>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
>> ---
>
> I think this looks good (and is a long-overdue addition to the logging
> functionality).
>
> One thought I have (and I'm kicking myself for not thinking of it
> earlier) is that this is starting to get very similar to the "string
> stream" functionality in lib/kunit/string-stream.{h,c}. Now, I
> actually think this implementation is much more efficient (using
> larger fragments, whereas the string stream uses variable-sized ones).
> Particularly since there are a lot of cases where string streams are
> created, converted to a string, and then logged, there's almost
> certainly a bunch of redundant work being done here.
>
> My gut feeling is that we should stick with this as-is, and maybe try
> to either work out some better integration between string streams and
> logging (to avoid that extra string allocation) or find some way of
> combining them.
>
I completely failed to notice string_stream. I could re-implement this
to use string_stream. I wonder whether appending newlines gets
a bit inefficient with the current string_stream implementation.
Could add newline support to string_stream and alloc one extra byte for
each fragment just in case we need to add a newline.
The string_stream implementation would waste a lot a memory if you log
many short lines. My current code wastes memory if you log lots of lines
that don't fit in available space in the current fragment - though it's
simple to shuffle the formatted string backwards to fill up the previous
fragment (I just haven't done that yet).
next prev parent reply other threads:[~2023-08-10 15:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 15:54 [PATCH v3 0/7] kunit: Add dynamically-extending log Richard Fitzgerald
2023-08-09 15:54 ` [PATCH v3 1/7] kunit: Replace fixed-size log with dynamically-extending buffer Richard Fitzgerald
2023-08-09 21:10 ` Rae Moar
2023-08-10 14:00 ` Richard Fitzgerald
2023-08-09 15:54 ` [PATCH v3 2/7] kunit: kunit-test: Add test cases for extending log buffer Richard Fitzgerald
2023-08-09 21:10 ` Rae Moar
2023-08-10 14:18 ` Richard Fitzgerald
2023-08-09 15:54 ` [PATCH v3 3/7] kunit: Handle logging of lines longer than the fragment buffer size Richard Fitzgerald
2023-08-10 14:38 ` David Gow
2023-08-10 15:09 ` Richard Fitzgerald [this message]
2023-08-11 8:27 ` David Gow
2023-08-10 22:41 ` Rae Moar
2023-08-09 15:54 ` [PATCH v3 4/7] kunit: kunit-test: Test logging a line that exactly fills a fragment Richard Fitzgerald
2023-08-09 21:22 ` Rae Moar
2023-08-10 14:24 ` Richard Fitzgerald
2023-08-09 15:54 ` [PATCH v3 5/7] kunit: kunit-test: Add test cases for logging very long lines Richard Fitzgerald
2023-08-10 22:58 ` Rae Moar
2023-08-09 15:54 ` [PATCH v3 6/7] kunit: kunit-test: Add test of logging only a newline Richard Fitzgerald
2023-08-10 23:02 ` Rae Moar
2023-08-09 15:54 ` [PATCH v3 7/7] kunit: Don't waste first attempt to format string in kunit_log_append() Richard Fitzgerald
2023-08-10 23:53 ` Rae Moar
2023-08-11 8:27 ` David Gow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1cba22b4-d8e2-e5bf-98b2-597dd1797304@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rmoar@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox