Skip to content

Commit e884602

Browse files
Leo Yanacmel
authored andcommitted
perf parse: Refactor 'struct perf_evsel_config_term'
The struct perf_evsel_config_term::val is a union which contains fields 'callgraph', 'drv_cfg' and 'branch' as string pointers. This leads to the complex code logic for handling every type's string separately, and it's hard to release string as a general way. This patch refactors the structure to add a common field 'str' in the 'val' union as string pointer and remove the other three fields 'callgraph', 'drv_cfg' and 'branch'. Without passing field name, the patch simplifies the string handling with macro ADD_CONFIG_TERM_STR() for string pointer assignment. This patch fixes multiple warnings of line over 80 characters detected by checkpatch tool. Signed-off-by: Leo Yan <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Suzuki Poulouse <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0cc4bd8 commit e884602

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

tools/perf/arch/arm/util/cs-etm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int cs_etm_set_sink_attr(struct perf_pmu *pmu,
226226
if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG)
227227
continue;
228228

229-
sink = term->val.drv_cfg;
229+
sink = term->val.str;
230230
snprintf(path, PATH_MAX, "sinks/%s", sink);
231231

232232
ret = perf_pmu__scan_file(pmu, path, "%x", &hash);

tools/perf/util/evsel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,12 @@ static void apply_config_terms(struct evsel *evsel,
808808
perf_evsel__reset_sample_bit(evsel, TIME);
809809
break;
810810
case PERF_EVSEL__CONFIG_TERM_CALLGRAPH:
811-
callgraph_buf = term->val.callgraph;
811+
callgraph_buf = term->val.str;
812812
break;
813813
case PERF_EVSEL__CONFIG_TERM_BRANCH:
814-
if (term->val.branch && strcmp(term->val.branch, "no")) {
814+
if (term->val.str && strcmp(term->val.str, "no")) {
815815
perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
816-
parse_branch_str(term->val.branch,
816+
parse_branch_str(term->val.str,
817817
&attr->branch_sample_type);
818818
} else
819819
perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);

tools/perf/util/evsel_config.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ struct perf_evsel_config_term {
3636
u64 period;
3737
u64 freq;
3838
bool time;
39-
char *callgraph;
40-
char *drv_cfg;
4139
u64 stack_user;
4240
int max_stack;
4341
bool inherit;
4442
bool overwrite;
45-
char *branch;
4643
unsigned long max_events;
4744
bool percore;
4845
bool aux_output;
4946
u32 aux_sample_size;
5047
u64 cfg_chg;
48+
char *str;
5149
} val;
5250
bool weak;
5351
};

tools/perf/util/parse-events.c

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,7 @@ static int config_attr(struct perf_event_attr *attr,
12191219
static int get_config_terms(struct list_head *head_config,
12201220
struct list_head *head_terms __maybe_unused)
12211221
{
1222-
#define ADD_CONFIG_TERM(__type, __name, __val) \
1223-
do { \
1222+
#define ADD_CONFIG_TERM(__type) \
12241223
struct perf_evsel_config_term *__t; \
12251224
\
12261225
__t = zalloc(sizeof(*__t)); \
@@ -1229,63 +1228,82 @@ do { \
12291228
\
12301229
INIT_LIST_HEAD(&__t->list); \
12311230
__t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \
1232-
__t->val.__name = __val; \
12331231
__t->weak = term->weak; \
1234-
list_add_tail(&__t->list, head_terms); \
1232+
list_add_tail(&__t->list, head_terms)
1233+
1234+
#define ADD_CONFIG_TERM_VAL(__type, __name, __val) \
1235+
do { \
1236+
ADD_CONFIG_TERM(__type); \
1237+
__t->val.__name = __val; \
1238+
} while (0)
1239+
1240+
#define ADD_CONFIG_TERM_STR(__type, __val) \
1241+
do { \
1242+
ADD_CONFIG_TERM(__type); \
1243+
__t->val.str = __val; \
12351244
} while (0)
12361245

12371246
struct parse_events_term *term;
12381247

12391248
list_for_each_entry(term, head_config, list) {
12401249
switch (term->type_term) {
12411250
case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
1242-
ADD_CONFIG_TERM(PERIOD, period, term->val.num);
1251+
ADD_CONFIG_TERM_VAL(PERIOD, period, term->val.num);
12431252
break;
12441253
case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ:
1245-
ADD_CONFIG_TERM(FREQ, freq, term->val.num);
1254+
ADD_CONFIG_TERM_VAL(FREQ, freq, term->val.num);
12461255
break;
12471256
case PARSE_EVENTS__TERM_TYPE_TIME:
1248-
ADD_CONFIG_TERM(TIME, time, term->val.num);
1257+
ADD_CONFIG_TERM_VAL(TIME, time, term->val.num);
12491258
break;
12501259
case PARSE_EVENTS__TERM_TYPE_CALLGRAPH:
1251-
ADD_CONFIG_TERM(CALLGRAPH, callgraph, term->val.str);
1260+
ADD_CONFIG_TERM_STR(CALLGRAPH, term->val.str);
12521261
break;
12531262
case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
1254-
ADD_CONFIG_TERM(BRANCH, branch, term->val.str);
1263+
ADD_CONFIG_TERM_STR(BRANCH, term->val.str);
12551264
break;
12561265
case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
1257-
ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);
1266+
ADD_CONFIG_TERM_VAL(STACK_USER, stack_user,
1267+
term->val.num);
12581268
break;
12591269
case PARSE_EVENTS__TERM_TYPE_INHERIT:
1260-
ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 1 : 0);
1270+
ADD_CONFIG_TERM_VAL(INHERIT, inherit,
1271+
term->val.num ? 1 : 0);
12611272
break;
12621273
case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
1263-
ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1);
1274+
ADD_CONFIG_TERM_VAL(INHERIT, inherit,
1275+
term->val.num ? 0 : 1);
12641276
break;
12651277
case PARSE_EVENTS__TERM_TYPE_MAX_STACK:
1266-
ADD_CONFIG_TERM(MAX_STACK, max_stack, term->val.num);
1278+
ADD_CONFIG_TERM_VAL(MAX_STACK, max_stack,
1279+
term->val.num);
12671280
break;
12681281
case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS:
1269-
ADD_CONFIG_TERM(MAX_EVENTS, max_events, term->val.num);
1282+
ADD_CONFIG_TERM_VAL(MAX_EVENTS, max_events,
1283+
term->val.num);
12701284
break;
12711285
case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
1272-
ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0);
1286+
ADD_CONFIG_TERM_VAL(OVERWRITE, overwrite,
1287+
term->val.num ? 1 : 0);
12731288
break;
12741289
case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
1275-
ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1);
1290+
ADD_CONFIG_TERM_VAL(OVERWRITE, overwrite,
1291+
term->val.num ? 0 : 1);
12761292
break;
12771293
case PARSE_EVENTS__TERM_TYPE_DRV_CFG:
1278-
ADD_CONFIG_TERM(DRV_CFG, drv_cfg, term->val.str);
1294+
ADD_CONFIG_TERM_STR(DRV_CFG, term->val.str);
12791295
break;
12801296
case PARSE_EVENTS__TERM_TYPE_PERCORE:
1281-
ADD_CONFIG_TERM(PERCORE, percore,
1282-
term->val.num ? true : false);
1297+
ADD_CONFIG_TERM_VAL(PERCORE, percore,
1298+
term->val.num ? true : false);
12831299
break;
12841300
case PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT:
1285-
ADD_CONFIG_TERM(AUX_OUTPUT, aux_output, term->val.num ? 1 : 0);
1301+
ADD_CONFIG_TERM_VAL(AUX_OUTPUT, aux_output,
1302+
term->val.num ? 1 : 0);
12861303
break;
12871304
case PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE:
1288-
ADD_CONFIG_TERM(AUX_SAMPLE_SIZE, aux_sample_size, term->val.num);
1305+
ADD_CONFIG_TERM_VAL(AUX_SAMPLE_SIZE, aux_sample_size,
1306+
term->val.num);
12891307
break;
12901308
default:
12911309
break;
@@ -1322,7 +1340,7 @@ static int get_config_chgs(struct perf_pmu *pmu, struct list_head *head_config,
13221340
}
13231341

13241342
if (bits)
1325-
ADD_CONFIG_TERM(CFG_CHG, cfg_chg, bits);
1343+
ADD_CONFIG_TERM_VAL(CFG_CHG, cfg_chg, bits);
13261344

13271345
#undef ADD_CONFIG_TERM
13281346
return 0;

0 commit comments

Comments
 (0)