perf inject: Set PERF_RECORD_MISC_BUILD_ID_SIZE

Message ID 20221119002750.1568027-1-namhyung@kernel.org
State New
Headers
Series perf inject: Set PERF_RECORD_MISC_BUILD_ID_SIZE |

Commit Message

Namhyung Kim Nov. 19, 2022, 12:27 a.m. UTC
  With perf inject -b, it synthesizes build-id event for DSOs.  But it
missed to set the size and resulted in having trailing zeros.

As perf record sets the size in write_build_id(), let's set the size
here as well.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/synthetic-events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Adrian Hunter Nov. 21, 2022, 8:45 a.m. UTC | #1
On 19/11/22 02:27, Namhyung Kim wrote:
> With perf inject -b, it synthesizes build-id event for DSOs.  But it
> missed to set the size and resulted in having trailing zeros.
> 
> As perf record sets the size in write_build_id(), let's set the size
> here as well.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/synthetic-events.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index cccd293b5312..0645795ff080 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -2218,8 +2218,9 @@ int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16
>  	len = pos->long_name_len + 1;
>  	len = PERF_ALIGN(len, NAME_ALIGN);
>  	memcpy(&ev.build_id.build_id, pos->bid.data, sizeof(pos->bid.data));
> +	ev.build_id.size = pos->bid.size;
>  	ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
> -	ev.build_id.header.misc = misc;
> +	ev.build_id.header.misc = misc | PERF_RECORD_MISC_BUILD_ID_SIZE;
>  	ev.build_id.pid = machine->pid;
>  	ev.build_id.header.size = sizeof(ev.build_id) + len;
>  	memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
  
Arnaldo Carvalho de Melo Nov. 23, 2022, 1:35 p.m. UTC | #2
Em Mon, Nov 21, 2022 at 10:45:14AM +0200, Adrian Hunter escreveu:
> On 19/11/22 02:27, Namhyung Kim wrote:
> > With perf inject -b, it synthesizes build-id event for DSOs.  But it
> > missed to set the size and resulted in having trailing zeros.
> > 
> > As perf record sets the size in write_build_id(), let's set the size
> > here as well.
> > 
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> 
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

Thanks, applied.

- Arnaldo

 
> > ---
> >  tools/perf/util/synthetic-events.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> > index cccd293b5312..0645795ff080 100644
> > --- a/tools/perf/util/synthetic-events.c
> > +++ b/tools/perf/util/synthetic-events.c
> > @@ -2218,8 +2218,9 @@ int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16
> >  	len = pos->long_name_len + 1;
> >  	len = PERF_ALIGN(len, NAME_ALIGN);
> >  	memcpy(&ev.build_id.build_id, pos->bid.data, sizeof(pos->bid.data));
> > +	ev.build_id.size = pos->bid.size;
> >  	ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
> > -	ev.build_id.header.misc = misc;
> > +	ev.build_id.header.misc = misc | PERF_RECORD_MISC_BUILD_ID_SIZE;
> >  	ev.build_id.pid = machine->pid;
> >  	ev.build_id.header.size = sizeof(ev.build_id) + len;
> >  	memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
  

Patch

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index cccd293b5312..0645795ff080 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -2218,8 +2218,9 @@  int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16
 	len = pos->long_name_len + 1;
 	len = PERF_ALIGN(len, NAME_ALIGN);
 	memcpy(&ev.build_id.build_id, pos->bid.data, sizeof(pos->bid.data));
+	ev.build_id.size = pos->bid.size;
 	ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
-	ev.build_id.header.misc = misc;
+	ev.build_id.header.misc = misc | PERF_RECORD_MISC_BUILD_ID_SIZE;
 	ev.build_id.pid = machine->pid;
 	ev.build_id.header.size = sizeof(ev.build_id) + len;
 	memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);