Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp635228img; Mon, 18 Mar 2019 10:45:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZglHqDIlyAQICH8tU1yNVuH0hqd/5pifoe8J+zMnqtH5+fzciXD3oaS+B8wFCTiwFe/13 X-Received: by 2002:a17:902:2989:: with SMTP id h9mr21169149plb.26.1552931105181; Mon, 18 Mar 2019 10:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552931105; cv=none; d=google.com; s=arc-20160816; b=lP3M3oJYFQY1bEp39rqraNy63C1o3Km6P7XDOUiS8MmnXNjCPYN6V+ZasxFHlNpI8U 5UejiWado6hjkFs3YD/Bmww1fRG/M+EFDjyyFlc2+2LDzzSfCjmaSwoWBXQiXBxFKpR3 Wsg5ArjLqbursgnBTCOLqhFExWXtPQm/u1QGzWtPvGy4pMoojNUac1tTAvD1uMaLMuWM ZiXbOtUvCFjCteWLkUpXcdBITRF5Zb2meltjYEbU8mwZbWBXqbcWUtkEtn4cvstr8PaA KMyM5h5M/edI5Tk4tvJPVAMVpq8qdejGp34197yh/qLJspBui81Y0u/Rto2nX7zGw6Pc hRFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject; bh=a/ujmxe3xd8XQmt9jO/BndCAMotRCW5+kDFp5KfzJMc=; b=vKoCKYjL7yolDI4U8O5+QctHRJ2kAHWm9a73PIH/P/mxIagtaEuJKY0Z29C1hOiUMQ ul7N+rdrIlmGtpwgVe9UiBuJwPcQIFZDIjMzSUacNGUpmhfN8rpA/VeGFIzxHkxxA59X GBatpWihfJCwzKUOjdtNIxoN23r/hT2YoOaPkZKOaB4+7dca4DL2htiEoqCvOZk69fnD XRyVdRRpubHc2hOuBgHRsnAQZeUAlHbjffwfDvUIcipfuUckjsU1mEZRaeFq1YQ7zXwh AmDlGAdcQUoPUeYquOhSTcbFZYxFQvWcw2yovbRZXOoYwFeRI2LYPb8qZK1xzEnQbs94 3cPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si10456434plb.38.2019.03.18.10.44.50; Mon, 18 Mar 2019 10:45:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbfCRRnm (ORCPT + 99 others); Mon, 18 Mar 2019 13:43:42 -0400 Received: from mga14.intel.com ([192.55.52.115]:38504 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727378AbfCRRnl (ORCPT ); Mon, 18 Mar 2019 13:43:41 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Mar 2019 10:43:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,494,1544515200"; d="scan'208";a="328370350" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 18 Mar 2019 10:43:39 -0700 Received: from [10.251.91.19] (abudanko-mobl.ccr.corp.intel.com [10.251.91.19]) by linux.intel.com (Postfix) with ESMTP id 190435805FC; Mon, 18 Mar 2019 10:43:36 -0700 (PDT) Subject: [PATCH v10 07/12] perf record: implement compression for serial trace streaming From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <12cce142-6238-475b-b9aa-236531c12c2b@linux.intel.com> Organization: Intel Corp. Message-ID: <744df43f-3932-2594-ddef-1e99a3cad03a@linux.intel.com> Date: Mon, 18 Mar 2019 20:43:35 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <12cce142-6238-475b-b9aa-236531c12c2b@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Compression is implemented using the functions from zstd.c. As the memory to operate on the compression uses mmap->data buffer. If Zstd streaming compression API fails for some reason the data to be compressed are just copied into the memory buffers using plain memcpy(). Compressed trace frame consists of an array of PERF_RECORD_COMPRESSED records. Each element of the array is not longer that PERF_SAMPLE_MAX_SIZE and consists of perf_event_header followed by the compressed chunk that is decompressed on the loading stage. Signed-off-by: Alexey Budankov --- tools/perf/builtin-record.c | 53 +++++++++++++++++++++++++++++++++++-- tools/perf/util/session.h | 2 ++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 948489cb6ff0..c22e65f6b8e6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -130,6 +130,9 @@ static int record__write(struct record *rec, struct perf_mmap *map __maybe_unuse return 0; } +static size_t zstd_compress(struct perf_session *session, void *dst, size_t dst_size, + void *src, size_t src_size); + #ifdef HAVE_AIO_SUPPORT static int record__aio_write(struct aiocb *cblock, int trace_fd, void *buf, size_t size, off_t off) @@ -389,6 +392,12 @@ static int record__pushfn(struct perf_mmap *map, void *to, void *bf, size_t size { struct record *rec = to; + if (record__comp_enabled(rec)) { + size = zstd_compress(rec->session, map->data, + perf_mmap__mmap_len(map), bf, size); + bf = map->data; + } + rec->samples++; return record__write(rec, map, bf, size); } @@ -775,6 +784,38 @@ static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) } } +static size_t process_comp_header(void *record, size_t increment) +{ + struct compressed_event *event = record; + size_t size = sizeof(struct compressed_event); + + if (increment) { + event->header.size += increment; + return increment; + } + + event->header.type = PERF_RECORD_COMPRESSED; + event->header.size = size; + + return size; +} + +static size_t zstd_compress(struct perf_session *session, void *dst, size_t dst_size, + void *src, size_t src_size) +{ + size_t compressed; + size_t max_record_size = PERF_SAMPLE_MAX_SIZE - sizeof(struct compressed_event) - 1; + + compressed = zstd_compress_stream_to_records(&(session->zstd_data), + dst, dst_size, src, src_size, max_record_size, + process_comp_header); + + session->bytes_transferred += src_size; + session->bytes_compressed += compressed; + + return compressed; +} + static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evlist, bool overwrite, bool sync) { @@ -1205,6 +1246,14 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) fd = perf_data__fd(data); rec->session = session; + if (zstd_init(&(session->zstd_data), rec->opts.comp_level) < 0) { + pr_err("Compression initialization failed.\n"); + return -1; + } + + session->header.env.comp_type = PERF_COMP_ZSTD; + session->header.env.comp_level = rec->opts.comp_level; + record__init_features(rec); if (rec->opts.use_clockid && rec->opts.clockid_res_ns) @@ -1537,6 +1586,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } out_delete_session: + zstd_fini(&(session->zstd_data)); perf_session__delete(session); return status; } @@ -2254,8 +2304,7 @@ int cmd_record(int argc, const char **argv) if (rec->opts.nr_cblocks > nr_cblocks_max) rec->opts.nr_cblocks = nr_cblocks_max; - if (verbose > 0) - pr_info("nr_cblocks: %d\n", rec->opts.nr_cblocks); + pr_debug("nr_cblocks: %d\n", rec->opts.nr_cblocks); pr_debug("affinity: %s\n", affinity_tags[rec->opts.affinity]); pr_debug("mmap flush: %d\n", rec->opts.mmap_flush); diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 0e14884f28b2..6c984c895924 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -8,6 +8,7 @@ #include "machine.h" #include "data.h" #include "ordered-events.h" +#include "util/compress.h" #include #include #include @@ -37,6 +38,7 @@ struct perf_session { struct perf_tool *tool; u64 bytes_transferred; u64 bytes_compressed; + struct zstd_data zstd_data; }; struct perf_tool; -- 2.20.1