1 // SPDX-License-Identifier: GPL-2.0
12 #ifdef HAVE_ZSTD_SUPPORT
13 static int perf_session__process_compressed_event(struct perf_session
*session
,
14 union perf_event
*event
, u64 file_offset
,
15 const char *file_path
)
18 size_t decomp_size
, src_size
;
19 u64 decomp_last_rem
= 0;
20 size_t mmap_len
, decomp_len
= session
->header
.env
.comp_mmap_len
;
21 struct decomp
*decomp
, *decomp_last
= session
->active_decomp
->decomp_last
;
24 decomp_last_rem
= decomp_last
->size
- decomp_last
->head
;
25 decomp_len
+= decomp_last_rem
;
28 mmap_len
= sizeof(struct decomp
) + decomp_len
;
29 decomp
= mmap(NULL
, mmap_len
, PROT_READ
|PROT_WRITE
,
30 MAP_ANONYMOUS
|MAP_PRIVATE
, -1, 0);
31 if (decomp
== MAP_FAILED
) {
32 pr_err("Couldn't allocate memory for decompression\n");
36 decomp
->file_pos
= file_offset
;
37 decomp
->file_path
= file_path
;
38 decomp
->mmap_len
= mmap_len
;
41 if (decomp_last_rem
) {
42 memcpy(decomp
->data
, &(decomp_last
->data
[decomp_last
->head
]), decomp_last_rem
);
43 decomp
->size
= decomp_last_rem
;
46 src
= (void *)event
+ sizeof(struct perf_record_compressed
);
47 src_size
= event
->pack
.header
.size
- sizeof(struct perf_record_compressed
);
49 decomp_size
= zstd_decompress_stream(session
->active_decomp
->zstd_decomp
, src
, src_size
,
50 &(decomp
->data
[decomp_last_rem
]), decomp_len
- decomp_last_rem
);
52 munmap(decomp
, mmap_len
);
53 pr_err("Couldn't decompress data\n");
57 decomp
->size
+= decomp_size
;
59 if (session
->active_decomp
->decomp
== NULL
)
60 session
->active_decomp
->decomp
= decomp
;
62 session
->active_decomp
->decomp_last
->next
= decomp
;
64 session
->active_decomp
->decomp_last
= decomp
;
66 pr_debug("decomp (B): %zd to %zd\n", src_size
, decomp_size
);
72 static int process_event_synth_tracing_data_stub(struct perf_session
*session
74 union perf_event
*event
77 dump_printf(": unhandled!\n");
81 static int process_event_synth_attr_stub(const struct perf_tool
*tool __maybe_unused
,
82 union perf_event
*event __maybe_unused
,
83 struct evlist
**pevlist
86 dump_printf(": unhandled!\n");
90 static int process_event_synth_event_update_stub(const struct perf_tool
*tool __maybe_unused
,
91 union perf_event
*event __maybe_unused
,
92 struct evlist
**pevlist
96 perf_event__fprintf_event_update(event
, stdout
);
98 dump_printf(": unhandled!\n");
102 int process_event_sample_stub(const struct perf_tool
*tool __maybe_unused
,
103 union perf_event
*event __maybe_unused
,
104 struct perf_sample
*sample __maybe_unused
,
105 struct evsel
*evsel __maybe_unused
,
106 struct machine
*machine __maybe_unused
)
108 dump_printf(": unhandled!\n");
112 static int process_event_stub(const struct perf_tool
*tool __maybe_unused
,
113 union perf_event
*event __maybe_unused
,
114 struct perf_sample
*sample __maybe_unused
,
115 struct machine
*machine __maybe_unused
)
117 dump_printf(": unhandled!\n");
121 static int process_finished_round_stub(const struct perf_tool
*tool __maybe_unused
,
122 union perf_event
*event __maybe_unused
,
123 struct ordered_events
*oe __maybe_unused
)
125 dump_printf(": unhandled!\n");
129 static int skipn(int fd
, off_t n
)
135 ret
= read(fd
, buf
, min(n
, (off_t
)sizeof(buf
)));
144 static s64
process_event_auxtrace_stub(struct perf_session
*session __maybe_unused
,
145 union perf_event
*event
)
147 dump_printf(": unhandled!\n");
148 if (perf_data__is_pipe(session
->data
))
149 skipn(perf_data__fd(session
->data
), event
->auxtrace
.size
);
150 return event
->auxtrace
.size
;
153 static int process_event_op2_stub(struct perf_session
*session __maybe_unused
,
154 union perf_event
*event __maybe_unused
)
156 dump_printf(": unhandled!\n");
162 int process_event_thread_map_stub(struct perf_session
*session __maybe_unused
,
163 union perf_event
*event __maybe_unused
)
166 perf_event__fprintf_thread_map(event
, stdout
);
168 dump_printf(": unhandled!\n");
173 int process_event_cpu_map_stub(struct perf_session
*session __maybe_unused
,
174 union perf_event
*event __maybe_unused
)
177 perf_event__fprintf_cpu_map(event
, stdout
);
179 dump_printf(": unhandled!\n");
184 int process_event_stat_config_stub(struct perf_session
*session __maybe_unused
,
185 union perf_event
*event __maybe_unused
)
188 perf_event__fprintf_stat_config(event
, stdout
);
190 dump_printf(": unhandled!\n");
194 static int process_stat_stub(struct perf_session
*perf_session __maybe_unused
,
195 union perf_event
*event
)
198 perf_event__fprintf_stat(event
, stdout
);
200 dump_printf(": unhandled!\n");
204 static int process_stat_round_stub(struct perf_session
*perf_session __maybe_unused
,
205 union perf_event
*event
)
208 perf_event__fprintf_stat_round(event
, stdout
);
210 dump_printf(": unhandled!\n");
214 static int process_event_time_conv_stub(struct perf_session
*perf_session __maybe_unused
,
215 union perf_event
*event
)
218 perf_event__fprintf_time_conv(event
, stdout
);
220 dump_printf(": unhandled!\n");
224 static int perf_session__process_compressed_event_stub(struct perf_session
*session __maybe_unused
,
225 union perf_event
*event __maybe_unused
,
226 u64 file_offset __maybe_unused
,
227 const char *file_path __maybe_unused
)
229 dump_printf(": unhandled!\n");
233 void perf_tool__init(struct perf_tool
*tool
, bool ordered_events
)
235 tool
->ordered_events
= ordered_events
;
236 tool
->ordering_requires_timestamps
= false;
237 tool
->namespace_events
= false;
238 tool
->cgroup_events
= false;
239 tool
->no_warn
= false;
240 tool
->show_feat_hdr
= SHOW_FEAT_NO_HEADER
;
242 tool
->sample
= process_event_sample_stub
;
243 tool
->mmap
= process_event_stub
;
244 tool
->mmap2
= process_event_stub
;
245 tool
->comm
= process_event_stub
;
246 tool
->namespaces
= process_event_stub
;
247 tool
->cgroup
= process_event_stub
;
248 tool
->fork
= process_event_stub
;
249 tool
->exit
= process_event_stub
;
250 tool
->lost
= perf_event__process_lost
;
251 tool
->lost_samples
= perf_event__process_lost_samples
;
252 tool
->aux
= perf_event__process_aux
;
253 tool
->itrace_start
= perf_event__process_itrace_start
;
254 tool
->context_switch
= perf_event__process_switch
;
255 tool
->ksymbol
= perf_event__process_ksymbol
;
256 tool
->bpf
= perf_event__process_bpf
;
257 tool
->text_poke
= perf_event__process_text_poke
;
258 tool
->aux_output_hw_id
= perf_event__process_aux_output_hw_id
;
259 tool
->read
= process_event_sample_stub
;
260 tool
->throttle
= process_event_stub
;
261 tool
->unthrottle
= process_event_stub
;
262 tool
->attr
= process_event_synth_attr_stub
;
263 tool
->event_update
= process_event_synth_event_update_stub
;
264 tool
->tracing_data
= process_event_synth_tracing_data_stub
;
265 tool
->build_id
= process_event_op2_stub
;
268 tool
->finished_round
= perf_event__process_finished_round
;
270 tool
->finished_round
= process_finished_round_stub
;
272 tool
->id_index
= process_event_op2_stub
;
273 tool
->auxtrace_info
= process_event_op2_stub
;
274 tool
->auxtrace
= process_event_auxtrace_stub
;
275 tool
->auxtrace_error
= process_event_op2_stub
;
276 tool
->thread_map
= process_event_thread_map_stub
;
277 tool
->cpu_map
= process_event_cpu_map_stub
;
278 tool
->stat_config
= process_event_stat_config_stub
;
279 tool
->stat
= process_stat_stub
;
280 tool
->stat_round
= process_stat_round_stub
;
281 tool
->time_conv
= process_event_time_conv_stub
;
282 tool
->feature
= process_event_op2_stub
;
283 #ifdef HAVE_ZSTD_SUPPORT
284 tool
->compressed
= perf_session__process_compressed_event
;
286 tool
->compressed
= perf_session__process_compressed_event_stub
;
288 tool
->finished_init
= process_event_op2_stub
;
291 bool perf_tool__compressed_is_stub(const struct perf_tool
*tool
)
293 return tool
->compressed
== perf_session__process_compressed_event_stub
;