[tip:perf/core] perf tools: Move dso_* related functions into dso object

2012-10-30 Thread tip-bot for Jiri Olsa
Commit-ID:  cdd059d731eeb466f51a404ee6cbfafb0fc7c20b
Gitweb: http://git.kernel.org/tip/cdd059d731eeb466f51a404ee6cbfafb0fc7c20b
Author: Jiri Olsa 
AuthorDate: Sat, 27 Oct 2012 23:18:32 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:37:25 -0200

perf tools: Move dso_* related functions into dso object

Moving dso_* related functions into dso object.

Keeping symbol loading related functions still in the symbol object as
it seems more convenient.

Signed-off-by: Jiri Olsa 
Reviewed-by: Namhyung Kim 
Tested-by: Namhyung Kim 
Cc: Corey Ashford 
Cc: Frederic Weisbecker 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351372712-21104-6-git-send-email-jo...@redhat.com
[ committer note: Use "symbol.h" instead of  to make it build with O= 
]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile  |2 +
 tools/perf/util/dso.c|  594 +
 tools/perf/util/dso.h|  148 
 tools/perf/util/symbol.c |  599 +-
 tools/perf/util/symbol.h |  134 +--
 5 files changed, 751 insertions(+), 726 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 629fc6a..ec63d53 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -327,6 +327,7 @@ LIB_H += util/svghelper.h
 LIB_H += util/tool.h
 LIB_H += util/run-command.h
 LIB_H += util/sigchain.h
+LIB_H += util/dso.h
 LIB_H += util/symbol.h
 LIB_H += util/color.h
 LIB_H += util/values.h
@@ -385,6 +386,7 @@ LIB_OBJS += $(OUTPUT)util/top.o
 LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
