Skip to content

Commit

Permalink
perf tools: Add 'ping' control command
Browse files Browse the repository at this point in the history
Add a control 'ping' command to detect if perf is up and its control
interface is operational.

It will be used in following daemon patches to synchronize with record
session - when control interface is up and running, we know that perf
record is monitoring and ready to receive signals.

Example session:

  terminal 1:

    # mkfifo control ack
    # perf record --control=fifo:control,ack

  terminal 2:

    # echo ping > control
    # cat ack
    ack

Signed-off-by: Jiri Olsa <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Acked-by: Namhyung Kim <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexei Budankov <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Michael Petlan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
olsajiri authored and acmel committed Jan 20, 2021
1 parent f186cd6 commit 47fddcb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ Available commands:
'disable name' : disable event 'name'
'snapshot' : AUX area tracing snapshot).
'stop' : stop perf record
'ping' : ping

'evlist [-v|-g|-F] : display all events
-F Show just the sample frequency used for each event.
Expand Down
1 change: 1 addition & 0 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
case EVLIST_CTL_CMD_ENABLE:
case EVLIST_CTL_CMD_DISABLE:
case EVLIST_CTL_CMD_EVLIST:
case EVLIST_CTL_CMD_PING:
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ static void process_evlist(struct evlist *evlist, unsigned int interval)
case EVLIST_CTL_CMD_UNSUPPORTED:
case EVLIST_CTL_CMD_EVLIST:
case EVLIST_CTL_CMD_STOP:
case EVLIST_CTL_CMD_PING:
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,9 @@ static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd,
} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_STOP_TAG,
(sizeof(EVLIST_CTL_CMD_STOP_TAG)-1))) {
*cmd = EVLIST_CTL_CMD_STOP;
} else if (!strncmp(cmd_data, EVLIST_CTL_CMD_PING_TAG,
(sizeof(EVLIST_CTL_CMD_PING_TAG)-1))) {
*cmd = EVLIST_CTL_CMD_PING;
}
}

Expand Down Expand Up @@ -2081,6 +2084,7 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)
break;
case EVLIST_CTL_CMD_SNAPSHOT:
case EVLIST_CTL_CMD_STOP:
case EVLIST_CTL_CMD_PING:
break;
case EVLIST_CTL_CMD_ACK:
case EVLIST_CTL_CMD_UNSUPPORTED:
Expand Down
2 changes: 2 additions & 0 deletions tools/perf/util/evlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evse
#define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
#define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
#define EVLIST_CTL_CMD_STOP_TAG "stop"
#define EVLIST_CTL_CMD_PING_TAG "ping"

#define EVLIST_CTL_CMD_MAX_LEN 64

Expand All @@ -343,6 +344,7 @@ enum evlist_ctl_cmd {
EVLIST_CTL_CMD_SNAPSHOT,
EVLIST_CTL_CMD_EVLIST,
EVLIST_CTL_CMD_STOP,
EVLIST_CTL_CMD_PING,
};

int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
Expand Down

0 comments on commit 47fddcb

Please sign in to comment.