Skip to content

Commit 249d7b2

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Consolidate some synth_event_trace code
The synth_event trace code contains some almost identical functions and some small functions that are called only once - consolidate the common code into single functions and fold in the small functions to simplify the code overall. Link: http://lkml.kernel.org/r/d1c8d8ad124a653b7543afe801d38c199ca5c20e.1580506712.git.zanussi@kernel.org Signed-off-by: Tom Zanussi <zanussi@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent d380dcd commit 249d7b2

1 file changed

Lines changed: 57 additions & 84 deletions

File tree

‎kernel/trace/trace_events_hist.c‎

Lines changed: 57 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,24 +2053,72 @@ int synth_event_trace_start(struct trace_event_file *file,
20532053
}
20542054
EXPORT_SYMBOL_GPL(synth_event_trace_start);
20552055

2056-
static int save_synth_val(struct synth_field *field, u64 val,
2057-
struct synth_event_trace_state *trace_state)
2056+
static int __synth_event_add_val(const char *field_name, u64 val,
2057+
struct synth_event_trace_state *trace_state)
20582058
{
2059-
struct synth_trace_event *entry = trace_state->entry;
2059+
struct synth_field *field = NULL;
2060+
struct synth_trace_event *entry;
2061+
struct synth_event *event;
2062+
int i, ret = 0;
2063+
2064+
if (!trace_state) {
2065+
ret = -EINVAL;
2066+
goto out;
2067+
}
2068+
2069+
/* can't mix add_next_synth_val() with add_synth_val() */
2070+
if (field_name) {
2071+
if (trace_state->add_next) {
2072+
ret = -EINVAL;
2073+
goto out;
2074+
}
2075+
trace_state->add_name = true;
2076+
} else {
2077+
if (trace_state->add_name) {
2078+
ret = -EINVAL;
2079+
goto out;
2080+
}
2081+
trace_state->add_next = true;
2082+
}
2083+
2084+
if (!trace_state->enabled)
2085+
goto out;
2086+
2087+
event = trace_state->event;
2088+
if (trace_state->add_name) {
2089+
for (i = 0; i < event->n_fields; i++) {
2090+
field = event->fields[i];
2091+
if (strcmp(field->name, field_name) == 0)
2092+
break;
2093+
}
2094+
if (!field) {
2095+
ret = -EINVAL;
2096+
goto out;
2097+
}
2098+
} else {
2099+
if (trace_state->cur_field >= event->n_fields) {
2100+
ret = -EINVAL;
2101+
goto out;
2102+
}
2103+
field = event->fields[trace_state->cur_field++];
2104+
}
20602105

2106+
entry = trace_state->entry;
20612107
if (field->is_string) {
20622108
char *str_val = (char *)(long)val;
20632109
char *str_field;
20642110

2065-
if (!str_val)
2066-
return -EINVAL;
2111+
if (!str_val) {
2112+
ret = -EINVAL;
2113+
goto out;
2114+
}
20672115

20682116
str_field = (char *)&entry->fields[field->offset];
20692117
strscpy(str_field, str_val, STR_VAR_LEN_MAX);
20702118
} else
20712119
entry->fields[field->offset] = val;
2072-
2073-
return 0;
2120+
out:
2121+
return ret;
20742122
}
20752123

20762124
/**
@@ -2104,54 +2152,10 @@ static int save_synth_val(struct synth_field *field, u64 val,
21042152
int synth_event_add_next_val(u64 val,
21052153
struct synth_event_trace_state *trace_state)
21062154
{
2107-
struct synth_field *field;
2108-
struct synth_event *event;
2109-
int ret = 0;
2110-
2111-
if (!trace_state) {
2112-
ret = -EINVAL;
2113-
goto out;
2114-
}
2115-
2116-
/* can't mix add_next_synth_val() with add_synth_val() */
2117-
if (trace_state->add_name) {
2118-
ret = -EINVAL;
2119-
goto out;
2120-
}
2121-
trace_state->add_next = true;
2122-
2123-
if (!trace_state->enabled)
2124-
goto out;
2125-
2126-
event = trace_state->event;
2127-
2128-
if (trace_state->cur_field >= event->n_fields) {
2129-
ret = -EINVAL;
2130-
goto out;
2131-
}
2132-
2133-
field = event->fields[trace_state->cur_field++];
2134-
ret = save_synth_val(field, val, trace_state);
2135-
out:
2136-
return ret;
2155+
return __synth_event_add_val(NULL, val, trace_state);
21372156
}
21382157
EXPORT_SYMBOL_GPL(synth_event_add_next_val);
21392158

2140-
static struct synth_field *find_synth_field(struct synth_event *event,
2141-
const char *field_name)
2142-
{
2143-
struct synth_field *field = NULL;
2144-
unsigned int i;
2145-
2146-
for (i = 0; i < event->n_fields; i++) {
2147-
field = event->fields[i];
2148-
if (strcmp(field->name, field_name) == 0)
2149-
return field;
2150-
}
2151-
2152-
return NULL;
2153-
}
2154-
21552159
/**
21562160
* synth_event_add_val - Add a named field's value to an open synth trace
21572161
* @field_name: The name of the synthetic event field value to set
@@ -2183,38 +2187,7 @@ static struct synth_field *find_synth_field(struct synth_event *event,
21832187
int synth_event_add_val(const char *field_name, u64 val,
21842188
struct synth_event_trace_state *trace_state)
21852189
{
2186-
struct synth_trace_event *entry;
2187-
struct synth_event *event;
2188-
struct synth_field *field;
2189-
int ret = 0;
2190-
2191-
if (!trace_state) {
2192-
ret = -EINVAL;
2193-
goto out;
2194-
}
2195-
2196-
/* can't mix add_next_synth_val() with add_synth_val() */
2197-
if (trace_state->add_next) {
2198-
ret = -EINVAL;
2199-
goto out;
2200-
}
2201-
trace_state->add_name = true;
2202-
2203-
if (!trace_state->enabled)
2204-
goto out;
2205-
2206-
event = trace_state->event;
2207-
entry = trace_state->entry;
2208-
2209-
field = find_synth_field(event, field_name);
2210-
if (!field) {
2211-
ret = -EINVAL;
2212-
goto out;
2213-
}
2214-
2215-
ret = save_synth_val(field, val, trace_state);
2216-
out:
2217-
return ret;
2190+
return __synth_event_add_val(field_name, val, trace_state);
22182191
}
22192192
EXPORT_SYMBOL_GPL(synth_event_add_val);
22202193

0 commit comments

Comments
 (0)