Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4311963pxb; Mon, 8 Feb 2021 13:12:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJywOTTZ3LTl+kpLBEo0u/AQXPwMN6f8SpXnsXZdDVY5CyXOg9SdvmYKaVb4ySToNWzUleWX X-Received: by 2002:a05:6402:5211:: with SMTP id s17mr19097302edd.312.1612818733858; Mon, 08 Feb 2021 13:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612818733; cv=none; d=google.com; s=arc-20160816; b=XMFysv2lXJcd2GBRH9TWoq/auSCHp7Ijm81eh06PAAg1zcXe0pVbR8DaruT4NVfu4L sfJCvOz8hpxR0Z42F8OvqbUPCtz1ZD07/XPFW4SWkPOLk4EuZwR3ILhMauSnU7HH9zIX 0NhWWsNPbnp2FB9O60zckcBTj3611iytrklaqIzZCdwxeKc0Z0MoMi9S9tAgC1nob0sL YsD6wQGz70+niOX5qmKmnl3IsVuaAIaTjSgksSpzXSSBwu3H78kyRqTuY9PSYfadLqef CH3Dmn8UjvjpZcwxM8nWJqnZILV3XVW3ucZOaUFx647eHUH6y9HTGlU8e8b8N/VqXJNY vOGQ== 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 :message-id:date:subject:cc:to:from; bh=r+j263vtonHcmGz3GChlGzHB7+NzK2+ruAGYJbP7dqs=; b=XDBU/t16LUAzOj50RpdLIFn543SRAIAxd/tV7UhvFLwITIfNBMos6gD+MwRrHjU5iC 1ffsHy2w7/wN7BdumLiT5+0DxxTQjKY3xTxpejnGh62k7U+CJT6XFQ3Zcen+te7iNJsP yLCoC2eZCvV3MJjj09d1990D1VD1oLP/qHC54p/7rQkoqJNM9vEnB0yWJAyaRSMTcXxV qfJHutSiFCDaaqfENBgxmw8JfRkG94CMmeCEcRWGHDjRU3PE6mcIj9SFqqe5tUdzxIX4 hwG0jr6g/vcamiM+5TpqqSCB+5cBhxvG4XIt/qwvC25MjtLiBOB3n//v31/syK+/dE2e dc8A== 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 d24si11761851edt.102.2021.02.08.13.11.48; Mon, 08 Feb 2021 13:12:13 -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 S232535AbhBHVLO convert rfc822-to-8bit (ORCPT + 99 others); Mon, 8 Feb 2021 16:11:14 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:36204 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236680AbhBHUKP (ORCPT ); Mon, 8 Feb 2021 15:10:15 -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-422-QkL8OILuNVaQjP_dVFhR5g-1; Mon, 08 Feb 2021 15:09:14 -0500 X-MC-Unique: QkL8OILuNVaQjP_dVFhR5g-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 DCBAF8030C2; Mon, 8 Feb 2021 20:09:11 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.194.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AAAB19C59; Mon, 8 Feb 2021 20:09:09 +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: [PATCHv4 00/24] perf tools: Add daemon command Date: Mon, 8 Feb 2021 21:08:44 +0100 Message-Id: <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 hi, we were asked for possibility to be able run record sessions on background. This patchset adds support to configure and run record sessions on background via new 'perf daemon' command. Please check below the example on usage. Available also here: git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git perf/daemon v4 changes: - update man page gradually in each patch [Arnaldo] - fixes in network code, add error handling [Arnaldo] - use readn/writen functions where possible [Arnaldo] - add more error checks for poll [Arnaldo] - use strlcpy in socket setup code [Arnaldo] - free/delete renames [Arnaldo] - add more error checks in check_base [Namhyung] - rename session -> daemon_session plus related functions renames [Namhyung] - man page updates v3 changes: - several patches merged - add comments to daemon locking [Namhyung] - split patch 1 to multiple patches [Namhyung] - add missing allocation checks [Namhyung] - add comments for session state transitions [Namhyung] - add base directory check [Namhyung] - use ',' as default for -x option [Namhyung] - remove extra close before dup2 [Namhyung] - add new reconfig test for empty config - add --base option v2 changes: - switch options to sub-commands [Namhyung] - use signalfd to track on sessions [Alexei] - use stop command to stop sessions [Alexei] - couple minor fixes [Alexei] - more detailed changelogs [Arnaldo] - added tests thanks, jirka --- Jiri Olsa (24): perf daemon: Add daemon command perf daemon: Add config option perf daemon: Add base option perf daemon: Add server socket support perf daemon: Add client socket support perf daemon: Add config file support perf daemon: Add config file change check perf daemon: Add background support perf daemon: Add signalfd support perf daemon: Add list command perf daemon: Add signal command perf daemon: Add stop command perf daemon: Allow only one daemon over base directory perf daemon: Set control fifo for session perf daemon: Add ping command perf daemon: Use control to stop session perf daemon: Add up time for daemon/session list perf daemon: Add examples to man page perf tests: Add daemon list command test perf tests: Add daemon reconfig test perf tests: Add daemon stop command test perf tests: Add daemon signal command test perf tests: Add daemon ping command test perf tests: Add daemon lock test tools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 14 ++ tools/perf/Documentation/perf-daemon.txt | 208 +++++++++++++++++++++++ tools/perf/builtin-daemon.c | 1506 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + tools/perf/tests/shell/daemon.sh | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 2207 insertions(+) create mode 100644 tools/perf/Documentation/perf-daemon.txt create mode 100644 tools/perf/builtin-daemon.c create mode 100755 tools/perf/tests/shell/daemon.sh --- Example with 2 record sessions: # 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 Check sessions: # perf daemon [603349:daemon] base: /opt/perfdata [603350:cycles] perf record -m 10M -e cycles --overwrite --switch-output -a [603351:sched] perf record -m 20M -e sched:* --overwrite --switch-output -a First line is daemon process info with configured daemon base. Check sessions with more info: # perf daemon -v [603349:daemon] base: /opt/perfdata output: /opt/perfdata/output lock: /opt/perfdata/lock up: 1 minutes [603350:cycles] perf record -m 10M -e cycles --overwrite --switch-output -a base: /opt/perfdata/session-cycles output: /opt/perfdata/session-cycles/output control: /opt/perfdata/session-cycles/control ack: /opt/perfdata/session-cycles/ack up: 1 minutes [603351:sched] perf record -m 20M -e sched:* --overwrite --switch-output -a base: /opt/perfdata/session-sched output: /opt/perfdata/session-sched/output control: /opt/perfdata/session-sched/control ack: /opt/perfdata/session-sched/ack up: 1 minutes The 'base' path is daemon/session base. The 'lock' file is daemon's lock file guarding that no other daemon is running on top of the base. The 'output' file is perf record output for specific session. The 'control' and 'ack' files are perf control files. The 'up' number shows minutes daemon/session is running. Make sure control session is online: # perf daemon ping OK cycles OK sched Send USR2 signal to session 'cycles' to generate perf.data file: # perf daemon signal --session cycles signal 12 sent to session 'cycles [603452]' # tail -2 /opt/perfdata/session-cycles/output [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2020123017013149 ] Send USR2 signal to all sessions: # perf daemon signal signal 12 sent to session 'cycles [603452]' signal 12 sent to session 'sched [603453]' # tail -2 /opt/perfdata/session-cycles/output [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2020123017024689 ] # tail -2 /opt/perfdata/session-sched/output [ perf record: dump data: Woken up 1 times ] [ perf record: Dump perf.data.2020123017024713 ] Stop daemon: # perf daemon stop