[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190212130844.GF775@krava>
Date: Tue, 12 Feb 2019 14:08:44 +0100
From: Jiri Olsa <jolsa@...hat.com>
To: Alexey Budankov <alexey.budankov@...ux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Namhyung Kim <namhyung@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Andi Kleen <ak@...ux.intel.com>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 3/4] perf record: enable runtime trace compression
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
Powered by blists - more mailing lists