Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp412799pxb; Wed, 29 Sep 2021 01:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVr0JLNBT3eQzM4/ueSg2b2qdA9GOYjvLXAAbk52eCYH4jKFNKcT5b98HM5qobCVtvS2SJ X-Received: by 2002:aa7:db13:: with SMTP id t19mr7373844eds.339.1632905283779; Wed, 29 Sep 2021 01:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632905283; cv=none; d=google.com; s=arc-20160816; b=b+Dl3La6r1SOJQr3bN7szay/AiYfSrvC783PqZzeAoc/r3Z96Koybf+mVSb++KoT8m L3McM6WeKFCFR+4BSAS+Jg1piVTUbH81lZCg3wpwUrKT0anv/iZjzpoRfDnZp9maJlP+ LO83K/5dJhbp3aY2c0toh70UriFHA69zKrWm+wWZdcn65FKjma4Ypygr0G6xT90wkWI3 hUy9qTcQYTc/Xq+MmlqRQqC2CyY3WSc+CMGZRo1rFvZkpPGiw+li2F1Q0tu/ZhU/dsld HVZa/JZJsT0csFGTuPduxRZTeesdI4A9QlIvABo/IOaj174M7bs/zPBGNpfZCKWklJc2 9Fjg== 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=SVnrLJSq3myWgkvJVR4uysfhhh1gDbBuVMm4vSgfsqs=; b=amrOito5bRheeSYBWAZQJK+5gYwO6jbq+6ti7XgHPRGufpvpMp92jfF90GhCpjc0ei H1R+V7Ud4Tjj0zxUIuHaOOyOznEpMom7t9sd3X4inILipk3jLxnqKcUuJO02eJDri9zq s3oVjFhv2/f248CNVnEpVkb5s8QaS6Y/SZU4rcI3CQtmJi8GWCRHpu4BXbmuxx+TMLbh fLPpu1CZa/iUFWnnIxDONTwdBtLcNhawSIx94SEoZVKGg7kbs78LsfvQGGcMbEjED5dn jL2Rw9EAzPkPSnV/6lQjYFDjywgV+esLsHgjQUafO3LsPLLHfzjF9x6Uk9mgAcm/i4ub ZsgA== 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 y102si1930717ede.370.2021.09.29.01.47.39; Wed, 29 Sep 2021 01:48:03 -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 S244870AbhI2IoB (ORCPT + 99 others); Wed, 29 Sep 2021 04:44:01 -0400 Received: from mga07.intel.com ([134.134.136.100]:13702 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244881AbhI2IoA (ORCPT ); Wed, 29 Sep 2021 04:44:00 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="288550405" X-IronPort-AV: E=Sophos;i="5.85,331,1624345200"; d="scan'208";a="288550405" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 01:42:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,331,1624345200"; d="scan'208";a="520757415" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga001.jf.intel.com with ESMTP; 29 Sep 2021 01:42:15 -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 6/6] perf session: Load single file for analysis Date: Wed, 29 Sep 2021 11:41:54 +0300 Message-Id: <8b3596e5b07af8d90ae76438e6d052058fd76d4f.1632900802.git.alexey.v.bayduraev@linux.intel.com> 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 Adding EOF flag to reader state and moving the check to reader__mmap. Separating reading code of single event into reader__read_event function. Adding basic reader return codes to simplify the code and introducing remap/read_event loop in __perf_session__process_events. 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 | 72 ++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 5e08def72b41..9a4fe78a7a54 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -63,6 +63,13 @@ struct reader_state { u64 file_offset; u64 data_size; u64 head; + bool eof; +}; + +enum { + READER_EOF, + READER_NODATA, + READER_OK, }; struct reader { @@ -2242,6 +2249,11 @@ reader__mmap(struct reader *rd, struct perf_session *session) char *buf, **mmaps = st->mmaps; u64 page_offset; + if (st->file_pos >= st->data_size) { + st->eof = true; + return READER_EOF; + } + mmap_prot = PROT_READ; mmap_flags = MAP_SHARED; @@ -2270,36 +2282,26 @@ reader__mmap(struct reader *rd, struct perf_session *session) mmaps[st->mmap_idx] = st->mmap_cur = buf; st->mmap_idx = (st->mmap_idx + 1) & (ARRAY_SIZE(st->mmaps) - 1); st->file_pos = st->file_offset + st->head; - return 0; + return READER_OK; } static int -reader__process_events(struct reader *rd, struct perf_session *session, - struct ui_progress *prog) +reader__read_event(struct reader *rd, struct perf_session *session, + struct ui_progress *prog) { struct reader_state *st = &rd->state; - u64 size; - int err = 0; + int err = READER_OK; union perf_event *event; + u64 size; s64 skip; -remap: - err = reader__mmap(rd, session); - if (err) - goto out; - if (session->one_mmap) { - session->one_mmap_addr = rd->state.mmap_cur; - session->one_mmap_offset = rd->state.file_offset; - } - -more: event = fetch_mmaped_event(st->head, st->mmap_size, st->mmap_cur, session->header.needs_swap); if (IS_ERR(event)) return PTR_ERR(event); if (!event) - goto remap; + return READER_NODATA; session->active_reader = rd; size = event->header.size; @@ -2321,18 +2323,12 @@ reader__process_events(struct reader *rd, struct perf_session *session, st->head += size; st->file_pos += size; - err = __perf_session__process_decomp_events(session); - if (err) - goto out; + skip = __perf_session__process_decomp_events(session); + if (skip) + err = skip; ui_progress__update(prog, size); - if (session_done()) - goto out; - - if (st->file_pos < st->data_size) - goto more; - out: session->active_reader = NULL; return err; @@ -2369,9 +2365,31 @@ static int __perf_session__process_events(struct perf_session *session) err = reader__init(&rd, &session->one_mmap); if (err) goto out_err; - err = reader__process_events(&rd, session, &prog); - if (err) + err = reader__mmap(&rd, session); + if (err != READER_OK) { + if (err == READER_EOF) + err = -EINVAL; goto out_err; + } + if (session->one_mmap) { + session->one_mmap_addr = rd.state.mmap_cur; + session->one_mmap_offset = rd.state.file_offset; + } + + while (true) { + if (session_done()) + break; + + err = reader__read_event(&rd, session, &prog); + if (err < 0) + break; + if (err == READER_NODATA) { + err = reader__mmap(&rd, session); + if (err <= 0) + break; + } + } + /* do the final flush for ordered samples */ err = ordered_events__flush(oe, OE_FLUSH__FINAL); if (err) -- 2.19.0