Skip to content

perf tools: Add daemon command

Jiri Olsa lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest24 patches 10 repliesIn review
  2. v324 patches 32 repliesSuperseded
  3. v222 patches 21 repliesApplied
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC8 patches18 repliesApplied

Changes in v4 from the cover letter

- 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

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/24perf daemon: Add daemon commandtools/perf/Build tools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c +3 more+130 -00 replies
2/24perf daemon: Add config optiontools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+48 -00 replies
3/24perf daemon: Add base optiontools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+15 -00 replies
4/24perf daemon: Add server socket supporttools/perf/builtin-daemon.c+116 -10 replies
5/24perf daemon: Add client socket supporttools/perf/builtin-daemon.c+135 -02 replies
6/24perf daemon: Add config file supporttools/perf/Documentation/perf-config.txt tools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+393 -24 replies
7/24perf daemon: Add config file change checktools/perf/builtin-daemon.c+97 -30 replies
8/24perf daemon: Add background supporttools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+66 -00 replies
9/24perf daemon: Add signalfd supporttools/perf/builtin-daemon.c+155 -60 replies
10/24perf daemon: Add list commandtools/perf/builtin-daemon.c+86 -30 replies
11/24perf daemon: Add signal commandtools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+77 -70 replies
12/24perf daemon: Add stop commandtools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+35 -00 replies
13/24perf daemon: Allow only one daemon over base directorytools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+63 -12 replies
14/24perf daemon: Set control fifo for sessiontools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+28 -10 replies
15/24perf daemon: Add ping commandtools/perf/Documentation/perf-daemon.txt tools/perf/builtin-daemon.c+158 -02 replies
16/24perf daemon: Use control to stop sessiontools/perf/builtin-daemon.c+46 -100 replies
17/24perf daemon: Add up time for daemon/session listtools/perf/builtin-daemon.c+20 -00 replies
18/24perf daemon: Add examples to man pagetools/perf/Documentation/perf-daemon.txt+98 -00 replies
19/24perf tests: Add daemon list command testtools/perf/tests/shell/daemon.sh+184 -00 replies
20/24perf tests: Add daemon reconfig testtools/perf/tests/shell/daemon.sh+119 -00 replies
21/24perf tests: Add daemon stop command testtools/perf/tests/shell/daemon.sh+54 -00 replies
22/24perf tests: Add daemon signal command testtools/perf/tests/shell/daemon.sh+40 -00 replies
23/24perf tests: Add daemon ping command testtools/perf/tests/shell/daemon.sh+40 -00 replies
24/24perf tests: Add daemon lock testtools/perf/tests/shell/daemon.sh+38 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCHv4 00/24] perf tools: Add daemon command

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