Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4313753pxb; Mon, 8 Feb 2021 13:15:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMgEN+lWEH+uQJUiAxjAdIWWlpF3FN8fiSBPVql1Trl3toVHa5PSbvVe04R9PQv+O9F8dE X-Received: by 2002:aa7:cdcd:: with SMTP id h13mr19077400edw.11.1612818903525; Mon, 08 Feb 2021 13:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612818903; cv=none; d=google.com; s=arc-20160816; b=Mqnn4ThcTFf8TX1NxeVuTUESUVxegrRztWiqvQd7LQ+3XF/ACNBXjXRihYG07De5DS sOu8cO2rhie7G28Uh5dXizaCTPYgE6HUah0A6hiWLoIainnxcx1XvYae6Bzft2fCqT6A Kz9jAk4v7HKq90xmPdkUT2FGBlWGCGm+Cb7UUvOYg8c+tAO50KDvxV864tlBJZjGFzBX 8a0w5GrUNfBKj2SkvlKt2cG6elRpq5kN6YOsBRMom/ZcqKo8Y70TdiThfmqAHgI+wUQU 9vxy7G+KDN1qdmvn4ybTij/S4d+8+eWDZEYmSAeuolLI/9eUHzv5P3uMrbeFmGNaNcr3 1K9w== 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=jAiZoDboGClJOCbOI09xRb4bJ1M7pnzAJ+NoVKLy/Po=; b=c1SytEc7Q7SD07XbOjVN5k4Jz1H2M1sZyfQSSVT6oUjvax4j3a6nhRua3luyjqZyyG dq/ARf0rnDy6oxxehV2t4aWVhL1iWCWv67cehke40iBVgQzasjv3LKgaWU78AN0W8Ez8 FOuW80VR8ievEB4Z/ZW3TVtoqE19/Ilel1Cz/8Mz3o1Fx7Vfa/6+UwWo70vvey09deNV Hz5zNrgmGYClWxnn9ER1ZeaSML/Hddb6caqVgr9Txun6DdSU222uRyngDTtJqfLqCwUJ JjpLSMq3EHgdLUWHLB4Fyuc2BhQkpki2Zf1BMrfW0pNuMXxYSVzyZP4E6151fkkeS7FF zS/g== 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 r21si14085936ejo.142.2021.02.08.13.14.39; Mon, 08 Feb 2021 13:15:03 -0800 (PST) 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 S231178AbhBHVNv convert rfc822-to-8bit (ORCPT + 99 others); Mon, 8 Feb 2021 16:13:51 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:36298 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232967AbhBHUKh (ORCPT ); Mon, 8 Feb 2021 15:10:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-527-3KyexpOVPPWtRJZBzz-4bQ-1; Mon, 08 Feb 2021 15:09:41 -0500 X-MC-Unique: 3KyexpOVPPWtRJZBzz-4bQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A8C980364B; Mon, 8 Feb 2021 20:09:38 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E8F719C59; Mon, 8 Feb 2021 20:09:35 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Alexei Budankov Subject: [PATCH 10/24] perf daemon: Add list command Date: Mon, 8 Feb 2021 21:08:54 +0100 Message-Id: <20210208200908.1019149-11-jolsa@kernel.org> In-Reply-To: <20210208200908.1019149-1-jolsa@kernel.org> References: <20210208200908.1019149-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding list command to display all running sessions. It's the default command if no other command is specified. Example: # cat ~/.perfconfig [daemon] base=/opt/perfdata [session-cycles] run = -m 10M -e cycles --overwrite --switch-output -a [session-sched] run = -m 20M -e sched:* --overwrite --switch-output -a Starting the daemon: # perf daemon start List sessions: # perf daemon [771394:daemon] base: /opt/perfdata [771395:cycles] perf record -m 10M -e cycles --overwrite --switch-output -a [771396:sched] perf record -m 20M -e sched:* --overwrite --switch-output -a List sessions with more info: # perf daemon -v [771394:daemon] base: /opt/perfdata output: /opt/perfdata/output [771395:cycles] perf record -m 10M -e cycles --overwrite --switch-output -a base: /opt/perfdata/session-cycles output: /opt/perfdata/session-cycles/output [771396:sched] perf record -m 20M -e sched:* --overwrite --switch-output -a base: /opt/perfdata/session-sched output: /opt/perfdata/session-sched/output The 'output' file is perf record output for specific session. Note you have to stop all running perf processes manually at this point, stop command is coming in following patches. Signed-off-by: Jiri Olsa --- tools/perf/builtin-daemon.c | 89 +++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c index 8b834a5d91ff..8a0994b0dfce 100644 --- a/tools/perf/builtin-daemon.c +++ b/tools/perf/builtin-daemon.c @@ -81,6 +81,7 @@ struct daemon { const char *config; char *config_real; char *config_base; + const char *csv_sep; const char *base_user; char *base; struct list_head sessions; @@ -528,11 +529,78 @@ static int setup_server_socket(struct daemon *daemon) return fd; } +enum { + CMD_LIST = 0, + CMD_MAX, +}; + union cmd { int cmd; + + /* CMD_LIST */ + struct { + int cmd; + int verbose; + char csv_sep; + } list; }; -static int handle_server_socket(struct daemon *daemon __maybe_unused, int sock_fd) +static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out) +{ + char csv_sep = cmd->list.csv_sep; + struct daemon_session *session; + + if (csv_sep) { + fprintf(out, "%d%c%s%c%s%c%s/%s", + /* pid daemon */ + getpid(), csv_sep, "daemon", + /* base */ + csv_sep, daemon->base, + /* output */ + csv_sep, daemon->base, SESSION_OUTPUT); + + fprintf(out, "\n"); + } else { + fprintf(out, "[%d:daemon] base: %s\n", getpid(), daemon->base); + if (cmd->list.verbose) { + fprintf(out, " output: %s/%s\n", + daemon->base, SESSION_OUTPUT); + } + } + + list_for_each_entry(session, &daemon->sessions, list) { + if (csv_sep) { + fprintf(out, "%d%c%s%c%s", + /* pid */ + session->pid, + /* name */ + csv_sep, session->name, + /* base */ + csv_sep, session->run); + + fprintf(out, "%c%s%c%s/%s", + /* session dir */ + csv_sep, session->base, + /* session output */ + csv_sep, session->base, SESSION_OUTPUT); + + fprintf(out, "\n"); + } else { + fprintf(out, "[%d:%s] perf record %s\n", + session->pid, session->name, session->run); + if (!cmd->list.verbose) + continue; + fprintf(out, " base: %s\n", + session->base); + fprintf(out, " output: %s/%s\n", + session->base, SESSION_OUTPUT); + } + } + + return 0; +} + +static int handle_server_socket(struct daemon *daemon, int sock_fd) { int ret = -1, fd; FILE *out = NULL; @@ -556,6 +624,9 @@ static int handle_server_socket(struct daemon *daemon __maybe_unused, int sock_f } switch (cmd.cmd) { + case CMD_LIST: + ret = cmd_session_list(daemon, &cmd, out); + break; default: break; } @@ -968,7 +1039,6 @@ static int __cmd_start(struct daemon *daemon, struct option parent_options[], return err; } -__maybe_unused static int send_cmd(struct daemon *daemon, union cmd *cmd) { int ret = -1, fd; @@ -1009,6 +1079,17 @@ static int send_cmd(struct daemon *daemon, union cmd *cmd) return ret; } +static int send_cmd_list(struct daemon *daemon) +{ + union cmd cmd = { + .list.cmd = CMD_LIST, + .list.verbose = verbose, + }; + + cmd.list.csv_sep = daemon->csv_sep ? *daemon->csv_sep : 0; + return send_cmd(daemon, &cmd); +} + int cmd_daemon(int argc, const char **argv) { struct option daemon_options[] = { @@ -1017,6 +1098,8 @@ int cmd_daemon(int argc, const char **argv) "config file", "config file path"), OPT_STRING(0, "base", &__daemon.base_user, "directory", "base directory"), + OPT_STRING_OPTARG('x', "field-separator", &__daemon.csv_sep, + "field separator", "print counts with custom separator", ","), OPT_END() }; @@ -1039,5 +1122,5 @@ int cmd_daemon(int argc, const char **argv) return -1; } - return -1; + return send_cmd_list(&__daemon); } -- 2.29.2