[DTrace-devel] [PATCH 09/20] libdtrace: streamline kernel symbol parsing and module lookup

Kris Van Hees kris.van.hees at oracle.com
Sat Nov 7 15:53:14 UTC 2026


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.



More information about the DTrace-devel mailing list