Re: [PATCH v2 4/4] perf report: support record trace file decompression

From: Alexey Budankov
Date: Wed Feb 20 2019 - 09:46:31 EST



On 12.02.2019 16:09, Jiri Olsa wrote:
> On Mon, Feb 11, 2019 at 11:25:00PM +0300, Alexey Budankov wrote:
>
> SNIP
>
>> +static int perf_session__process_compressed_event(struct perf_session *session,
>> + union perf_event *event, u64 file_offset)
>> +{
>> + void *src;
>> + size_t decomp_size, src_size;
>> + u64 decomp_last_rem = 0;
>> + size_t decomp_len = session->header.env.comp_mmap_len;
>> + struct decomp *decomp, *decomp_last = session->decomp_last;
>> +
>> + decomp = mmap(NULL, sizeof(struct decomp) + decomp_len, PROT_READ|PROT_WRITE,
>> + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
>> + if (decomp == MAP_FAILED) {
>> + pr_err("Couldn't allocate memory for decompression\n");
>> + return -1;
>> + }
>> +
>> + decomp->file_pos = file_offset;
>> + decomp->head = 0;
>> +
>> + if (decomp_last) {
>> + decomp_last_rem = decomp_last->size - decomp_last->head;
>> + memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), decomp_last_rem);
>> + decomp->size = decomp_last_rem;
>> + }
>> +
>> + src = (void *)event + sizeof(struct compressed_event);
>> + src_size = event->pack.header.size - sizeof(struct compressed_event);
>> +
>> + decomp_size = perf_session__zstd_decompress(session, src, src_size,
>> + &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem);
>> + if (!decomp_size) {
>> + munmap(decomp, sizeof(struct decomp) + decomp_len);
>> + pr_err("Couldn't decompress data\n");
>> + return -1;
>> + }
>> +
>> + decomp->size += decomp_size;
>> +
>> + if (session->decomp == NULL) {
>> + session->decomp = decomp;
>> + session->decomp_last = decomp;
>> + } else {
>> + session->decomp_last->next = decomp;
>> + session->decomp_last = decomp;
>> + }
>
> can this happen? can you process more compressed events
> before you deliver them in __perf_session__process_decomp_events?
>
> I think I asked similar question in my other email..

Answered to that mail.

Thanks,
Alexey

>
> thanks,
> jirka
>