From: Jiri Olsa <jolsa@redhat.com>
To: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 3/4] perf record: enable runtime trace compression
Date: Tue, 12 Feb 2019 14:08:44 +0100 [thread overview]
Message-ID: <20190212130844.GF775@krava> (raw)
In-Reply-To: <5bc6958d-f4bc-d4ea-e5d0-16c5e7b73911@linux.intel.com>
On Mon, Feb 11, 2019 at 11:23:40PM +0300, Alexey Budankov wrote:
SNIP
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 18fb9c8cbf9c..5d406eebd058 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -29,6 +29,112 @@
> #include "stat.h"
> #include "arch/common.h"
>
I think this should not be in session.c but separated in new object
> +#ifdef HAVE_ZSTD_SUPPORT
> +int perf_session__zstd_init(struct perf_session *session, int level)
> +{
> + size_t ret;
> +
> + session->header.env.comp_type = PERF_COMP_NONE;
> + session->header.env.comp_level = 0;
> +
> + session->zstd_cstream = ZSTD_createCStream();
> + if (session->zstd_cstream == NULL) {
> + pr_err("Couldn't create compression stream.\n");
> + return -1;
> + }
> +
> + ret = ZSTD_initCStream(session->zstd_cstream, level);
> + if (ZSTD_isError(ret)) {
> + pr_err("Failed to initialize compression stream: %s\n", ZSTD_getErrorName(ret));
> + return -1;
> + }
> +
> + session->header.env.comp_type = PERF_COMP_ZSTD;
> + session->header.env.comp_level = level;
> +
> + return 0;
> +}
> +
> +int perf_session__zstd_fini(struct perf_session *session)
> +{
> + if (session->zstd_cstream) {
> + ZSTD_freeCStream(session->zstd_cstream);
> + session->zstd_cstream = NULL;
> + }
> +
> + return 0;
> +}
> +
> +size_t perf_session__zstd_compress(void *to, void *dst, size_t dst_size,
> + void *src, size_t src_size)
> +{
> + struct perf_session *session = to;
> + size_t ret, size, compressed = 0;
> + struct compressed_event *event = NULL;
> + /* maximum size of record data size (2^16 - 1 - header) */
> + const size_t max_data_size = (1 << 8 * sizeof(event->header.size)) -
> + 1 - sizeof(struct compressed_event);
> + ZSTD_inBuffer input = { src, src_size, 0 };
> + ZSTD_outBuffer output;
> +
> + while (input.pos < input.size) {
> + event = dst;
> +
> + event->header.type = PERF_RECORD_COMPRESSED;
> + event->header.size = size = sizeof(struct compressed_event);
> + compressed += size;
> + dst += size;
> + dst_size -= size;
> +
> + output = (ZSTD_outBuffer){ dst, (dst_size > max_data_size) ?
> + max_data_size : dst_size, 0 };
> + ret = ZSTD_compressStream(session->zstd_cstream, &output, &input);
> + ZSTD_flushStream(session->zstd_cstream, &output);
> + if (ZSTD_isError(ret)) {
> + pr_err("failed to compress %ld bytes: %s\n",
> + (long)src_size, ZSTD_getErrorName(ret));
> + return perf_session__zstd_copy(session, dst, dst_size, src, src_size);
> + }
> + size = output.pos;
> +
> + event->header.size += size;
> + compressed += size;
> + dst += size;
> + dst_size -= size;
> + }
> +
> + session->bytes_transferred += src_size;
> + session->bytes_compressed += compressed;
> +
> + return compressed;
> +}
> +#else /* !HAVE_ZSTD_SUPPORT */
> +int perf_session__zstd_init(struct perf_session *session __maybe_unused, int level __maybe_unused)
> +{
> + return 0;
> +}
> +
> +int perf_session__zstd_fini(struct perf_session *session __maybe_unused)
> +{
> + return 0;
> +}
> +
> +size_t perf_session__zstd_compress(void *to __maybe_unused,
> + void *dst __maybe_unused, size_t dst_size __maybe_unused,
> + void *src __maybe_unused, size_t src_size __maybe_unused)
> +{
> + return 0;
> +}
> +#endif
> +
> +size_t perf_session__zstd_copy(void *to __maybe_unused,
> + void *dst, size_t dst_size __maybe_unused,
> + void *src, size_t src_size)
> +{
> + memcpy(dst, src, src_size);
> + return src_size;
> +}
> +
SNIP
next prev parent reply other threads:[~2019-02-12 13:08 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-11 20:17 [PATCH v2 0/4] perf: enable compression of record mode trace to save storage space Alexey Budankov
2019-02-11 20:21 ` [PATCH v2 1/4] feature: realize libzstd check, LIBZSTD_DIR and NO_LIBZSTD defines Alexey Budankov
2019-02-11 20:22 ` [PATCH v2 2/4] perf record: implement -z=<level> and --mmap-flush=<thres> options Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 14:13 ` Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 14:13 ` Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 15:24 ` Alexey Budankov
2019-02-21 9:49 ` Jiri Olsa
2019-02-21 11:24 ` Alexey Budankov
2019-02-25 15:27 ` Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 14:15 ` Alexey Budankov
2019-02-21 9:47 ` Jiri Olsa
2019-02-21 11:23 ` Alexey Budankov
2019-02-25 15:26 ` Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 14:13 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 15:19 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 14:25 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 14:14 ` Alexey Budankov
2019-02-25 15:30 ` Alexey Budankov
2019-02-11 20:23 ` [PATCH v2 3/4] perf record: enable runtime trace compression Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa [this message]
2019-02-20 15:13 ` Alexey Budankov
2019-02-21 9:43 ` Jiri Olsa
2019-02-21 11:30 ` Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 14:53 ` Alexey Budankov
2019-02-21 9:43 ` Jiri Olsa
2019-02-21 11:18 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 15:09 ` Alexey Budankov
2019-02-25 15:27 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 15:11 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 15:03 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 15:06 ` Alexey Budankov
2019-02-11 20:25 ` [PATCH v2 4/4] perf report: support record trace file decompression Alexey Budankov
2019-02-12 13:08 ` Jiri Olsa
2019-02-20 15:19 ` Alexey Budankov
2019-02-25 15:28 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 14:48 ` Alexey Budankov
[not found] ` <0132ec08-e28b-4102-5053-8f8e21e7fd44@linux.intel.com>
2019-02-27 10:56 ` Alexey Budankov
2019-02-27 11:17 ` Jiri Olsa
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 14:46 ` Alexey Budankov
2019-02-12 13:09 ` Jiri Olsa
2019-02-20 14:44 ` Alexey Budankov
2019-02-12 12:27 ` [PATCH v2 0/4] perf: enable compression of record mode trace to save storage space Arnaldo Carvalho de Melo
2019-02-12 14:06 ` Alexey Budankov
-- strict thread matches above, loose matches on Subject: below --
2019-01-28 7:02 Alexey Budankov
2019-01-28 7:10 ` [PATCH v2 3/4] perf record: enable runtime trace compression Alexey Budankov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190212130844.GF775@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox