Skip to contentSkip to conversation

perf: Support for Openembedded/Yocto -dbg packages

PATCH Superseded Ricardo Ribalda Delgado 5 participants 11 messages Sep 18, 2013 – Oct 2, 2013 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Support for Openembedded/Yocto -dbg packages

On OpenEmbedded the symbol files are located under a .debug folder on the same folder as the binary file.

This patch adds support for such files.

---
 tools/perf/util/dso.c    | 16 ++++++++++++++++
 tools/perf/util/dso.h    |  1 +
 tools/perf/util/symbol.c |  1 +
 3 files changed, 18 insertions(+)
tools/perf/util/dso.c +16 -0
index c4374f0..bab18b7 100644
@@ -14,6 +14,7 @@ char dso__symtab_origin(const struct dso *dso)
 		[DSO_BINARY_TYPE__BUILD_ID_CACHE]	= 'B',
 		[DSO_BINARY_TYPE__FEDORA_DEBUGINFO]	= 'f',
 		[DSO_BINARY_TYPE__UBUNTU_DEBUGINFO]	= 'u',
+		[DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
 		[DSO_BINARY_TYPE__BUILDID_DEBUGINFO]	= 'b',
 		[DSO_BINARY_TYPE__SYSTEM_PATH_DSO]	= 'd',
 		[DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]	= 'K',
@@ -64,6 +65,21 @@ int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
 			 symbol_conf.symfs, dso->long_name);
 		break;
 