+LIB_OBJS += $(OUTPUT)util/dso.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
 LIB_OBJS += $(OUTPUT)util/symbol-elf.o
 LIB_OBJS += $(OUTPUT)util/dso-test-data.o
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
new file mode 100644
index 000..db24a3f
--- /dev/null
+++ b/tools/perf/util/dso.c
@@ -0,0 +1,594 @@
+#include "symbol.h"
+#include "dso.h"
+#include "util.h"
+#include "debug.h"
+
+char dso__symtab_origin(const struct dso *dso)
+{
+   static const char origin[] = {
+   [DSO_BINARY_TYPE__KALLSYMS] = 'k',
+   [DSO_BINARY_TYPE__VMLINUX]  = 'v',
+   [DSO_BINARY_TYPE__JAVA_JIT] = 'j',
+   [DSO_BINARY_TYPE__DEBUGLINK]= 'l',
+   [DSO_BINARY_TYPE__BUILD_ID_CACHE]   = 'B',
+   [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f',
+   [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u',
+   [DSO_BINARY_TYPE__BUILDID_DEBUGINFO]= 'b',
+   [DSO_BINARY_TYPE__SYSTEM_PATH_DSO]  = 'd',
+   [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]  = 'K',
+   [DSO_BINARY_TYPE__GUEST_KALLSYMS]   = 'g',
+   [DSO_BINARY_TYPE__GUEST_KMODULE]= 'G',
+   [DSO_BINARY_TYPE__GUEST_VMLINUX]= 'V',
+   };
+
+   if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
+   return '!';
+   return origin[dso->symtab_type];
+}
+
+int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
+ char *root_dir, char *file, size_t size)
+{
+   char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+   int ret = 0;
+
+   switch (type) {
+   case DSO_BINARY_TYPE__DEBUGLINK: {
+   char *debuglink;
+
+   strncpy(file, dso->long_name, size);
+   debuglink = file + dso->long_name_len;
+   while (debuglink != file && *debuglink != '/')
+   debuglink--;
+   if (*debuglink == '/')
+   debuglink++;
+   filename__read_debuglink(dso->long_name, debuglink,
+size - (debuglink - file));
+   }
+   break;
+   case DSO_BINARY_TYPE__BUILD_ID_CACHE:
+   /* skip the locally configured cache if a symfs is given */
+   if (symbol_conf.symfs[0] ||
+   (dso__build_id_filename(dso, file, size) == NULL))
+   ret = -1;
+   break;
+
+   case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
+   snprintf(file, size, "%s/usr/lib/debug%s.debug",
+symbol_conf.symfs, dso->long_name);
+   break;
+
+   case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
+   snprintf(file, size, "%s/usr/lib/debug%s",
+symbol_conf.symfs, dso->long_name);
+   break;
+
+   case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
+   if (!dso->has_build_id) {
+   ret = -1;
+   break;
+   }
+
+   build_id__sprintf(dso->build_id,
+ sizeof(dso->build_id),
+ 

[tip:perf/core] perf tools: Move dso_* related functions into dso object

2012-10-30 Thread tip-bot for Jiri Olsa
Commit-ID:  cdd059d731eeb466f51a404ee6cbfafb0fc7c20b
Gitweb: http://git.kernel.org/tip/cdd059d731eeb466f51a404ee6cbfafb0fc7c20b
Author: Jiri Olsa jo...@redhat.com
AuthorDate: Sat, 27 Oct 2012 23:18:32 +0200
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:37:25 -0200

perf tools: Move dso_* related functions into dso object

Moving dso_* related functions into dso object.

Keeping symbol loading related functions still in the symbol object as
it seems more convenient.

Signed-off-by: Jiri Olsa jo...@redhat.com
Reviewed-by: Namhyung Kim namhy...@kernel.org
Tested-by: Namhyung Kim namhy...@kernel.org
Cc: Corey Ashford cjash...@linux.vnet.ibm.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1351372712-21104-6-git-send-email-jo...@redhat.com
[ committer note: Use symbol.h instead of symbol.h to make it build with O= 
]
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/Makefile  |2 +
 tools/perf/util/dso.c|  594 +
 tools/perf/util/dso.h|  148 
 tools/perf/util/symbol.c |  599 +-
 tools/perf/util/symbol.h |  134 +--
 5 files changed, 751 insertions(+), 726 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 629fc6a..ec63d53 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -327,6 +327,7 @@ LIB_H += util/svghelper.h
 LIB_H += util/tool.h
 LIB_H += util/run-command.h
 LIB_H += util/sigchain.h
+LIB_H += util/dso.h
 LIB_H += util/symbol.h
 LIB_H += util/color.h
 LIB_H += util/values.h
@@ -385,6 +386,7 @@ LIB_OBJS += $(OUTPUT)util/top.o
 LIB_OBJS += $(OUTPUT)util/usage.o
 LIB_OBJS += $(OUTPUT)util/wrapper.o
 LIB_OBJS += $(OUTPUT)util/sigchain.o
+LIB_OBJS += $(OUTPUT)util/dso.o
 LIB_OBJS += $(OUTPUT)util/symbol.o
 LIB_OBJS += $(OUTPUT)util/symbol-elf.o
 LIB_OBJS += $(OUTPUT)util/dso-test-data.o
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
new file mode 100644
index 000..db24a3f
--- /dev/null
+++ b/tools/perf/util/dso.c
@@ -0,0 +1,594 @@
+#include symbol.h
+#include dso.h
+#include util.h
+#include debug.h
+
+char dso__symtab_origin(const struct dso *dso)
+{
+   static const char origin[] = {
+   [DSO_BINARY_TYPE__KALLSYMS] = 'k',
+   [DSO_BINARY_TYPE__VMLINUX]  = 'v',
+   [DSO_BINARY_TYPE__JAVA_JIT] = 'j',
+   [DSO_BINARY_TYPE__DEBUGLINK]= 'l',
+   [DSO_BINARY_TYPE__BUILD_ID_CACHE]   = 'B',
+   [DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f',
+   [DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u',
+   [DSO_BINARY_TYPE__BUILDID_DEBUGINFO]= 'b',
+   [DSO_BINARY_TYPE__SYSTEM_PATH_DSO]  = 'd',
+   [DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]  = 'K',
+   [DSO_BINARY_TYPE__GUEST_KALLSYMS]   = 'g',
+   [DSO_BINARY_TYPE__GUEST_KMODULE]= 'G',
+   [DSO_BINARY_TYPE__GUEST_VMLINUX]= 'V',
+   };
+
+   if (dso == NULL || dso-symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
+   return '!';
+   return origin[dso-symtab_type];
+}
+
+int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
+ char *root_dir, char *file, size_t size)
+{
+   char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+   int ret = 0;
+
+   switch (type) {
+   case DSO_BINARY_TYPE__DEBUGLINK: {
+   char *debuglink;
+
+   strncpy(file, dso-long_name, size);
+   debuglink = file + dso-long_name_len;
+   while (debuglink != file  *debuglink != '/')
+   debuglink--;
+   if (*debuglink == '/')
+   debuglink++;
+   filename__read_debuglink(dso-long_name, debuglink,
+size - (debuglink - file));
+   }
+   break;
+   case DSO_BINARY_TYPE__BUILD_ID_CACHE:
+   /* skip the locally configured cache if a symfs is given */
+   if (symbol_conf.symfs[0] ||
+   (dso__build_id_filename(dso, file, size) == NULL))
+   ret = -1;
+   break;
+
+   case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
+   snprintf(file, size, %s/usr/lib/debug%s.debug,
+symbol_conf.symfs, dso-long_name);
+   break;
+
+   case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
+   snprintf(file, size, %s/usr/lib/debug%s,
+symbol_conf.symfs, dso-long_name);
+   break;
+
+   case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
+   if (!dso-has_build_id) {
+   ret = -1;
+