aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-03-25 18:59:00 -0400
committerIngo Molnar <mingo@elte.hu>2010-03-26 03:52:59 -0400
commit5aab621b7bf024608f0c089e21656e7fe875a150 (patch)
tree5fd0da72082d4a60e0d05c727411cd089250d3a3
parent618038df3588fdfcaccfd40057f36ce792bee252 (diff)
perf symbols: Move hex2u64 and strxfrchar to symbol.c
Mostly used in symbol.c so move them there to reduce the number of files needed to use the symbol system. Also do some header adjustments with the same intent. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1269557941-15617-5-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--tools/perf/util/parse-events.c1
-rw-r--r--tools/perf/util/string.c43
-rw-r--r--tools/perf/util/string.h2
-rw-r--r--tools/perf/util/symbol.c85
-rw-r--r--tools/perf/util/symbol.h10
5 files changed, 76 insertions, 65 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index a2014459125a..435781e0c205 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -5,6 +5,7 @@
5#include "parse-events.h" 5#include "parse-events.h"
6#include "exec_cmd.h" 6#include "exec_cmd.h"
7#include "string.h" 7#include "string.h"
8#include "symbol.h"
8#include "cache.h" 9#include "cache.h"
9#include "header.h" 10#include "header.h"
10#include "debugfs.h" 11#include "debugfs.h"
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index a175949ed216..d4389242cfd7 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,49 +1,6 @@
1#include "string.h" 1#include "string.h"
2#include "util.h" 2#include "util.h"
3 3
4static int hex(char ch)
5{
6 if ((ch >= '0') && (ch <= '9'))
7 return ch - '0';
8 if ((ch >= 'a') && (ch <= 'f'))
9 return ch - 'a' + 10;
10 if ((ch >= 'A') && (ch <= 'F'))
11 return ch - 'A' + 10;
12 return -1;
13}
14
15/*
16 * While we find nice hex chars, build a long_val.
17 * Return number of chars processed.
18 */
19int hex2u64(const char *ptr, u64 *long_val)
20{
21 const char *p = ptr;
22 *long_val = 0;
23
24 while (*p) {
25 const int hex_val = hex(*p);
26
27 if (hex_val < 0)
28 break;
29
30 *long_val = (*long_val << 4) | hex_val;
31 p++;
32 }
33
34 return p - ptr;
35}
36
37char *strxfrchar(char *s, char from, char to)
38{
39 char *p = s;
40
41 while ((p = strchr(p, from)) != NULL)
42 *p++ = to;
43
44 return s;
45}
46
47#define K 1024LL 4#define K 1024LL
48/* 5/*
49 * perf_atoll() 6 * perf_atoll()
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
index 542e44de3719..700582416664 100644
--- a/tools/perf/util/string.h
+++ b/tools/perf/util/string.h
@@ -4,8 +4,6 @@
4#include <stdbool.h> 4#include <stdbool.h>
5#include "types.h" 5#include "types.h"
6 6
7int hex2u64(const char *ptr, u64 *val);
8char *strxfrchar(char *s, char from, char to);
9s64 perf_atoll(const char *str); 7s64 perf_atoll(const char *str);
10char **argv_split(const char *str, int *argcp); 8char **argv_split(const char *str, int *argcp);
11void argv_free(char **argv); 9void argv_free(char **argv);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 3eb9de4baef3..f3d4151e46a1 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1,13 +1,19 @@
1#include "util.h" 1#define _GNU_SOURCE
2#include "../perf.h" 2#include <ctype.h>
3#include "sort.h" 3#include <dirent.h>
4#include "string.h" 4#include <errno.h>
5#include <libgen.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/param.h>
12#include <fcntl.h>
13#include <unistd.h>
5#include "symbol.h" 14#include "symbol.h"
6#include "thread.h" 15#include "strlist.h"
7 16
8#include "debug.h"
9
10#include <asm/bug.h>
11#include <libelf.h> 17#include <libelf.h>
12#include <gelf.h> 18#include <gelf.h>
13#include <elf.h> 19#include <elf.h>
@@ -114,8 +120,8 @@ static void map_groups__fixup_end(struct map_groups *self)
114static struct symbol *symbol__new(u64 start, u64 len, const char *name) 120static struct symbol *symbol__new(u64 start, u64 len, const char *name)
115{ 121{
116 size_t namelen = strlen(name) + 1; 122 size_t namelen = strlen(name) + 1;
117 struct symbol *self = zalloc(symbol_conf.priv_size + 123 struct symbol *self = calloc(1, (symbol_conf.priv_size +
118 sizeof(*self) + namelen); 124 sizeof(*self) + namelen));
119 if (self == NULL) 125 if (self == NULL)
120 return NULL; 126 return NULL;
121 127
@@ -166,7 +172,7 @@ static void dso__set_basename(struct dso *self)
166 172
167struct dso *dso__new(const char *name) 173struct dso *dso__new(const char *name)
168{ 174{
169 struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1); 175 struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1);
170 176
171 if (self != NULL) { 177 if (self != NULL) {
172 int i; 178 int i;
@@ -1382,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self)
1382 return 0; 1388 return 0;
1383} 1389}
1384 1390
1385static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname) 1391static int map_groups__set_modules_path_dir(struct map_groups *self, char *dir_name)
1386{ 1392{
1387 struct dirent *dent; 1393 struct dirent *dent;
1388 DIR *dir = opendir(dirname); 1394 DIR *dir = opendir(dir_name);
1389 1395
1390 if (!dir) { 1396 if (!dir) {
1391 pr_debug("%s: cannot open %s dir\n", __func__, dirname); 1397 pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
1392 return -1; 1398 return -1;
1393 } 1399 }
1394 1400
@@ -1401,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
1401 continue; 1407 continue;
1402 1408
1403 snprintf(path, sizeof(path), "%s/%s", 1409 snprintf(path, sizeof(path), "%s/%s",
1404 dirname, dent->d_name); 1410 dir_name, dent->d_name);
1405 if (map_groups__set_modules_path_dir(self, path) < 0) 1411 if (map_groups__set_modules_path_dir(self, path) < 0)
1406 goto failure; 1412 goto failure;
1407 } else { 1413 } else {
@@ -1421,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
1421 continue; 1427 continue;
1422 1428
1423 snprintf(path, sizeof(path), "%s/%s", 1429 snprintf(path, sizeof(path), "%s/%s",
1424 dirname, dent->d_name); 1430 dir_name, dent->d_name);
1425 1431
1426 long_name = strdup(path); 1432 long_name = strdup(path);
1427 if (long_name == NULL) 1433 if (long_name == NULL)
@@ -1458,8 +1464,8 @@ static int map_groups__set_modules_path(struct map_groups *self)
1458 */ 1464 */
1459static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) 1465static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
1460{ 1466{
1461 struct map *self = zalloc(sizeof(*self) + 1467 struct map *self = calloc(1, (sizeof(*self) +
1462 (dso->kernel ? sizeof(struct kmap) : 0)); 1468 (dso->kernel ? sizeof(struct kmap) : 0)));
1463 if (self != NULL) { 1469 if (self != NULL) {
1464 /* 1470 /*
1465 * ->end will be filled after we load all the symbols 1471 * ->end will be filled after we load all the symbols
@@ -1963,3 +1969,46 @@ int map_groups__create_kernel_maps(struct map_groups *self,
1963 map_groups__fixup_end(self); 1969 map_groups__fixup_end(self);
1964 return 0; 1970 return 0;
1965} 1971}
1972
1973static int hex(char ch)
1974{
1975 if ((ch >= '0') && (ch <= '9'))
1976 return ch - '0';
1977 if ((ch >= 'a') && (ch <= 'f'))
1978 return ch - 'a' + 10;
1979 if ((ch >= 'A') && (ch <= 'F'))
1980 return ch - 'A' + 10;
1981 return -1;
1982}
1983
1984/*
1985 * While we find nice hex chars, build a long_val.
1986 * Return number of chars processed.
1987 */
1988int hex2u64(const char *ptr, u64 *long_val)
1989{
1990 const char *p = ptr;
1991 *long_val = 0;
1992
1993 while (*p) {
1994 const int hex_val = hex(*p);
1995
1996 if (hex_val < 0)
1997 break;
1998
1999 *long_val = (*long_val << 4) | hex_val;
2000 p++;
2001 }
2002
2003 return p - ptr;
2004}
2005
2006char *strxfrchar(char *s, char from, char to)
2007{
2008 char *p = s;
2009
2010 while ((p = strchr(p, from)) != NULL)
2011 *p++ = to;
2012
2013 return s;
2014}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index a4a894b8ea03..757fae3f5ee0 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -3,10 +3,11 @@
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include "types.h" 6#include <stdint.h>
7#include "map.h"
7#include <linux/list.h> 8#include <linux/list.h>
8#include <linux/rbtree.h> 9#include <linux/rbtree.h>
9#include "event.h" 10#include <stdio.h>
10 11
11#define DEBUG_CACHE_DIR ".debug" 12#define DEBUG_CACHE_DIR ".debug"
12 13
@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
29#endif 30#endif
30#endif 31#endif
31 32
33int hex2u64(const char *ptr, u64 *val);
34char *strxfrchar(char *s, char from, char to);
35
32/* 36/*
33 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; 37 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
34 * for newer versions we can use mmap to reduce memory usage: 38 * for newer versions we can use mmap to reduce memory usage:
@@ -44,6 +48,8 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
44#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ 48#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
45#endif 49#endif
46 50
51#define BUILD_ID_SIZE 20
52
47struct symbol { 53struct symbol {
48 struct rb_node rb_node; 54 struct rb_node rb_node;
49 u64 start; 55 u64 start;