+	case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:{
+		char *last_slash;
+
+		last_slash = dso->long_name + dso->long_name_len;
+		while (last_slash != dso->long_name && *last_slash != '/')
+			last_slash--;
+
+		snprintf(file, MIN(size, strlen(symbol_conf.symfs) +
+				(last_slash - dso->long_name) + 2), "%s%s",
+				symbol_conf.symfs, dso->long_name);
+		snprintf(file + strlen(file), size-strlen(file), ".debug%s",
+				last_slash);
+		}
+		break;
+
 	case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
 		if (!dso->has_build_id) {
 			ret = -1;
tools/perf/util/dso.h +1 -0
index d51aaf2..4f78e7b 100644
@@ -20,6 +20,7 @@ enum dso_binary_type {
 	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
 	DSO_BINARY_TYPE__GUEST_KMODULE,
 	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
+	DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
 	DSO_BINARY_TYPE__NOT_FOUND,
 };
 
tools/perf/util/symbol.c +1 -0
index d5528e1..f69d57b 100644
@@ -51,6 +51,7 @@ static enum dso_binary_type binary_type_symtab[] = {
 	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
 	DSO_BINARY_TYPE__GUEST_KMODULE,
 	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
+	DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
 	DSO_BINARY_TYPE__NOT_FOUND,
 };
 
Signature · 1 line
1.8.4.rc3
#1 lore raw
Quoted 4 lines · Ricardo Ribalda Delgado

On OpenEmbedded the symbol files are located under a .debug folder on the same folder as the binary file.

This patch adds support for such files.

It would be nice to cite before/after perf report output, to see how this improved things and to see the output format you picked.

Quoted 13 lines
---
 tools/perf/util/dso.c    | 16 ++++++++++++++++
 tools/perf/util/dso.h    |  1 +
 tools/perf/util/symbol.c |  1 +
 3 files changed, 18 insertions(+)
tools/perf/util/dso.c +0 -0
index c4374f0..bab18b7 100644

tools/perf/util/dso.c char dso__symtab_origin(const struct dso *dso) · line 20

Quoted 7 lines
tools/perf/util/dso.c +1 -0
@@ -14,6 +14,7 @@ char dso__symtab_origin(const struct dso *dso)
 		[DSO_BINARY_TYPE__BUILD_ID_CACHE]	= 'B',
 		[DSO_BINARY_TYPE__FEDORA_DEBUGINFO]	= 'f',
 		[DSO_BINARY_TYPE__UBUNTU_DEBUGINFO]	= 'u',
+		[DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
 		[DSO_BINARY_TYPE__BUILDID_DEBUGINFO]	= 'b',
 		[DSO_BINARY_TYPE__SYSTEM_PATH_DSO]	= 'd',
 		[DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]	= 'K',

Stylistic nit: if a new entry breaks vertical alignment then re-align the other entries as well so that it still looks nice after your change ...

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 68

Quoted 5 lines
tools/perf/util/dso.c +1 -0
@@ -64,6 +65,21 @@ int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
 			 symbol_conf.symfs, dso->long_name);
 		break;
 
+	case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:{

/: {

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 79

Quoted 11 lines
tools/perf/util/dso.c +11 -0
+		char *last_slash;
+
+		last_slash = dso->long_name + dso->long_name_len;
+		while (last_slash != dso->long_name && *last_slash != '/')
+			last_slash--;
+
+		snprintf(file, MIN(size, strlen(symbol_conf.symfs) +
+				(last_slash - dso->long_name) + 2), "%s%s",
+				symbol_conf.symfs, dso->long_name);
+		snprintf(file + strlen(file), size-strlen(file), ".debug%s",
+				last_slash);

So the way such multi-snprintf() sequences are implemented in the kernel is not this unreadable, fragile, repetitive concatenation of length calculations, but an adjustment of 'size':

		size -= snprintf(..., size, ...);

that way 'size' always tracks the remaining limit of the output string, each snprintf consumes from it.

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 81

Quoted 2 lines
tools/perf/util/dso.c +2 -0
+		}
+		break;

Small nit: we generally put the final break inside the block.

Besides the details it looks like a useful patch.

Thanks,

Ingo

#2 lore raw

Hello Ingo

Incredible how many code style rules I can break in 20 lines of code :). I have just uploaded v2

Thanks for your comments.

Quoted 74 lines · Ingo Molnar
Quoted 4 lines · Ricardo Ribalda Delgado

On OpenEmbedded the symbol files are located under a .debug folder on the same folder as the binary file.

This patch adds support for such files.

It would be nice to cite before/after perf report output, to see how this improved things and to see the output format you picked.

Quoted 13 lines
---
 tools/perf/util/dso.c    | 16 ++++++++++++++++
 tools/perf/util/dso.h    |  1 +
 tools/perf/util/symbol.c |  1 +
 3 files changed, 18 insertions(+)
tools/perf/util/dso.c +0 -0
index c4374f0..bab18b7 100644

tools/perf/util/dso.c char dso__symtab_origin(const struct dso *dso) · line 20

Quoted 7 lines
tools/perf/util/dso.c +1 -0
@@ -14,6 +14,7 @@ char dso__symtab_origin(const struct dso *dso)
              [DSO_BINARY_TYPE__BUILD_ID_CACHE]       = 'B',
              [DSO_BINARY_TYPE__FEDORA_DEBUGINFO]     = 'f',
              [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO]     = 'u',
+             [DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
              [DSO_BINARY_TYPE__BUILDID_DEBUGINFO]    = 'b',
              [DSO_BINARY_TYPE__SYSTEM_PATH_DSO]      = 'd',
              [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]  = 'K',

Stylistic nit: if a new entry breaks vertical alignment then re-align the other entries as well so that it still looks nice after your change ...

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 68

Quoted 5 lines
tools/perf/util/dso.c +1 -0
@@ -64,6 +65,21 @@ int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
                       symbol_conf.symfs, dso->long_name);
              break;
 
+     case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:{

/: {

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 79

Quoted 11 lines
tools/perf/util/dso.c +11 -0
+             char *last_slash;
+
+             last_slash = dso->long_name + dso->long_name_len;
+             while (last_slash != dso->long_name && *last_slash != '/')
+                     last_slash--;
+
+             snprintf(file, MIN(size, strlen(symbol_conf.symfs) +
+                             (last_slash - dso->long_name) + 2), "%s%s",
+                             symbol_conf.symfs, dso->long_name);
+             snprintf(file + strlen(file), size-strlen(file), ".debug%s",
+                             last_slash);

So the way such multi-snprintf() sequences are implemented in the kernel is not this unreadable, fragile, repetitive concatenation of length calculations, but an adjustment of 'size':

                size -= snprintf(..., size, ...);

that way 'size' always tracks the remaining limit of the output string, each snprintf consumes from it.

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 81

Quoted 2 lines
tools/perf/util/dso.c +2 -0
+             }
+             break;

Small nit: we generally put the final break inside the block.

Besides the details it looks like a useful patch.

Thanks,

Ingo

Signature · 1 line
Ricardo Ribalda
#3 lore raw

Hello again Ingo:

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Just tell me if you prefer this and I send v3.

Thanks!

Quoted 87 lines · Ricardo Ribalda Delgado

Hello Ingo

Incredible how many code style rules I can break in 20 lines of code :). I have just uploaded v2

Thanks for your comments.

Quoted 67 lines · Ingo Molnar
Quoted 4 lines · Ricardo Ribalda Delgado

On OpenEmbedded the symbol files are located under a .debug folder on the same folder as the binary file.

This patch adds support for such files.

It would be nice to cite before/after perf report output, to see how this improved things and to see the output format you picked.

Quoted 13 lines
---
 tools/perf/util/dso.c    | 16 ++++++++++++++++
 tools/perf/util/dso.h    |  1 +
 tools/perf/util/symbol.c |  1 +
 3 files changed, 18 insertions(+)
tools/perf/util/dso.c +0 -0
index c4374f0..bab18b7 100644

tools/perf/util/dso.c char dso__symtab_origin(const struct dso *dso) · line 20

Quoted 7 lines
tools/perf/util/dso.c +1 -0
@@ -14,6 +14,7 @@ char dso__symtab_origin(const struct dso *dso)
              [DSO_BINARY_TYPE__BUILD_ID_CACHE]       = 'B',
              [DSO_BINARY_TYPE__FEDORA_DEBUGINFO]     = 'f',
              [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO]     = 'u',
+             [DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO] = 'o',
              [DSO_BINARY_TYPE__BUILDID_DEBUGINFO]    = 'b',
              [DSO_BINARY_TYPE__SYSTEM_PATH_DSO]      = 'd',
              [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]  = 'K',

Stylistic nit: if a new entry breaks vertical alignment then re-align the other entries as well so that it still looks nice after your change ...

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 68

Quoted 5 lines
tools/perf/util/dso.c +1 -0
@@ -64,6 +65,21 @@ int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
                       symbol_conf.symfs, dso->long_name);
              break;
 
