From: Kris Van Hees <kris.van.hees@oracle.com>
To: Nick Alcock <nix@esperi.org.uk>
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH 09/20] libdtrace: streamline kernel symbol parsing and module lookup
Date: Sat, 7 Nov 2026 15:53:14 +0000 [thread overview]
Message-ID: <au9Jamtz3PtdAnnr@kvh-deb-bpf> (raw)
In-Reply-To: <87eccyt8xc.fsf@esperi.org.uk>
On Fri, Nov 06, 2026 at 12:56:47PM +0000, Nick Alcock wrote:
> On 30 Oct 2026, Kris Van Hees told this:
>
> Is it really worth replacing sscanf(), which though it's a bit clunky is
> at least used by other people, with even more hand-rolled parsing code?
> The hex parser isn't too bad, but this:
>
> > +static int
> > +dt_modsym_parse(const char *line, int kind, dt_kallsym_t *sym)
> > +{
> > + const char *end;
> > + uint64_t value;
> > + size_t len;
> > +
> > + if (dt_modsym_hex(&line, &value) != 0)
> > + return -1;
> > + sym->addr = value;
> > + sym->size = 1;
> > + if (kind == DT_MODSYM_KALLMODSYMS) {
> > + if (dt_modsym_hex(&line, &value) != 0 || value > SIZE_MAX)
> > + return -1;
> > + sym->size = value;
> > + }
> > + while (isspace((unsigned char)*line))
> > + line++;
> > + if (*line == '\0')
> > + return -1;
> > + sym->type = *line++;
> > + if (!isspace((unsigned char)*line))
> > + return -1;
> > + while (isspace((unsigned char)*line))
> > + line++;
> > + len = strcspn(line, " \t\r\n");
> > + if (len == 0 || len >= sizeof(sym->name))
> > + return -1;
> > + memcpy(sym->name, line, len);
> > + sym->name[len] = '\0';
> > + line += len;
> > + while (isspace((unsigned char)*line))
> > + line++;
> > + if (*line == '\0') {
> > + strcpy(sym->mod, "vmlinux");
> > + return 0;
> > + }
> > + if (*line++ != '[' || (end = strchr(line, ']')) == NULL)
> > + return -1;
> > + len = end - line;
> > + if (len == 0 || len >= sizeof(sym->mod))
> > + return -1;
> > + memcpy(sym->mod, line, len);
> > + sym->mod[len] = '\0';
> > + return 1; /* Explicit module name(s). */
> > +}
>
> ... strikes me as exactly the sort of thing you should never ever do as
> root.
>
> Is sscanf() really noticable in profiles? (I guess it might be: we are
> calling it hundreds of thousands of times, after all...)
Yes - benchmarking the change showed on average a 5x speedup compared to
the sscanf() version, which is quite significant during dtrace startup.
prev parent reply other threads:[~2026-11-07 15:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 19:36 [PATCH 09/20] libdtrace: streamline kernel symbol parsing and module lookup Kris Van Hees
2026-11-06 12:56 ` Nick Alcock
2026-11-07 15:53 ` Kris Van Hees [this message]
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=au9Jamtz3PtdAnnr@kvh-deb-bpf \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=nix@esperi.org.uk \
/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