Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp53634pxv; Tue, 29 Jun 2021 23:16:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK4ffkx3d4enXzhu+6UR+MsFeKS0fw/p3wHGGkNaU63Hj5U34c104yq03+/nGYl6eUNMWn X-Received: by 2002:a17:907:628d:: with SMTP id nd13mr32890636ejc.299.1625033771397; Tue, 29 Jun 2021 23:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625033771; cv=none; d=google.com; s=arc-20160816; b=h3l1w4FLhJwPfnlEKrEoCHkAK5EzzN6mlKJqHJYQ+yWtwAy4FwVduEZMtMloExzWjO 7qgDMBcGWKeLCB69hAmYYanRT3LuaplUyWztUU2MCrsdu4+OgcqR39y4+mCuFy0JfWje 5mQyDe1vAEXSrH9/ut1HVMW2yzJn1aVYdBVSPDY75X5ZQIwADbYGojtEIK0N4J0IZi4X 3ilyb/sKn6TCsII3VPHo3WaWuF1Ly97s159lAeGq7828ACseAuThiz8/UJltKE1bjymT f9bmUN14xb+VqOSrG1acCJu30LmjLWr/aI3NdyeeMU50GYwKSbl/+2waEtDpnNr4Jyuf PqUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=DT1VEhZeNr6s/86X+UE2qNX8jcV0kx4gFWwnom6ABS4=; b=jO/mA/rWrVlPit7yoyWamq6/g6P/Xq6AZUOme/eleWA6gN9sO6DYbDMSAT0FinT89l 89h86AFVHtX1yFKnfPH7/MOH22Ln8asArDS9tgjYEu9gvL0ruOkioBFMy1Rjim5AwL72 JnJ/UMmeoJ+MUg1bG8t8fbSHaxgTvJnKD7/AB/oAK2OqjkzbUUuzH7jjmhMZDH9ynOnP lcZtCtCLlJXLj4NEtnpD/FqTWjkZ0o4mVcz08wHBFU+uNCb7ABGpfsZ1YZ69moPi9nN7 j5fIC4HscKFlpGBePGPrPFr+QyD0FhK3UOa/Eeltsv9InHjBcpxxyvlJBH9EepjcScQm 0igg== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eo21si20741494ejc.27.2021.06.29.23.15.47; Tue, 29 Jun 2021 23:16:11 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232304AbhF3GRY (ORCPT + 99 others); Wed, 30 Jun 2021 02:17:24 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:37646 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbhF3GRX (ORCPT ); Wed, 30 Jun 2021 02:17:23 -0400 Received: by mail-lf1-f44.google.com with SMTP id q16so2982491lfr.4 for ; Tue, 29 Jun 2021 23:14:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DT1VEhZeNr6s/86X+UE2qNX8jcV0kx4gFWwnom6ABS4=; b=oDhg8dUYtTp60DJhcTrO5q8/7NBZk3yxXHda8IGFHrea1LdUqvKiwwaw1sTV097Bnh RJs9GPJTY3Pr75pu1AhW4OZ3kupqTCKVRW0EXvkDpcfLc9u6x+/XwnMccbO2+KzQPgEi hIQPZyFq/gbcmeVk9dqO9JD7nENlq3mgfwdZ0JJxay0yUuIpAJFNtGnjtMTg9fpUtwLv 7x7AX2zCucqAaPTIcQqcqCuuNxhSK2Li3KdsJwzXcP6my0yZLJfP2FuCaq94UdAKQ9fj 3f7D/zBGN5GtF4GLSktPCpfkhS88nnpMBVKdTbu5T2Cmwd1m9HxWoQTnYwDcN4Y9t7Ry QEHg== X-Gm-Message-State: AOAM533aOhrx25eVQ0pIRK9FNeQuqbZdtWaatdcNAjDigIDP/2t9Zjy/ LSBcmV89rsfxOlBg+V1ZX3mZuxsQKs6PWhrNU9Q= X-Received: by 2002:a19:4916:: with SMTP id w22mr27067838lfa.374.1625033694646; Tue, 29 Jun 2021 23:14:54 -0700 (PDT) MIME-Version: 1.0 References: <036fbbd11ffd0d0c9338ef61a0076685ac502000.1624350588.git.alexey.v.bayduraev@linux.intel.com> In-Reply-To: <036fbbd11ffd0d0c9338ef61a0076685ac502000.1624350588.git.alexey.v.bayduraev@linux.intel.com> From: Namhyung Kim Date: Tue, 29 Jun 2021 23:14:43 -0700 Message-ID: Subject: Re: [PATCH v7 20/20] perf session: Load data directory files for analysis To: Alexey Bayduraev Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 22, 2021 at 1:43 AM Alexey Bayduraev wrote: > > Load data directory files and provide basic raw dump and aggregated > analysis support of data directories in report mode, still with no > memory consumption optimizations. > > Design and implementation are based on the prototype [1], [2]. > > [1] git clone https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git -b perf/record_threads > [2] https://lore.kernel.org/lkml/20180913125450.21342-1-jolsa@kernel.org/ > > Suggested-by: Jiri Olsa > Signed-off-by: Alexey Bayduraev > --- > tools/perf/util/session.c | 129 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 129 insertions(+) > > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index fe25abf83b80..2c0eb126cdbb 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -65,6 +65,7 @@ struct reader_state { > u64 data_size; > u64 head; > bool eof; > + u64 size; > }; > > enum { > @@ -2322,6 +2323,7 @@ reader__read_event(struct reader *rd, struct perf_session *session, > if (skip) > size += skip; > > + st->size += size; > st->head += size; > st->file_pos += size; > > @@ -2421,6 +2423,130 @@ static int __perf_session__process_events(struct perf_session *session) > return err; > } > > +/* > + * This function reads, merge and process directory data. > + * It assumens the version 1 of directory data, where each > + * data file holds per-cpu data, already sorted by kernel. > + */ > +static int __perf_session__process_dir_events(struct perf_session *session) > +{ > + struct perf_data *data = session->data; > + struct perf_tool *tool = session->tool; > + int i, ret = 0, readers = 1; > + struct ui_progress prog; > + u64 total_size = perf_data__size(session->data); > + struct reader *rd; > + > + perf_tool__fill_defaults(tool); > + > + ui_progress__init_size(&prog, total_size, "Sorting events..."); > + > + for (i = 0; i < data->dir.nr; i++) { > + if (data->dir.files[i].size) > + readers++; > + } > + > + rd = session->readers = zalloc(readers * sizeof(struct reader)); > + if (!rd) > + return -ENOMEM; > + session->nr_readers = readers; > + readers = 0; > + > + rd[readers] = (struct reader) { > + .fd = perf_data__fd(session->data), > + .path = session->data->file.path, > + .data_size = session->header.data_size, > + .data_offset = session->header.data_offset, > + .in_place_update = session->data->in_place_update, > + }; > + ret = reader__init(&rd[readers], NULL); > + if (ret) > + goto out_err; > + ret = reader__mmap(&rd[readers], session); > + if (ret != READER_OK) { > + if (ret == READER_EOF) > + ret = -EINVAL; > + goto out_err; > + } > + readers++; > + > + for (i = 0; i < data->dir.nr; i++) { > + if (data->dir.files[i].size) { Just one more nitpicking. :) You can save an indent depth by having if (!data->dir.files[i].size) continue; Thanks, Namhyung > + rd[readers] = (struct reader) { > + .fd = data->dir.files[i].fd, > + .path = data->dir.files[i].path, > + .data_size = data->dir.files[i].size, > + .data_offset = 0, > + .in_place_update = session->data->in_place_update, > + }; > + ret = reader__init(&rd[readers], NULL); > + if (ret) > + goto out_err; > + ret = reader__mmap(&rd[readers], session); > + if (ret != READER_OK) { > + if (ret == READER_EOF) > + ret = -EINVAL; > + goto out_err; > + } > + readers++; > + } > + }