+     case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:{

/: {

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 79

Quoted 11 lines
tools/perf/util/dso.c +11 -0
+             char *last_slash;
+
+             last_slash = dso->long_name + dso->long_name_len;
+             while (last_slash != dso->long_name && *last_slash != '/')
+                     last_slash--;
+
+             snprintf(file, MIN(size, strlen(symbol_conf.symfs) +
+                             (last_slash - dso->long_name) + 2), "%s%s",
+                             symbol_conf.symfs, dso->long_name);
+             snprintf(file + strlen(file), size-strlen(file), ".debug%s",
+                             last_slash);

So the way such multi-snprintf() sequences are implemented in the kernel is not this unreadable, fragile, repetitive concatenation of length calculations, but an adjustment of 'size':

                size -= snprintf(..., size, ...);

that way 'size' always tracks the remaining limit of the output string, each snprintf consumes from it.

tools/perf/util/dso.c int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, · line 81

Quoted 2 lines
tools/perf/util/dso.c +2 -0
+             }
+             break;
Quoted 7 lines

Small nit: we generally put the final break inside the block.

Besides the details it looks like a useful patch.

Thanks,

Ingo

--
Ricardo Ribalda

Signature · 1 line
Ricardo Ribalda
maintainer
#4 lore raw
Quoted 4 lines · Ricardo Ribalda Delgado

Hello again Ingo:

Perhaps this is even more clear than v2:

Quoted 9 lines

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

#5 lore raw

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 12 lines · Ricardo Ribalda Delgado
Quoted 10 lines

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Quoted 4 lines

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

- Arnaldo

#6 lore raw
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 11 lines · Ricardo Ribalda Delgado
Quoted 10 lines

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Quoted 7 lines
Quoted 4 lines

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

Hm, could we do:

	#define snprintf scnprintf

or:

	#define snprintf(x...) BUILD_BUG()

?

I don't think there's any valid code, except printf wrappers (which we don't have in perf), where the semantics of snprintf() would be needed.

Thanks,

Ingo

#7 lore raw

Hello Ingo Arnaldo and Peter

I have just posted v3,

Thanks for your comments!

Quoted 40 lines · Ingo Molnar
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 11 lines · Ricardo Ribalda Delgado
Quoted 10 lines

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Quoted 7 lines
Quoted 4 lines

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

Hm, could we do:

        #define snprintf scnprintf

or:

        #define snprintf(x...) BUILD_BUG()

?

I don't think there's any valid code, except printf wrappers (which we don't have in perf), where the semantics of snprintf() would be needed.

Thanks,

Ingo

Signature · 1 line
Ricardo Ribalda
#8 lore raw
In reply to Ingo Molnar

Em Wed, Sep 18, 2013 at 03:29:03PM +0200, Ingo Molnar escreveu:

Quoted 8 lines · Arnaldo Carvalho de Melo
Quoted 6 lines

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 2 lines

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

Quoted 6 lines

Hm, could we do:

	#define snprintf scnprintf
or:
	#define snprintf(x...) BUILD_BUG()

?

Yes, I prefer the later, with a short explanation, will do.

- Arnaldo

Quoted 6 lines

I don't think there's any valid code, except printf wrappers (which we don't have in perf), where the semantics of snprintf() would be needed.

Thanks,

Ingo

maintainer
#9 lore raw
In reply to Ingo Molnar

Hi Ingo and Arnaldo,

Quoted 27 lines · Ingo Molnar
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 11 lines · Ricardo Ribalda Delgado
Quoted 10 lines

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Quoted 7 lines
Quoted 4 lines

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

Hm, could we do:

	#define snprintf scnprintf
Quoted 8 lines

or:

	#define snprintf(x...) BUILD_BUG()

?

I don't think there's any valid code, except printf wrappers (which we don't have in perf), where the semantics of snprintf() would be needed.

There are some places that use snprintf() to query the actual length:

tools/perf/util/srcline.c:245: size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
tools/perf/util/values.c:147: width = snprintf(NULL, 0, "%d", values->pid[i]);
tools/perf/util/values.c:150: width = snprintf(NULL, 0, "%d", values->tid[i]);
tools/perf/util/values.c:154: width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);
tools/perf/util/values.c:189: width = snprintf(NULL, 0, "%d", values->pid[i]);
tools/perf/util/values.c:192: width = snprintf(NULL, 0, "%d", values->tid[i]);
tools/perf/util/values.c:200: width = snprintf(NULL, 0, "%" PRIx64, values->counterrawid[j]);
tools/perf/util/values.c:206: width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);

Thanks,
Namhyung

#10 lore raw
Quoted 41 lines · Namhyung Kim

Hi Ingo and Arnaldo,

Quoted 27 lines · Ingo Molnar
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 18, 2013 at 12:18:01PM +0200, Peter Zijlstra escreveu:

Quoted 11 lines · Ricardo Ribalda Delgado
Quoted 10 lines

Perhaps this is even more clear than v2:

len = snprintf(file, size, "%s", symbol_conf.symfs); size -= len;
file += len;
len = snprintf(file, MIN(size,(last_slash - dso->long_name) + 2), "%s", dso->long_name);
size -= len;
file += len;
len = snprintf(file, size, ".debug%s", last_slash);

Quoted 7 lines
Quoted 4 lines

len = 0;

len += snprintf(str + len, size - len, ...);
len += snprintf(str + len, size - len, ...);

And avoid snprintf like the plague, use scnprintf instead... See e7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 for details :-)

Hm, could we do:

	#define snprintf scnprintf
Quoted 8 lines

or:

	#define snprintf(x...) BUILD_BUG()

?

I don't think there's any valid code, except printf wrappers (which we don't have in perf), where the semantics of snprintf() would be needed.

There are some places that use snprintf() to query the actual length:

Quoted 8 lines

tools/perf/util/srcline.c:245: size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
tools/perf/util/values.c:147: width = snprintf(NULL, 0, "%d", values->pid[i]);
tools/perf/util/values.c:150: width = snprintf(NULL, 0, "%d", values->tid[i]);
tools/perf/util/values.c:154: width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);
tools/perf/util/values.c:189: width = snprintf(NULL, 0, "%d", values->pid[i]);
tools/perf/util/values.c:192: width = snprintf(NULL, 0, "%d", values->tid[i]);
tools/perf/util/values.c:200: width = snprintf(NULL, 0, "%" PRIx64, values->counterrawid[j]);
tools/perf/util/values.c:206: width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);

I think that should be a separate, more obviously named helper inline instead, something like:

static inline printf_width(const char *fmt, ...)

{
        va_list args;
        int width;

        va_start(args, fmt);
        width = vsnprintf(NULL, 0, fmt, args);
        va_end(args);

        return width;
}

#define snprintf(fmt...) BUILD_BUG_ON(1, "Use scnprintf() instead of snprintf()")

or so? Then we could use it like this:

Quoted 1 line

tools/perf/util/values.c:147: width = printf_width("%d", values->pid[i]);

and naked snprintf use would provoke a build bug.

Various printf wrappers can still use vsnprintf() - it's the routine use of snprintf() instead of scnprintf() that should be inhibited.

Thanks,

Ingo