Skip to content

Commit

Permalink
perf daemon: Set control fifo for session
Browse files Browse the repository at this point in the history
Setup control fifos for session and add --control option to session
arguments.

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

Use can list control fifos with (control and ack files):

  # perf daemon -v
  [776459:daemon] base: /opt/perfdata
    output:  /opt/perfdata/output
    lock:    /opt/perfdata/lock
  [776460:cycles] perf record -m 20M -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
  [776461: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

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: https://lore.kernel.org/r/20210208200908.1019149-15-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Feb 11, 2021
1 parent 8c98be6 commit 6a6d180
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tools/perf/Documentation/perf-daemon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ flight recorder sessions in above example or session that is configured
to produce data periodically, like with --switch-output configuration
for time and size.

Each session is started with control setup (with perf record --control
options).

OPTIONS
-------
-v::
Expand Down
26 changes: 25 additions & 1 deletion tools/perf/builtin-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "util.h"

#define SESSION_OUTPUT "output"
#define SESSION_CONTROL "control"
#define SESSION_ACK "ack"

/*
* Session states:
Expand Down Expand Up @@ -74,6 +76,7 @@ struct daemon_session {
char *base;
char *name;
char *run;
char *control;
int pid;
struct list_head list;
enum daemon_session_state state;
Expand Down Expand Up @@ -365,7 +368,18 @@ static int daemon_session__run(struct daemon_session *session,
dup2(fd, 2);
close(fd);

scnprintf(buf, sizeof(buf), "%s record %s", daemon->perf, session->run);
if (mkfifo(SESSION_CONTROL, O_RDWR) && errno != EEXIST) {
perror("failed: create control fifo");
return -1;
}

if (mkfifo(SESSION_ACK, O_RDWR) && errno != EEXIST) {
perror("failed: create ack fifo");
return -1;
}

scnprintf(buf, sizeof(buf), "%s record --control=fifo:%s,%s %s",
daemon->perf, SESSION_CONTROL, SESSION_ACK, session->run);

argv = argv_split(buf, &argc);
if (!argv)
Expand Down Expand Up @@ -603,6 +617,12 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
/* session output */
csv_sep, session->base, SESSION_OUTPUT);

fprintf(out, "%c%s/%s%c%s/%s",
/* session control */
csv_sep, session->base, SESSION_CONTROL,
/* session ack */
csv_sep, session->base, SESSION_ACK);

fprintf(out, "\n");
} else {
fprintf(out, "[%d:%s] perf record %s\n",
Expand All @@ -613,6 +633,10 @@ static int cmd_session_list(struct daemon *daemon, union cmd *cmd, FILE *out)
session->base);
fprintf(out, " output: %s/%s\n",
session->base, SESSION_OUTPUT);
fprintf(out, " control: %s/%s\n",
session->base, SESSION_CONTROL);
fprintf(out, " ack: %s/%s\n",
session->base, SESSION_ACK);
}
}

Expand Down

0 comments on commit 6a6d180

Please sign in to comment.