All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Ian Rogers <irogers@google.com>,
	Alexei Budankov <abudankov@huawei.com>
Subject: [PATCH 10/24] perf daemon: Add list command
Date: Mon,  8 Feb 2021 21:08:54 +0100	[thread overview]
Message-ID: <20210208200908.1019149-11-jolsa@kernel.org> (raw)
In-Reply-To: <20210208200908.1019149-1-jolsa@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 <jolsa@kernel.org>
---
 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


  parent reply	other threads:[~2021-02-08 21:14 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 20:08 [PATCHv4 00/24] perf tools: Add daemon command Jiri Olsa
2021-02-08 20:08 ` [PATCH 01/24] perf daemon: " Jiri Olsa
2021-02-08 20:08 ` [PATCH 02/24] perf daemon: Add config option Jiri Olsa
2021-02-08 20:08 ` [PATCH 03/24] perf daemon: Add base option Jiri Olsa
2021-02-08 20:08 ` [PATCH 04/24] perf daemon: Add server socket support Jiri Olsa
2021-02-08 20:08 ` [PATCH 05/24] perf daemon: Add client " Jiri Olsa
2021-02-11 12:52   ` Arnaldo Carvalho de Melo
2021-02-11 16:35     ` Jiri Olsa
2021-02-08 20:08 ` [PATCH 06/24] perf daemon: Add config file support Jiri Olsa
2021-02-11  6:01   ` Namhyung Kim
2021-02-11 16:45     ` Jiri Olsa
2021-02-11 17:10       ` Arnaldo Carvalho de Melo
2021-02-11 22:52         ` Jiri Olsa
2021-02-08 20:08 ` [PATCH 07/24] perf daemon: Add config file change check Jiri Olsa
2021-02-08 20:08 ` [PATCH 08/24] perf daemon: Add background support Jiri Olsa
2021-02-08 20:08 ` [PATCH 09/24] perf daemon: Add signalfd support Jiri Olsa
2021-02-08 20:08 ` Jiri Olsa [this message]
2021-02-08 20:08 ` [PATCH 11/24] perf daemon: Add signal command Jiri Olsa
2021-02-08 20:08 ` [PATCH 12/24] perf daemon: Add stop command Jiri Olsa
2021-02-08 20:08 ` [PATCH 13/24] perf daemon: Allow only one daemon over base directory Jiri Olsa
2021-02-11 13:20   ` Arnaldo Carvalho de Melo
2021-02-11 16:35     ` Jiri Olsa
2021-02-08 20:08 ` [PATCH 14/24] perf daemon: Set control fifo for session Jiri Olsa
2021-02-08 20:08 ` [PATCH 15/24] perf daemon: Add ping command Jiri Olsa
2021-02-10 12:51   ` Arnaldo Carvalho de Melo
2021-02-10 13:27     ` Jiri Olsa
2021-02-08 20:09 ` [PATCH 16/24] perf daemon: Use control to stop session Jiri Olsa
2021-02-08 20:09 ` [PATCH 17/24] perf daemon: Add up time for daemon/session list Jiri Olsa
2021-02-08 20:09 ` [PATCH 18/24] perf daemon: Add examples to man page Jiri Olsa
2021-02-08 20:09 ` [PATCH 19/24] perf tests: Add daemon list command test Jiri Olsa
2021-02-08 20:09 ` [PATCH 20/24] perf tests: Add daemon reconfig test Jiri Olsa
2021-02-08 20:09 ` [PATCH 21/24] perf tests: Add daemon stop command test Jiri Olsa
2021-02-08 20:09 ` [PATCH 22/24] perf tests: Add daemon signal " Jiri Olsa
2021-02-08 20:09 ` [PATCH 23/24] perf tests: Add daemon ping " Jiri Olsa
2021-02-08 20:09 ` [PATCH 24/24] perf tests: Add daemon lock test Jiri Olsa
     [not found] <20210129134855.195810-1-jolsa@redhat.com>
2021-01-30 23:48 ` [PATCHv3 00/24] perf tools: Add daemon command Jiri Olsa
2021-01-30 23:48   ` [PATCH 10/24] perf daemon: Add list command Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210208200908.1019149-11-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=abudankov@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.