Skip to content

Commit

Permalink
Add fast trace_seq_put_sval and trace_seq_put_uval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesart committed Jun 10, 2018
1 parent a2e86d3 commit ce4f209
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/trace-cmd/event-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4904,7 +4904,7 @@ void pevent_print_field(struct trace_seq *s, void *data,
if (field->flags & FIELD_IS_LONG)
trace_seq_printf(s, "0x%x", (int)val);
else
trace_seq_printf(s, "%d", (int)val);
trace_seq_put_sval(s, val); // "%d"
break;
case 2:
trace_seq_printf(s, "%2d", (short)val);
Expand All @@ -4913,13 +4913,13 @@ void pevent_print_field(struct trace_seq *s, void *data,
trace_seq_printf(s, "%1d", (char)val);
break;
default:
trace_seq_printf(s, "%lld", val);
trace_seq_put_sval(s, val); // "%lld"
}
} else {
if (field->flags & FIELD_IS_LONG)
trace_seq_printf(s, "0x%llx", val);
else
trace_seq_printf(s, "%llu", val);
trace_seq_put_uval(s, val); // "%llu"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/trace-cmd/event-parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
extern int trace_seq_puts(struct trace_seq *s, const char *str);
extern int trace_seq_putc(struct trace_seq *s, unsigned char c);

int trace_seq_put_sval(struct trace_seq *s, long long val);
int trace_seq_put_uval(struct trace_seq *s, unsigned long long val);

extern void trace_seq_terminate(struct trace_seq *s);

extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
Expand Down
65 changes: 28 additions & 37 deletions src/trace-cmd/trace-seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ static char *format_signed(char buf[BUFFER_SIZE], long long value)
return str;
}

int trace_seq_put_sval(struct trace_seq *s, long long val)
{
const char *str;
char buf[BUFFER_SIZE];

str = format_signed(buf, val);
trace_seq_puts(s, str);
return 1;
}

int trace_seq_put_uval(struct trace_seq *s, unsigned long long val)
{
const char *str;
char buf[BUFFER_SIZE];

str = format_decimal(buf, val);
trace_seq_puts(s, str);
return 1;
}

/**
* trace_seq_printf - sequence printing of trace information
* @s: trace sequence descriptor
Expand All @@ -164,45 +184,16 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)

// Optimization:
// ~30% of several traces appear to have constant "%s" fmts.
// ~69.9% have %d or %lld
if (fmt[ 0 ] == '%')
if (fmt[ 0 ] == '%' && fmt[ 1 ] == 's' && fmt[ 2 ] == '\0')
{
const char *str;
char buf[BUFFER_SIZE];

if (fmt[ 1 ] == 's' && fmt[ 2 ] == '\0')
{
va_start(ap, fmt);
str = va_arg(ap, const char *);
va_end(ap);

trace_seq_puts(s, str);
return 1;
}
else if (fmt[ 1 ] == 'd' && fmt[ 2 ] == '\0')
{
int num;

va_start(ap, fmt);
num = va_arg(ap, int);
va_end(ap);

str = format_signed(buf, num);
trace_seq_puts(s, str);
return 1;
}
else if (fmt[ 1 ] == 'l' && fmt[ 2 ] == 'l' && fmt[ 3 ] == 'd' && fmt[ 4 ] == '\0')
{
long long num;

va_start(ap, fmt);
num = va_arg(ap, long long);
va_end(ap);

str = format_signed(buf, num);
trace_seq_puts(s, str);
return 1;
}

va_start(ap, fmt);
str = va_arg(ap, const char *);
va_end(ap);

trace_seq_puts(s, str);
return 1;
}

try_again:
Expand Down

0 comments on commit ce4f209

Please sign in to comment.