Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-18 Thread Jiri Olsa
On Fri, Dec 18, 2020 at 10:25:06PM +0900, Namhyung Kim wrote:

SNIP

> >
> > so the current way is, that following creates daemon:
> >
> >   # perf daemon --config 
> >
> > and any other 'non --config' option' is used to 'query/control' daemon:
> >
> >   # perf daemon
> >   # perf daemon --signal
> >   # perf daemon --stop
> >   ...
> 
> My opinion is that it'd be better having sub-commands for essential
> operations like start, stop.  Also daemons tend to have 'status' or
> 'reload' operations too.
> 
>   # perf daemon start --config ...
>   # perf daemon stop

ok, seems better

> 
> As a system daemon, I agree it should follow the standard location
> for the default base directory and config file.

currently we have this order:

  1. custom perfconfig if specified
  2. system perf config /etc/perfconfig if exists
  3. $HOME/.perfconfig if exists

I think we should keep that, when there's a perf systemd service config
file for this, it can use --config 'whatever'

jirka



Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-18 Thread Namhyung Kim
Hi Jiri,

On Wed, Dec 16, 2020 at 4:44 AM Jiri Olsa  wrote:
>
> On Tue, Dec 15, 2020 at 06:40:26PM +0300, Alexei Budankov wrote:
> > Hi,
> >
> > On 12.12.2020 13:43, Jiri Olsa wrote:
> > > Adding daemon command that allows to run record sessions
> > > on background. Each session represents one perf record
> > > process and is configured in config file.
> > >
> > > Example:
> > >
> > >   # cat config.daemon
> > >   [daemon]
> > >   base=/opt/perfdata
> >
> > It could probably make sense to consider using locations at /var/
> > directory, similar to other already existing daemon processes in
> > system so admin and user experience would be easily reusabe for
> > performance monitoring daemon (service).
>
> hm, you can specify any /var path in there if you like,
> do you suggest to hardcode it?
>
> >
> > >
> > >   [session-1]
> > >   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> > > --switch-output -a
> > >
> > >   [session-2]
> > >   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> > > --switch-output -a
> > >
> > > Default perf config has the same daemon base:
> > >
> > >   # cat ~/.perfconfig
> > >   [daemon]
> > >   base=/opt/perfdata
> > >
> > > Starting the daemon:
> > >
> > >   # perf daemon --config config.daemon
> >
> > It could make sense to name daemon config file similar to .perfconfig
> > e.g. like .perfconfig.daemon. perf daemon command would then assume, by
> > default, usage of .perfconfig.daemon config or the one specified on the
> > command line via --config option. It also would be helpfull have loaded
> > config file path printed into console:
> > # perf daemon
> > Daemon process  started with config /path/to/.perfconfig.daemon
>
> so the current way is, that following creates daemon:
>
>   # perf daemon --config 
>
> and any other 'non --config' option' is used to 'query/control' daemon:
>
>   # perf daemon
>   # perf daemon --signal
>   # perf daemon --stop
>   ...

My opinion is that it'd be better having sub-commands for essential
operations like start, stop.  Also daemons tend to have 'status' or
'reload' operations too.

  # perf daemon start --config ...
  # perf daemon stop

As a system daemon, I agree it should follow the standard location
for the default base directory and config file.

Thanks,
Namhyung


Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-16 Thread Jiri Olsa
On Wed, Dec 16, 2020 at 10:54:43AM +0300, Alexei Budankov wrote:
> 
> On 15.12.2020 22:43, Jiri Olsa wrote:
> > On Tue, Dec 15, 2020 at 06:40:26PM +0300, Alexei Budankov wrote:
> >> Hi,
> >>
> >> On 12.12.2020 13:43, Jiri Olsa wrote:
> >>> Adding daemon command that allows to run record sessions
> >>> on background. Each session represents one perf record
> >>> process and is configured in config file.
> >>>
> >>> Example:
> >>>
> >>>   # cat config.daemon
> >>>   [daemon]
> >>>   base=/opt/perfdata
> >>
> >> It could probably make sense to consider using locations at /var/
> >> directory, similar to other already existing daemon processes in
> >> system so admin and user experience would be easily reusabe for
> >> performance monitoring daemon (service).
> > 
> > hm, you can specify any /var path in there if you like,
> > do you suggest to hardcode it?
> 
> This thing: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
> Since Perf is a part of OS it would better use some standardized locations.

