Skip to content

Commit 65963e5

Browse files
mathieupoirieracmel
authored andcommitted
perf cs-etm: Introducing function cs_etm_decoder__init_dparams()
Introducing function cs_etm_decoder__init_dparams() to avoid repeating code at two different places. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Suzuki K Poulouse <suzuki.poulose@arm.com> Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190212171618.25355-5-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent d3267ad commit 65963e5

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎tools/perf/util/cs-etm-decoder/cs-etm-decoder.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ enum {
105105
CS_ETM_PROTO_PTM,
106106
};
107107

108-
enum {
108+
enum cs_etm_decoder_operation {
109109
CS_ETM_OPERATION_PRINT = 1,
110110
CS_ETM_OPERATION_DECODE,
111+
CS_ETM_OPERATION_MAX,
111112
};
112113

113114
int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder,

‎tools/perf/util/cs-etm.c‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ static void cs_etm__packet_dump(const char *pkt_string)
136136
fflush(stdout);
137137
}
138138

139+
static int cs_etm__init_decoder_params(struct cs_etm_decoder_params *d_params,
140+
struct cs_etm_queue *etmq,
141+
enum cs_etm_decoder_operation mode)
142+
{
143+
int ret = -EINVAL;
144+
145+
if (!(mode < CS_ETM_OPERATION_MAX))
146+
goto out;
147+
148+
d_params->packet_printer = cs_etm__packet_dump;
149+
d_params->operation = mode;
150+
d_params->data = etmq;
151+
d_params->formatted = true;
152+
d_params->fsyncs = false;
153+
d_params->hsyncs = false;
154+
d_params->frame_aligned = true;
155+
156+
ret = 0;
157+
out:
158+
return ret;
159+
}
160+
139161
static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,
140162
struct auxtrace_buffer *buffer)
141163
{
@@ -182,12 +204,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,
182204
}
183205

184206
/* Set decoder parameters to simply print the trace packets */
185-
d_params.packet_printer = cs_etm__packet_dump;
186-
d_params.operation = CS_ETM_OPERATION_PRINT;
187-
d_params.formatted = true;
188-
d_params.fsyncs = false;
189-
d_params.hsyncs = false;
190-
d_params.frame_aligned = true;
207+
if (cs_etm__init_decoder_params(&d_params, NULL,
208+
CS_ETM_OPERATION_PRINT))
209+
return;
191210

192211
decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params);
193212

@@ -436,13 +455,9 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
436455
}
437456

438457
/* Set decoder parameters to simply print the trace packets */
439-
d_params.packet_printer = cs_etm__packet_dump;
440-
d_params.operation = CS_ETM_OPERATION_DECODE;
441-
d_params.formatted = true;
442-
d_params.fsyncs = false;
443-
d_params.hsyncs = false;
444-
d_params.frame_aligned = true;
445-
d_params.data = etmq;
458+
if (cs_etm__init_decoder_params(&d_params, etmq,
459+
CS_ETM_OPERATION_DECODE))
460+
goto out_free;
446461

447462
etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params);
448463

0 commit comments

Comments
 (0)