Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1333730pxb; Thu, 7 Oct 2021 05:51:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwajSL59smCrium4HsxMtFBDsIwSBZVIF11V/YAnEquWrIAXOT6+v3tYZ94Ae5yA7EYG+Zd X-Received: by 2002:a17:902:d707:b0:13d:bbe8:bcff with SMTP id w7-20020a170902d70700b0013dbbe8bcffmr3534129ply.75.1633611066691; Thu, 07 Oct 2021 05:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633611066; cv=none; d=google.com; s=arc-20160816; b=A5ubX/Lf8PcXRISMqeDSaiTC7Ne+OvvBNVFppZbPa1vlG9miHDQP9uUb11RcG2Fuvw pYx+OPhD5Yt6kI0h/xaASQaXZ3/QHTntN2reWaqqbfv0/1EoT3CDHigLqWgwQ9NrHSIU QdEnskbd6CrhZ1VNHOVT4ebTYpa+X9By9L6meKluTgWJ+F3QDPGMG++7eeEzXHeZ2Efi 6b9NIcoL+V+NH/PKfpn+izFfGHbBj04Qm3KWvHmesieV8Lr6JgOVV5ntiIY2/xnQrVDi w5GuZJaeL85/EgpUWwfKqrASTp49qwxzE97dbJ2VOmUSt8+eDFgHWIu8NZ97txxTvgtT AuPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=v0kfuShDjk6+wkbEXcOd895MojMlqzgOEHeemsw1IJU=; b=ZJOXP6+EpfIGfaR4XRHXD1SXqz/xEdNfLA/pRtRmasE4hJQOcSixLCqYp18OYawcAh ojQnKiGhxCfC+akI04edKCZSwqbdeti+7arh0f88oNNLciVbr3jPBrltkLD7GIYr40Rm 2lgwjTLcrkDWbg2pWmWg3ETlaeJxu6fbHHq3q115lTBeE3O6C/003fxggsWgaH/Pf2WE tTyHBXnZCR6vmLsQ2k0KhpMQFXBHGo7Js3urbcmpw5QCnAHLNQOeYpW6tP8b5MBPaREr kCxJ+nj9BLKFVLm87+Fhgp47dkajmHgQWBYPAQUX82bYqpIe9gbnL7buXFA9Tffh0llw BfQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id s17si1538599pls.417.2021.10.07.05.50.46; Thu, 07 Oct 2021 05:51:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240906AbhJGK2D (ORCPT + 99 others); Thu, 7 Oct 2021 06:28:03 -0400 Received: from mga01.intel.com ([192.55.52.88]:3734 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240892AbhJGK2A (ORCPT ); Thu, 7 Oct 2021 06:28:00 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10129"; a="249532657" X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="249532657" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 03:25:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,354,1624345200"; d="scan'208";a="657335463" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga005.jf.intel.com with ESMTP; 07 Oct 2021 03:25:54 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: [PATCH v3 3/8] perf session: Move init/release code to separate functions Date: Thu, 7 Oct 2021 13:25:38 +0300 Message-Id: X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Separating init/release code into reader__init and reader__release_decomp functions. Removing a duplicate call to ui_progress__init_size, the same call can be found in __perf_session__process_events. For multiple traces ui_progress should be initialized by total size before reader__init calls. Suggested-by: Jiri Olsa Acked-by: Namhyung Kim Reviewed-by: Riccardo Mancini Tested-by: Riccardo Mancini Signed-off-by: Alexey Bayduraev --- tools/perf/util/session.c | 44 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c3930c49da7a..00417b0d29ec 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2184,28 +2184,23 @@ struct reader { }; static int -reader__process_events(struct reader *rd, struct perf_session *session, - struct ui_progress *prog) +reader__init(struct reader *rd, bool *one_mmap) { u64 data_size = rd->data_size; - u64 page_offset, size; - int err = 0, mmap_prot, mmap_flags; - char *buf, **mmaps = rd->mmaps; - union perf_event *event; - s64 skip; + u64 page_offset; + char **mmaps = rd->mmaps; page_offset = page_size * (rd->data_offset / page_size); rd->file_offset = page_offset; rd->head = rd->data_offset - page_offset; - ui_progress__init_size(prog, data_size, "Processing events..."); - data_size += rd->data_offset; rd->mmap_size = MMAP_SIZE; if (rd->mmap_size > data_size) { rd->mmap_size = data_size; - session->one_mmap = true; + if (one_mmap) + *one_mmap = true; } memset(mmaps, 0, sizeof(rd->mmaps)); @@ -2214,6 +2209,30 @@ reader__process_events(struct reader *rd, struct perf_session *session, return -1; rd->decomp_data.zstd_decomp = &rd->zstd_data; + return 0; +} + +static void +reader__release_decomp(struct reader *rd) +{ + perf_decomp__release_events(rd->decomp_data.decomp); + zstd_fini(&rd->zstd_data); +} + +static int +reader__process_events(struct reader *rd, struct perf_session *session, + struct ui_progress *prog) +{ + u64 page_offset, size; + int err = 0, mmap_prot, mmap_flags; + char *buf, **mmaps = rd->mmaps; + union perf_event *event; + s64 skip; + + err = reader__init(rd, &session->one_mmap); + if (err) + goto out; + mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2286,7 +2305,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, if (session_done()) goto out; - if (rd->file_pos < data_size) + if (rd->file_pos < rd->data_size + rd->data_offset) goto more; out: @@ -2343,8 +2362,7 @@ static int __perf_session__process_events(struct perf_session *session) */ ordered_events__reinit(&session->ordered_events); auxtrace__free_events(session); - perf_decomp__release_events(rd.decomp_data.decomp); - zstd_fini(&rd.zstd_data); + reader__release_decomp(&rd); session->one_mmap = false; return err; } -- 2.19.0