sure, user is free to configure that

SNIP

> >>> + start = current = time(NULL);
> >>> +
> >>> + do {
> >>> + usleep(500);
> >>
> >> This polling design is actually sub-optimal because it induces redundant
> >> noise in a system. Ideally it should be implemented in async fashion so
> >> kernel would atomically notify daemon process on event happened in some
> >> of record processes e.g. using of poll-like() system call.
> > 
> > ok, any suggestion?
> 
> Possibly, checking SIGCHLDs via signalfd [1] OR using pidfd [2] on kernel 
> v5.3+
> 
> [1] https://man7.org/linux/man-pages/man2/signalfd.2.html
> [2] https://man7.org/linux/man-pages/man2/pidfd_open.2.html

will check, thanks

jirka



Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-15 Thread Alexei Budankov


On 15.12.2020 22:43, Jiri Olsa wrote:
> On Tue, Dec 15, 2020 at 06:40:26PM +0300, Alexei Budankov wrote:
>> Hi,
>>
>> On 12.12.2020 13:43, Jiri Olsa wrote:
>>> Adding daemon command that allows to run record sessions
>>> on background. Each session represents one perf record
>>> process and is configured in config file.
>>>
>>> Example:
>>>
>>>   # cat config.daemon
>>>   [daemon]
>>>   base=/opt/perfdata
>>
>> It could probably make sense to consider using locations at /var/
>> directory, similar to other already existing daemon processes in
>> system so admin and user experience would be easily reusabe for
>> performance monitoring daemon (service).
> 
> hm, you can specify any /var path in there if you like,
> do you suggest to hardcode it?

This thing: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
Since Perf is a part of OS it would better use some standardized locations.

> 
>>
>>>
>>>   [session-1]
>>>   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
>>> --switch-output -a
>>>
>>>   [session-2]
>>>   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
>>> --switch-output -a
>>>
>>> Default perf config has the same daemon base:
>>>
>>>   # cat ~/.perfconfig
>>>   [daemon]
>>>   base=/opt/perfdata
>>>
>>> Starting the daemon:
>>>
>>>   # perf daemon --config config.daemon
>>
>> It could make sense to name daemon config file similar to .perfconfig
>> e.g. like .perfconfig.daemon. perf daemon command would then assume, by
>> default, usage of .perfconfig.daemon config or the one specified on the
>> command line via --config option. It also would be helpfull have loaded
>> config file path printed into console:
>> # perf daemon
>> Daemon process  started with config /path/to/.perfconfig.daemon
> 
> so the current way is, that following creates daemon:
> 
>   # perf daemon --config 
> 
> and any other 'non --config' option' is used to 'query/control' daemon:
> 
>   # perf daemon
>   # perf daemon --signal
>   # perf daemon --stop
>   ...
> 
> 
> I'd like to keep short way checking on daemon, without too many
> options, like:
> 
>   # perf daemon
>   [690174:daemon] base: /opt/perfdata
>   [690175:top] perf record -e cycles --switch-output=1m --switch-max-files=6 
> -a
> 
> 
> I think maybe we don't need any other .perfconfig, we could have
> all in standard .perfconfig, like:
> 
>   # cat .perfconfig:
>   [daemon]
>   base=/opt/perfdata
> 
>   [session-1]
>   run = -m 1M -e cycles --overwrite --switch-output -a
>   [session-2]
>   run = -m 1M -e sched:* --overwrite --switch-output -a
> 
> 
> and to run daemon on top of it:
> 
>   # perf daemon --start
> 
> 
> to run daemon with alternate config:
> 
>   # perf daemon --start=
> 
> or:
> 
>   # perf daemon --start --config=
> 
> 
> and checking on daemon with default .perfconfig setup:
> 
>   # perf daemon
> 
> 
> checking on daemon with different base or config:
> 
>   # perf daemon --base=
>   # perf daemon --config=
>   # perf daemon --base= --stop
>   # perf daemon --base= --signal
>   # perf daemon --config= --stop
>   # perf daemon --config= --signal
> 
> how about that?

Extending .perfconfig would look simpler for users, IHMO.
It looks like --base option actually implements --sandbox
or similar semantics.

> 
> SNIP
> 
>>> +static struct session*
>>> +daemon__find_session(struct daemon *daemon, char *name)
>>> +{
>>> +   struct session *session;
>>> +
>>> +   list_for_each_entry(session, &daemon->sessions, list) {
>>> +   if (!strcmp(session->name, name))
>>> +   return session;
>>> +   }
>>> +
>>> +   return NULL;
>>> +}
>>> +
>>> +static int session_name(const char *var, char *session, int len)
>>
>> should possibly name it get_session_name.
> 
> ok
> 
>>
>>> +{
>>> +   const char *p = var + sizeof("session-") - 1;
>>
>> should possibly check that p still points inside [var, var+len).
> 
> ok
> 
> SNIP
> 
>>> +static int session__wait(struct session *session, struct daemon *daemon,
>>> +int secs)
>>> +{
>>> +   time_t current, start = 0;
>>> +   int cnt;
>>> +
>>> +   start = current = time(NULL);
>>> +
>>> +   do {
>>> +   usleep(500);
>>
>> This polling design is actually sub-optimal because it induces redundant
>> noise in a system. Ideally it should be implemented in async fashion so
>> kernel would atomically notify daemon process on event happened in some
>> of record processes e.g. using of poll-like() system call.
> 
> ok, any suggestion?

Possibly, checking SIGCHLDs via signalfd [1] OR using pidfd [2] on kernel v5.3+

[1] https://man7.org/linux/man-pages/man2/signalfd.2.html
[2] https://man7.org/linux/man-pages/man2/pidfd_open.2.html

Thanks,
Alexei

> 
>>
>>> +   cnt = session__check(session, daemon);
>>> +   if (cnt)
>>> +   break;
>>> +
>>> +   current = time(NULL);
>>> +   } while ((start + secs > current));
>>> +
>>> +   return cnt;
>>> +}
>>> +
>>> +static int session__signal(struct session *sess

Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-15 Thread Jiri Olsa
On Tue, Dec 15, 2020 at 06:40:26PM +0300, Alexei Budankov wrote:
> Hi,
> 
> On 12.12.2020 13:43, Jiri Olsa wrote:
> > Adding daemon command that allows to run record sessions
> > on background. Each session represents one perf record
> > process and is configured in config file.
> > 
> > Example:
> > 
> >   # cat config.daemon
> >   [daemon]
> >   base=/opt/perfdata
> 
> It could probably make sense to consider using locations at /var/
> directory, similar to other already existing daemon processes in
> system so admin and user experience would be easily reusabe for
> performance monitoring daemon (service).

hm, you can specify any /var path in there if you like,
do you suggest to hardcode it?

> 
> > 
> >   [session-1]
> >   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> > --switch-output -a
> > 
> >   [session-2]
> >   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> > --switch-output -a
> > 
> > Default perf config has the same daemon base:
> > 
> >   # cat ~/.perfconfig
> >   [daemon]
> >   base=/opt/perfdata
> > 
> > Starting the daemon:
> > 
> >   # perf daemon --config config.daemon
> 
> It could make sense to name daemon config file similar to .perfconfig
> e.g. like .perfconfig.daemon. perf daemon command would then assume, by
> default, usage of .perfconfig.daemon config or the one specified on the
> command line via --config option. It also would be helpfull have loaded
> config file path printed into console:
> # perf daemon
> Daemon process  started with config /path/to/.perfconfig.daemon

so the current way is, that following creates daemon:

  # perf daemon --config 

and any other 'non --config' option' is used to 'query/control' daemon:

  # perf daemon
  # perf daemon --signal
  # perf daemon --stop
  ...


I'd like to keep short way checking on daemon, without too many
options, like:

  # perf daemon
  [690174:daemon] base: /opt/perfdata
  [690175:top] perf record -e cycles --switch-output=1m --switch-max-files=6 -a


I think maybe we don't need any other .perfconfig, we could have
all in standard .perfconfig, like:

  # cat .perfconfig:
  [daemon]
  base=/opt/perfdata

  [session-1]
  run = -m 1M -e cycles --overwrite --switch-output -a
  [session-2]
  run = -m 1M -e sched:* --overwrite --switch-output -a


and to run daemon on top of it:

  # perf daemon --start


to run daemon with alternate config:

  # perf daemon --start=

or:

  # perf daemon --start --config=


and checking on daemon with default .perfconfig setup:

  # perf daemon


checking on daemon with different base or config:

  # perf daemon --base=
  # perf daemon --config=
  # perf daemon --base= --stop
  # perf daemon --base= --signal
  # perf daemon --config= --stop
  # perf daemon --config= --signal

how about that?

SNIP

> > +static struct session*
> > +daemon__find_session(struct daemon *daemon, char *name)
> > +{
> > +   struct session *session;
> > +
> > +   list_for_each_entry(session, &daemon->sessions, list) {
> > +   if (!strcmp(session->name, name))
> > +   return session;
> > +   }
> > +
> > +   return NULL;
> > +}
> > +
> > +static int session_name(const char *var, char *session, int len)
> 
> should possibly name it get_session_name.

ok

> 
> > +{
> > +   const char *p = var + sizeof("session-") - 1;
> 
> should possibly check that p still points inside [var, var+len).

ok

SNIP

> > +static int session__wait(struct session *session, struct daemon *daemon,
> > +int secs)
> > +{
> > +   time_t current, start = 0;
> > +   int cnt;
> > +
> > +   start = current = time(NULL);
> > +
> > +   do {
> > +   usleep(500);
> 
> This polling design is actually sub-optimal because it induces redundant
> noise in a system. Ideally it should be implemented in async fashion so
> kernel would atomically notify daemon process on event happened in some
> of record processes e.g. using of poll-like() system call.

ok, any suggestion?

> 
> > +   cnt = session__check(session, daemon);
> > +   if (cnt)
> > +   break;
> > +
> > +   current = time(NULL);
> > +   } while ((start + secs > current));
> > +
> > +   return cnt;
> > +}
> > +
> > +static int session__signal(struct session *session, int sig)
> > +{
> > +   if (session->pid < 0)
> > +   return -1;
> > +   return kill(session->pid, sig);
> 
> "Better" alternative could possibly be sending of some 'stop' command
> via --control=fd.

true, nice idea.. seems more clean and we already have control fd open

will add it to next version

thanks,
jirka



Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-15 Thread Jiri Olsa
On Tue, Dec 15, 2020 at 12:44:08PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Sat, Dec 12, 2020 at 11:43:54AM +0100, Jiri Olsa escreveu:
> > Adding daemon command that allows to run record sessions
> > on background. Each session represents one perf record
> > process and is configured in config file.
> > 
> > Example:
> > 
> >   # cat config.daemon
> >   [daemon]
> >   base=/opt/perfdata
> > 
> >   [session-1]
> >   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> > --switch-output -a
> > 
> >   [session-2]
> >   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> > --switch-output -a
> > 
> > Default perf config has the same daemon base:
> > 
> >   # cat ~/.perfconfig
> >   [daemon]
> >   base=/opt/perfdata
> > 
> > Starting the daemon:
> > 
> >   # perf daemon --config config.daemon
> > 
> > Check sessions:
> 
> "Check"? You mean that using 'perf daemon' without any args will just
> attach to whatever daemon is running and list the current sessions?
> 
> So we can only have one daemon running in a machine?
> 
> That seems constraining, perhaps we can give each daemon a name?

as I explained in the other email, the difference is the base path
specified for both daemon and other commands

I made other changes showing line for daemon process itself
with base path:

  $ sudo /opt/perf/bin/perf daemon
  [690174:daemon] base: /opt/perfdata
  [690175:top] perf record -e cycles --switch-output=1m --switch-max-files=6 -a

  $ sudo /opt/perf/bin/perf daemon -v
  [690174:daemon] base: /opt/perfdata
output:  /opt/perfdata/output
lock:/opt/perfdata/lock
up:  268 minutes
  [690175:top] perf record -e cycles --switch-output=1m --switch-max-files=6 -a
base:/opt/perfdata/top
output:  /opt/perfdata/top/output
control: /opt/perfdata/top/control
ack: /opt/perfdata/top/ack
up:  268 minutes

jirka



Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-15 Thread Arnaldo Carvalho de Melo
Em Sat, Dec 12, 2020 at 11:43:54AM +0100, Jiri Olsa escreveu:
> Adding daemon command that allows to run record sessions
> on background. Each session represents one perf record
> process and is configured in config file.
> 
> Example:
> 
>   # cat config.daemon
>   [daemon]
>   base=/opt/perfdata
> 
>   [session-1]
>   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> --switch-output -a
> 
>   [session-2]
>   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> --switch-output -a
> 
> Default perf config has the same daemon base:
> 
>   # cat ~/.perfconfig
>   [daemon]
>   base=/opt/perfdata
> 
> Starting the daemon:
> 
>   # perf daemon --config config.daemon
> 
> Check sessions:

"Check"? You mean that using 'perf daemon' without any args will just
attach to whatever daemon is running and list the current sessions?

So we can only have one daemon running in a machine?

That seems constraining, perhaps we can give each daemon a name?
 
>   # perf daemon
>   [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch-output -a
>   [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
> --overwrite --switch-output -a
> 
> Check sessions with more info:
> 
>   # perf daemon -v
>   [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch-output -a
> output:  /opt/perfdata/1/output
>   [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
> --overwrite --switch-output -a
> output:  /opt/perfdata/2/output
> 
> The 'output' file is perf record output for specific session.
> 
> Signed-off-by: Jiri Olsa 
> ---
>  tools/perf/Build |   3 +
>  tools/perf/Documentation/perf-daemon.txt |  97 +++
>  tools/perf/builtin-daemon.c  | 794 +++
>  tools/perf/builtin.h |   1 +
>  tools/perf/command-list.txt  |   1 +
>  tools/perf/perf.c|   1 +
>  6 files changed, 897 insertions(+)
>  create mode 100644 tools/perf/Documentation/perf-daemon.txt
>  create mode 100644 tools/perf/builtin-daemon.c
> 
> diff --git a/tools/perf/Build b/tools/perf/Build
> index 5f392dbb88fc..54aa38996fff 100644
> --- a/tools/perf/Build
> +++ b/tools/perf/Build
> @@ -24,6 +24,7 @@ perf-y += builtin-mem.o
>  perf-y += builtin-data.o
>  perf-y += builtin-version.o
>  perf-y += builtin-c2c.o
> +perf-y += builtin-daemon.o
>  
>  perf-$(CONFIG_TRACE) += builtin-trace.o
>  perf-$(CONFIG_LIBELF) += builtin-probe.o
> @@ -53,3 +54,5 @@ perf-y += scripts/
>  perf-$(CONFIG_TRACE) += trace/beauty/
>  
>  gtk-y += ui/gtk/
> +
> +CFLAGS_builtin-daemon.o += -DPERF="BUILD_STR($(bindir_SQ)/perf)"
> diff --git a/tools/perf/Documentation/perf-daemon.txt 
> b/tools/perf/Documentation/perf-daemon.txt
> new file mode 100644
> index ..dee39be110ba
> --- /dev/null
> +++ b/tools/perf/Documentation/perf-daemon.txt
> @@ -0,0 +1,97 @@
> +perf-daemon(1)
> +==
> +
> +NAME
> +
> +perf-daemon - Run record sessions on background
> +
> +SYNOPSIS
> +
> +[verse]
> +'perf daemon'
> +'perf daemon' []
> +
> +DESCRIPTION
> +---
> +This command allows to run simple daemon process that starts and
> +monitors configured record sessions.
> +
> +Each session represents one perf record process.
> +
> +These sessions are configured through config file, see CONFIG FILE
> +section with EXAMPLES.
> +
> +OPTIONS
> +---
> +--config=::
> + Config file path.
> +
> +-f::
> +--foreground::
> + Do not put the process in background.
> +
> +-v::
> +--verbose::
> + Be more verbose.
> +
> +CONFIG FILE
> +---
> +The daemon is configured within standard perf config file by
> +following new variables:
> +
> +daemon.base:
> + Base path for daemon data. All sessions data are
> + stored under this path.
> +
> +session-.run:
> + Defines new record session. The value is record's command
> + line without the 'record' keyword.
> +
> +EXAMPLES
> +
> +Example with 2 record sessions:
> +
> +  # cat config.daemon
> +  [daemon]
> +  base=/opt/perfdata
> +
> +  [session-1]
> +  run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> --switch-output -a
> +
> +  [session-2]
> +  run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> --switch-output -a
> +
> +
> +Default perf config has the same daemon base:
> +
> +  # cat ~/.perfconfig
> +  [daemon]
> +  base=/opt/perfdata
> +
> +
> +Starting the daemon:
> +
> +  # perf daemon --config config.daemon
> +
> +
> +Check sessions:
> +
> +  # perf daemon
> +  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch-output -a
> +  [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
> --overwrite --switch-output -a
> +
> +
> +Check sessions with more info:
> +
> +  # perf daemon -v
> +  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch

Re: [PATCH 4/8] perf daemon: Add daemon command

2020-12-15 Thread Alexei Budankov
Hi,

On 12.12.2020 13:43, Jiri Olsa wrote:
> Adding daemon command that allows to run record sessions
> on background. Each session represents one perf record
> process and is configured in config file.
> 
> Example:
> 
>   # cat config.daemon
>   [daemon]
>   base=/opt/perfdata

It could probably make sense to consider using locations at /var/
directory, similar to other already existing daemon processes in
system so admin and user experience would be easily reusabe for
performance monitoring daemon (service).

> 
>   [session-1]
>   run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> --switch-output -a
> 
>   [session-2]
>   run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> --switch-output -a
> 
> Default perf config has the same daemon base:
> 
>   # cat ~/.perfconfig
>   [daemon]
>   base=/opt/perfdata
> 
> Starting the daemon:
> 
>   # perf daemon --config config.daemon

It could make sense to name daemon config file similar to .perfconfig
e.g. like .perfconfig.daemon. perf daemon command would then assume, by
default, usage of .perfconfig.daemon config or the one specified on the
command line via --config option. It also would be helpfull have loaded
config file path printed into console:
# perf daemon
Daemon process  started with config /path/to/.perfconfig.daemon

> 
> Check sessions:
> 
>   # perf daemon
>   [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch-output -a
>   [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
> --overwrite --switch-output -a
> 
> Check sessions with more info:
> 
>   # perf daemon -v
>   [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
> --overwrite --switch-output -a
> output:  /opt/perfdata/1/output
>   [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
> --overwrite --switch-output -a
> output:  /opt/perfdata/2/output
> 
> The 'output' file is perf record output for specific session.
> 
> Signed-off-by: Jiri Olsa 
> ---
>  tools/perf/Build |   3 +
>  tools/perf/Documentation/perf-daemon.txt |  97 +++
>  tools/perf/builtin-daemon.c  | 794 +++
>  tools/perf/builtin.h |   1 +
>  tools/perf/command-list.txt  |   1 +
>  tools/perf/perf.c|   1 +
>  6 files changed, 897 insertions(+)
>  create mode 100644 tools/perf/Documentation/perf-daemon.txt
>  create mode 100644 tools/perf/builtin-daemon.c
> 
> diff --git a/tools/perf/Build b/tools/perf/Build
> index 5f392dbb88fc..54aa38996fff 100644
> --- a/tools/perf/Build
> +++ b/tools/perf/Build
> @@ -24,6 +24,7 @@ perf-y += builtin-mem.o
>  perf-y += builtin-data.o
>  perf-y += builtin-version.o
>  perf-y += builtin-c2c.o
> +perf-y += builtin-daemon.o
>  
>  perf-$(CONFIG_TRACE) += builtin-trace.o
>  perf-$(CONFIG_LIBELF) += builtin-probe.o
> @@ -53,3 +54,5 @@ perf-y += scripts/
>  perf-$(CONFIG_TRACE) += trace/beauty/
>  
>  gtk-y += ui/gtk/
> +
> +CFLAGS_builtin-daemon.o += -DPERF="BUILD_STR($(bindir_SQ)/perf)"
> diff --git a/tools/perf/Documentation/perf-daemon.txt 
> b/tools/perf/Documentation/perf-daemon.txt
> new file mode 100644
> index ..dee39be110ba
> --- /dev/null
> +++ b/tools/perf/Documentation/perf-daemon.txt
> @@ -0,0 +1,97 @@
> +perf-daemon(1)
> +==
> +
> +NAME
> +
> +perf-daemon - Run record sessions on background
> +
> +SYNOPSIS
> +
> +[verse]
> +'perf daemon'
> +'perf daemon' []
> +
> +DESCRIPTION
> +---
> +This command allows to run simple daemon process that starts and
> +monitors configured record sessions.
> +
> +Each session represents one perf record process.
> +
> +These sessions are configured through config file, see CONFIG FILE
> +section with EXAMPLES.
> +
> +OPTIONS
> +---
> +--config=::
> + Config file path.
> +
> +-f::
> +--foreground::
> + Do not put the process in background.
> +
> +-v::
> +--verbose::
> + Be more verbose.
> +
> +CONFIG FILE
> +---
> +The daemon is configured within standard perf config file by
> +following new variables:
> +
> +daemon.base:
> + Base path for daemon data. All sessions data are
> + stored under this path.
> +
> +session-.run:
> + Defines new record session. The value is record's command
> + line without the 'record' keyword.
> +
> +EXAMPLES
> +
> +Example with 2 record sessions:
> +
> +  # cat config.daemon
> +  [daemon]
> +  base=/opt/perfdata
> +
> +  [session-1]
> +  run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
> --switch-output -a
> +
> +  [session-2]
> +  run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
> --switch-output -a
> +
> +
> +Default perf config has the same daemon base:
> +
> +  # cat ~/.perfconfig
> +  [daemon]
> +  base=/opt/perfdata
> +
> +
> +Starting the daemon:
> +
> +  # perf daemon --config config.daemon
> +
> +
> +Check sessions:
> +
> +  # perf daemon
> +  [1:92187

[PATCH 4/8] perf daemon: Add daemon command

2020-12-12 Thread Jiri Olsa
Adding daemon command that allows to run record sessions
on background. Each session represents one perf record
process and is configured in config file.

Example:

  # cat config.daemon
  [daemon]
  base=/opt/perfdata

  [session-1]
  run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
--switch-output -a

  [session-2]
  run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
--switch-output -a

Default perf config has the same daemon base:

  # cat ~/.perfconfig
  [daemon]
  base=/opt/perfdata

Starting the daemon:

  # perf daemon --config config.daemon

Check sessions:

  # perf daemon
  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
--overwrite --switch-output -a
  [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
--overwrite --switch-output -a

Check sessions with more info:

  # perf daemon -v
  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
--overwrite --switch-output -a
output:  /opt/perfdata/1/output
  [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
--overwrite --switch-output -a
output:  /opt/perfdata/2/output

The 'output' file is perf record output for specific session.

Signed-off-by: Jiri Olsa 
---
 tools/perf/Build |   3 +
 tools/perf/Documentation/perf-daemon.txt |  97 +++
 tools/perf/builtin-daemon.c  | 794 +++
 tools/perf/builtin.h |   1 +
 tools/perf/command-list.txt  |   1 +
 tools/perf/perf.c|   1 +
 6 files changed, 897 insertions(+)
 create mode 100644 tools/perf/Documentation/perf-daemon.txt
 create mode 100644 tools/perf/builtin-daemon.c

diff --git a/tools/perf/Build b/tools/perf/Build
index 5f392dbb88fc..54aa38996fff 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -24,6 +24,7 @@ perf-y += builtin-mem.o
 perf-y += builtin-data.o
 perf-y += builtin-version.o
 perf-y += builtin-c2c.o
+perf-y += builtin-daemon.o
 
 perf-$(CONFIG_TRACE) += builtin-trace.o
 perf-$(CONFIG_LIBELF) += builtin-probe.o
@@ -53,3 +54,5 @@ perf-y += scripts/
 perf-$(CONFIG_TRACE) += trace/beauty/
 
 gtk-y += ui/gtk/
+
+CFLAGS_builtin-daemon.o += -DPERF="BUILD_STR($(bindir_SQ)/perf)"
diff --git a/tools/perf/Documentation/perf-daemon.txt 
b/tools/perf/Documentation/perf-daemon.txt
new file mode 100644
index ..dee39be110ba
--- /dev/null
+++ b/tools/perf/Documentation/perf-daemon.txt
@@ -0,0 +1,97 @@
+perf-daemon(1)
+==
+
+NAME
+
+perf-daemon - Run record sessions on background
+
+SYNOPSIS
+
+[verse]
+'perf daemon'
+'perf daemon' []
+
+DESCRIPTION
+---
+This command allows to run simple daemon process that starts and
+monitors configured record sessions.
+
+Each session represents one perf record process.
+
+These sessions are configured through config file, see CONFIG FILE
+section with EXAMPLES.
+
+OPTIONS
+---
+--config=::
+   Config file path.
+
+-f::
+--foreground::
+   Do not put the process in background.
+
+-v::
+--verbose::
+   Be more verbose.
+
+CONFIG FILE
+---
+The daemon is configured within standard perf config file by
+following new variables:
+
+daemon.base:
+   Base path for daemon data. All sessions data are
+   stored under this path.
+
+session-.run:
+   Defines new record session. The value is record's command
+   line without the 'record' keyword.
+
+EXAMPLES
+
+Example with 2 record sessions:
+
+  # cat config.daemon
+  [daemon]
+  base=/opt/perfdata
+
+  [session-1]
+  run = -m 10M -e cycles -o /opt/perfdata/1/perf.data --overwrite 
--switch-output -a
+
+  [session-2]
+  run = -m 20M -e sched:* -o /opt/perfdata/2/perf.data --overwrite 
--switch-output -a
+
+
+Default perf config has the same daemon base:
+
+  # cat ~/.perfconfig
+  [daemon]
+  base=/opt/perfdata
+
+
+Starting the daemon:
+
+  # perf daemon --config config.daemon
+
+
+Check sessions:
+
+  # perf daemon
+  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
--overwrite --switch-output -a
+  [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
--overwrite --switch-output -a
+
+
+Check sessions with more info:
+
+  # perf daemon -v
+  [1:92187] perf record -m 11M -e cycles -o /opt/perfdata/1/perf.data 
--overwrite --switch-output -a
+output:  /opt/perfdata/1/output
+  [2:92188] perf record -m 20M -e sched:* -o /opt/perfdata/2/perf.data 
--overwrite --switch-output -a
+output:  /opt/perfdata/2/output
+
+The 'output' file is perf record output for specific session.
+
+
+SEE ALSO
+
+linkperf:perf-record[1], linkperf:perf-config[1]
diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
new file mode 100644
index ..7f455837d58a
--- /dev/null
+++ b/tools/perf/builtin-daemon.c
@@ -0,0 +1,794 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#inc