Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2883459ima; Sun, 3 Feb 2019 08:42:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN5SrrCa18Nhlvf8gjXo9aCvFUsKSrm93o5SvXDo3a6UbrbP9sU+V0YAfX856QjYCLBK9llj X-Received: by 2002:a62:26c7:: with SMTP id m190mr48655337pfm.79.1549212159386; Sun, 03 Feb 2019 08:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549212159; cv=none; d=google.com; s=arc-20160816; b=tnsQEPOiyNObXbUI5jD1Skk1JLpENyIXQXisV5OVVPsv0moNUE8hoU86JZMLskOJyU vCeYEttGpeQCICtXuPah4ODtgkVLQ8QsixCLTHgZeDv0MTXa9r1KpvnzYldsO6nNn5Bh WLeKt1Iraawmwy1IYfQP8/RrZr8dxrrLeZNXPPaKUXJrkKpPzF0UfJOX/ZC6EyP+4k8N RrliEySTV6dcaNs6K9CVq4OnhphIxl1pLQ3CzG4NrexpwvC3Xgnr4y/bPJ6HG+lcgGeL vgYoGwoJ9fREXVO7WCuWvwRl4X12M2QZOZPc84J7dgXb+tfILQWjq+dult7rsJc9Zxgj Iq+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=nSNU/w3vFv8goQt/VUwQEDlp1WX0F4gL4KBVP3y4RKo=; b=e0LvUCZeDIQWMheXGPtfPdrGYsOmXk0lcmhfksHGb1DgvWE5DUZ26+D6lWJ6BX1CZa +z+GS31qr41GprHmkt/lV0Jlq/JZuD1Dy3XyxIgfZwjgpRlasjrDreIq9CmwP3T5EVnj 8a1QOJNSuAZv8f4Xy10BBC4oVIa5cw0A7leG773Ji3l7eeHm168hfTes03jePe/y4mXT upEspvI7BN912mTEGl8oJ59q8DZWofGx2HtNPlJ+v6fkkoooz6OhIvO7YnwkvJ+MMn1w n82v3/bYTqDXrHJ9bG3srlJShMcQdG1Qo56160E0LzmQAJsOl/K84678Oj1zaQUG23+f tEjQ== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n184si8866979pgn.95.2019.02.03.08.42.24; Sun, 03 Feb 2019 08:42:39 -0800 (PST) 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728453AbfBCPap (ORCPT + 99 others); Sun, 3 Feb 2019 10:30:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33054 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728266AbfBCPal (ORCPT ); Sun, 3 Feb 2019 10:30:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F00C14E916; Sun, 3 Feb 2019 15:30:40 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-46.brq.redhat.com [10.40.204.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E91C5C238; Sun, 3 Feb 2019 15:30:38 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Adrian Hunter , Andi Kleen , Stephane Eranian , Alexey Budankov Subject: [PATCH 06/14] perf data: Add perf_data__(create_dir|free_dir) functions Date: Sun, 3 Feb 2019 16:30:10 +0100 Message-Id: <20190203153018.9650-7-jolsa@kernel.org> In-Reply-To: <20190203153018.9650-1-jolsa@kernel.org> References: <20190203153018.9650-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 03 Feb 2019 15:30:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding perf_data__create_dir to create nr files inside struct perf_data path directory: int perf_data__create_dir(struct perf_data *data, int nr); and function to free that data: void perf_data__free_dir(struct perf_data *data); Link: http://lkml.kernel.org/n/tip-kl4s1f13cg6wycrg367p85qm@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/data.c | 47 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/data.h | 8 +++++++ 2 files changed, 55 insertions(+) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index 0a3051cc0ea0..ff1d9e5bd68d 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -7,11 +7,58 @@ #include #include #include +#include #include "data.h" #include "util.h" #include "debug.h" +static void free_dir(struct perf_data_file *files, int nr) +{ + while (--nr >= 1) { + close(files[nr].fd); + free(files[nr].path); + } + free(files); +} + +void perf_data__free_dir(struct perf_data *data) +{ + free_dir(data->dir.files, data->dir.nr); +} + +int perf_data__create_dir(struct perf_data *data, int nr) +{ + struct perf_data_file *files = NULL; + int i, ret = -1; + + files = malloc(nr * sizeof(*files)); + if (!files) + return -ENOMEM; + + data->dir.files = files; + data->dir.nr = nr; + + for (i = 0; i < nr; i++) { + struct perf_data_file *file = &files[i]; + + if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0) + goto out_err; + + ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); + if (ret < 0) + goto out_err; + + file->fd = ret; + } + + return 0; + +out_err: + free_dir(files, i); + return ret; +} + static bool check_pipe(struct perf_data *data) { struct stat st; diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h index 2bce28117ccf..3b4115dc777f 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h @@ -21,6 +21,11 @@ struct perf_data { bool is_pipe; bool force; enum perf_data_mode mode; + + struct { + struct perf_data_file *files; + int nr; + } dir; }; static inline bool perf_data__is_read(struct perf_data *data) @@ -64,4 +69,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file, int perf_data__switch(struct perf_data *data, const char *postfix, size_t pos, bool at_exit); + +int perf_data__create_dir(struct perf_data *data, int nr); +void perf_data__free_dir(struct perf_data *data); #endif /* __PERF_DATA_H */ -- 2.17.2