Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3490016pxu; Tue, 15 Dec 2020 08:11:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHHrO24riO+62gprakf+eyieJEIcDKQqAjBXh/zjNLTv6xBRipzCmDkYH3agoP5A2+YhxV X-Received: by 2002:a50:d2c8:: with SMTP id q8mr29163264edg.375.1608048690032; Tue, 15 Dec 2020 08:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608048690; cv=none; d=google.com; s=arc-20160816; b=cMWJL9XSsPYSDvIaQsBTgjijKBzOsqWk32uuUJjf/CYU3E0ri1zgW7+WN9fmhlBfC9 251pb19CPGAjJUD6PbiL9HiB9t3dsXYR7qNFfJ3T8Wc0LUe9Aexhp1KmR91GPLrydH5K oWITCPQyRk/INNWqyZf3DXxQYgKkn9ambZRaOtt8tzq+h2mtUkQchToDUwhW0QNKudki lL3S/KUNXQlms5Y8jMhrYAEL8wJe2UZq/IYwr9Me9D++S3mWGM66PJ6ZXNrX4xB9Cc55 9wSahmjY+Vvc7BGXst7C2+aOe/vIM2UGIPoB8vajtyOtaSkE0y7MqXziUQSveW6TjKiV weeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=qMitwddOIRzqBh7ef6yMciFjP/tjz04xwEVFLiWCzg8=; b=LpfR2NFqkPaHyLrorinRJrBD6WGGO2yt2jHz5aoILsXBIIS/8US3sWb49ZSbYWuMlO 5z/mLBWYqIbjSfze9BzVJ735nSsPFc/PtMURA6iNkJVUALL2s/YsfrEV2UiadnjAiy65 W7BIKdBljsZx7ufB4gJ5nnHs/0ja+FaN6Cb22VjOn50CjSomzFozfaxncJjvLuzK7JDw 9OWyMj8CCvBsORwK6x1Tfogi0+0ywDeOqg0/9sXGeOpxUJTYm5l7cXLkOuYUgjM6lGLx hQzowqPlsWVZanAi+X1v0b6H0vVo3PwYyOiVRaGHDnyvusCYco9r/Q+AihkD/WQn5TeO NJWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XbK0APLl; 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 cw14si728625edb.289.2020.12.15.08.11.05; Tue, 15 Dec 2020 08:11:30 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XbK0APLl; 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 S1729652AbgLOQIx (ORCPT + 99 others); Tue, 15 Dec 2020 11:08:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:39448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730330AbgLOPpt (ORCPT ); Tue, 15 Dec 2020 10:45:49 -0500 Date: Tue, 15 Dec 2020 12:45:21 -0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608047108; bh=f+xqfrDWHHZ63Lq2sFUh12EO/RvErlVDz5pIJVg/J10=; h=From:To:Cc:Subject:References:In-Reply-To:From; b=XbK0APLlvjzEKSjuYOLGJvlxBoJiTaO1csiHL0jPa3vTRs53ZfT+dyePW0zI7iIwm hkjAhEKdGWvenjtQk4eIZG+IkiLseBTDAcZ4+6qOxz6wrTWagnGF/KaPNGSO/azH4Z Fa8KS6rdVdnGIsxfaab3/9pQLXHMGKLFvtNdokJzrKjs5JFPD6sa1C3+EixF00Bp1+ af4pzcJuuvWwN90JheBCwsALkOTAL9lgyk4ABXzApRijBqyZqRt4m+IUMtR81qAkr+ hS0qfhjF2dvgEhOnT9+FHvAYoxQoBYSTVbwfIGNCvaDLGDZ/nJmEa0Jpm9M89eksk7 LeQBwno9GrRuw== From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: Re: [PATCH 5/8] perf daemon: Add signal command Message-ID: <20201215154521.GF258566@kernel.org> References: <20201212104358.412065-1-jolsa@kernel.org> <20201212104358.412065-6-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201212104358.412065-6-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Dec 12, 2020 at 11:43:55AM +0100, Jiri Olsa escreveu: > Allow perf daemon to send SIGUSR2 to all running sessions: > > # perf daemon > [1:364758] perf record -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite --switch-output -a > [2:364759] perf record -m 10M -e sched:* -o /opt/perfdata/2/perf.data --overwrite --switch-output -a The above looks ambiguous, is it starting those sessions at this point or is it checking if there is a running daemon and then listing its sessions? - Arnaldo > # perf daemon -s > signal 12 sent to session '1 [92187]' > signal 12 sent to session '2 [92188]' > > Or to specific one: > > # perf daemon --signal=1 > signal 12 sent to session '1 [364758]' > > Signed-off-by: Jiri Olsa > --- > tools/perf/Documentation/perf-daemon.txt | 24 +++++++++++ > tools/perf/builtin-daemon.c | 51 +++++++++++++++++++++++- > 2 files changed, 73 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/Documentation/perf-daemon.txt b/tools/perf/Documentation/perf-daemon.txt > index dee39be110ba..203ec4bf704c 100644 > --- a/tools/perf/Documentation/perf-daemon.txt > +++ b/tools/perf/Documentation/perf-daemon.txt > @@ -30,6 +30,11 @@ OPTIONS > --foreground:: > Do not put the process in background. > > +-s:: > +--signal[=session]:: > + Send SIGUSR2 to specific session, if session is not specified, > + send SIGUSR2 to all sessions. > + > -v:: > --verbose:: > Be more verbose. > @@ -92,6 +97,25 @@ Check sessions with more info: > The 'output' file is perf record output for specific session. > > > +Send SIGUSR2 signal to all sessions: > + > + # perf daemon -s > + signal 12 sent to session '1 [92187]' > + signal 12 sent to session '2 [92188]' > + > +Send SIGUSR2 signal to session '1': > + > + # perf daemon --signal=1 > + signal 12 sent to session '1 [364758]' > + > +And check that the perf data dump was trigered: > + > + # cat /opt/perfdata/2/output > + rounding mmap pages size to 32M (8192 pages) > + [ perf record: dump data: Woken up 1 times ] > + [ perf record: Dump /opt/perfdata/2/perf.data.2020120715220385 ] > + > + > SEE ALSO > -------- > linkperf:perf-record[1], linkperf:perf-config[1] > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c > index 7f455837d58a..c53d4ddc2b49 100644 > --- a/tools/perf/builtin-daemon.c > +++ b/tools/perf/builtin-daemon.c > @@ -450,9 +450,15 @@ static int setup_server_socket(struct daemon *daemon) > enum cmd { > CMD_LIST = 0, > CMD_LIST_VERBOSE = 1, > + CMD_SIGNAL = 2, > CMD_MAX, > }; > > +struct cmd_signal { > + int sig; > + char name[16]; > +}; > + > static int cmd_session_list(struct daemon *daemon, FILE *out, bool simple) > { > struct session *session; > @@ -469,6 +475,28 @@ static int cmd_session_list(struct daemon *daemon, FILE *out, bool simple) > return 0; > } > > +static int cmd_session_kill(struct daemon *daemon, FILE *out, int fd) > +{ > + struct session *session; > + struct cmd_signal data; > + bool all = false; > + > + if (sizeof(data) != read(fd, &data, sizeof(data))) > + return -1; > + > + all = !strcmp(data.name, "all"); > + > + list_for_each_entry(session, &daemon->sessions, list) { > + if (all || !strcmp(data.name, session->name)) { > + session__signal(session, data.sig); > + fprintf(out, "signal %d sent to session '%s [%d]'\n", > + data.sig, session->name, session->pid); > + } > + } > + > + return 0; > +} > + > static int handle_server_socket(struct daemon *daemon, int sock_fd) > { > int ret = -EINVAL, fd; > @@ -497,6 +525,9 @@ static int handle_server_socket(struct daemon *daemon, int sock_fd) > case CMD_LIST_VERBOSE: > ret = cmd_session_list(daemon, out, cmd == CMD_LIST); > break; > + case CMD_SIGNAL: > + ret = cmd_session_kill(daemon, out, fd); > + break; > default: > break; > } > @@ -730,8 +761,9 @@ static int __cmd_daemon(struct daemon *daemon, bool foreground, const char *conf > return err; > } > > -static int send_cmd(struct daemon *daemon, u64 cmd) > +static int send_cmd(struct daemon *daemon, u64 cmd, const char *str) > { > + struct cmd_signal data; > char *line = NULL; > size_t len = 0; > ssize_t nread; > @@ -747,6 +779,14 @@ static int send_cmd(struct daemon *daemon, u64 cmd) > if (sizeof(cmd) != write(fd, &cmd, sizeof(cmd))) > return -1; > > + if (cmd == CMD_SIGNAL) { > + data.sig = SIGUSR2; > + strncpy(data.name, str, sizeof(data.name) - 1); > + > + if (sizeof(data) != write(fd, &data, sizeof(data))) > + return -1; > + } > + > in = fdopen(fd, "r"); > if (!in) { > perror("fopen"); > @@ -770,7 +810,9 @@ static const char * const daemon_usage[] = { > int cmd_daemon(int argc, const char **argv) > { > bool foreground = false; > + bool signal = false; > const char *config = NULL; > + const char *signal_str = NULL; > struct daemon daemon = { > .sessions = LIST_HEAD_INIT(daemon.sessions), > .out = stdout, > @@ -780,6 +822,8 @@ int cmd_daemon(int argc, const char **argv) > OPT_STRING(0, "config", &config, > "config file", "config file path"), > OPT_BOOLEAN('f', "foreground", &foreground, "stay on console"), > + OPT_STRING_OPTARG_SET('s', "signal", &signal_str, &signal, > + "signal", "send signal to session", "all"), > OPT_END() > }; > > @@ -790,5 +834,8 @@ int cmd_daemon(int argc, const char **argv) > if (config) > return __cmd_daemon(&daemon, foreground, config); > > - return send_cmd(&daemon, verbose ? CMD_LIST_VERBOSE : CMD_LIST); > + if (signal) > + return send_cmd(&daemon, CMD_SIGNAL, signal_str); > + > + return send_cmd(&daemon, verbose ? CMD_LIST_VERBOSE : CMD_LIST, NULL); > } > -- > 2.26.2 > -- - Arnaldo