Linux-perf-users Archive mirror
 help / color / mirror / Atom feed
From: Yang Jihong <yangjihong@bytedance.com>
To: Ian Rogers <irogers@google.com>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	adrian.hunter@intel.com, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH] perf build: Add LIBTRACEEVENT_DIR build option
Date: Mon, 6 May 2024 16:30:20 +0800	[thread overview]
Message-ID: <5bb8af54-8b09-4b36-b195-68a0626f56fb@bytedance.com> (raw)
In-Reply-To: <CAP-5=fXJAu8OO_Gaw45Hx3uq6N8VQBNFhqcUy3Zm2vKT-TDSOQ@mail.gmail.com>

Hello,

On 5/1/24 01:46, Ian Rogers wrote:
> On Sat, Mar 23, 2024 at 12:07 PM Ian Rogers <irogers@google.com> wrote:
>>
>> On Wed, Mar 13, 2024 at 11:30 PM Yang Jihong <yangjihong@bytedance.com> wrote:
>>>
>>> Currently, when libtraceevent is not linked,
>>> perf does not support tracepoint:
>>>
>>>    # ./perf record -e sched:sched_switch -a sleep 10
>>>    event syntax error: 'sched:sched_switch'
>>>                         \___ unsupported tracepoint
>>>
>>>    libtraceevent is necessary for tracepoint support
>>>    Run 'perf list' for a list of valid events
>>>
>>>     Usage: perf record [<options>] [<command>]
>>>        or: perf record [<options>] -- <command> [<options>]
>>>
>>>        -e, --event <event>   event selector. use 'perf list' to list available events
>>>
>>> For cross-compilation scenario, library may not be installed in the default
>>> system path. Based on the above requirements, add LIBTRACEEVENT_DIR build
>>> option to support specifying path of libtraceevent.
>>>
>>> Example:
>>>
>>>    1. Cross compile libtraceevent
>>>    # cd /opt/libtraceevent
>>>    # CROSS_COMPILE=aarch64-linux-gnu- make
>>>
>>>    2. Cross compile perf
>>>    # cd tool/perf
>>>    # make VF=1 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- NO_LIBELF=1 LDFLAGS=--static LIBTRACEEVENT_DIR=/opt/libtraceevent
>>>    <SNIP>
>>>    Auto-detecting system features:
>>>    <SNIP>
>>>    ...                       LIBTRACEEVENT_DIR: /opt/libtraceevent
>>>
>>> Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
>>
>> This all looks good to me, thanks!
>>
>> Reviewed-by: Ian Rogers <irogers@google.com>
>>
>>> ---
>>>   tools/perf/Makefile.config | 20 ++++++++++++++++----
>>>   1 file changed, 16 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
>>> index 1fe8df97fe88..7783479de691 100644
>>> --- a/tools/perf/Makefile.config
>>> +++ b/tools/perf/Makefile.config
>>> @@ -182,6 +182,16 @@ endif
>>>   FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
>>>   FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
>>>
>>> +# for linking with debug library, run like:
>>> +# make DEBUG=1 LIBTRACEEVENT_DIR=/opt/libtraceevent/
>>> +TRACEEVENTLIBS := -ltraceevent
>>> +ifdef LIBTRACEEVENT_DIR
>>> +  LIBTRACEEVENT_CFLAGS  := -I$(LIBTRACEEVENT_DIR)/include
>>> +  LIBTRACEEVENT_LDFLAGS := -L$(LIBTRACEEVENT_DIR)/lib
>>> +endif
> 
> I'm finding to test a libtraceevent asan build on a system that has
> libtraceevent installed, I need to carry this change:
> ```
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 7f1e016a9253..b356520d8291 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -187,7 +187,7 @@ FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
> TRACEEVENTLIBS := -ltraceevent
> ifdef LIBTRACEEVENT_DIR
>    LIBTRACEEVENT_CFLAGS  := -I$(LIBTRACEEVENT_DIR)/include
> -  LIBTRACEEVENT_LDFLAGS := -L$(LIBTRACEEVENT_DIR)/lib
> +  LIBTRACEEVENT_LDFLAGS := -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib64
> endif
> FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
> FEATURE_CHECK_LDFLAGS-libtraceevent := $(LIBTRACEEVENT_LDFLAGS)
> $(TRACEEVENTLIBS)
> ```
> 
> I'm not sure how to make this something that'll work well with cross
> compilation, etc.

Because of the holiday, the reply is a bit late.

It seems that perf built by asan/msan will not search for shared 
libraries in the -L directory.
We generally use cross-compile perf to analyze performance problems. In 
most cases, it is static compilation (rpath does not work), and it will 
not enable sanitizers.
so can we simply check if EXTRA_CFLAGS contains 
-fsanitize=address/memory, and add libtraceevent dir to rpath?

I submitted a patch, please see if the solution is feasible:
https://lore.kernel.org/all/20240506081648.3890067-1-yangjihong@bytedance.com/


Or we can add libtraceevent's ld.so.conf to the environment. This 
requires manual configuration of the build environment, which is 
inconvenient.

# echo "/opt/libtraceevent/lib" > /etc/ld.so.conf.d/libtracevent.conf
# ldconfig

Thanks,
Yang

      reply	other threads:[~2024-05-06  8:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  6:30 [PATCH] perf build: Add LIBTRACEEVENT_DIR build option Yang Jihong
2024-03-23 19:07 ` Ian Rogers
2024-04-30 17:46   ` Ian Rogers
2024-05-06  8:30     ` Yang Jihong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5bb8af54-8b09-4b36-b195-68a0626f56fb@bytedance.com \
    --to=yangjihong@bytedance.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).