提交 5aab621b 编写于 作者: A Arnaldo Carvalho de Melo 提交者: Ingo Molnar

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: NArnaldo 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: NIngo Molnar <mingo@elte.hu>
上级 618038df
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "parse-events.h" #include "parse-events.h"
#include "exec_cmd.h" #include "exec_cmd.h"
#include "string.h" #include "string.h"
#include "symbol.h"
#include "cache.h" #include "cache.h"
#include "header.h" #include "header.h"
#include "debugfs.h" #include "debugfs.h"
......
#include "string.h" #include "string.h"
#include "util.h" #include "util.h"
static int hex(char ch)
{
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
if ((ch >= 'A') && (ch <= 'F'))
return ch - 'A' + 10;
return -1;
}
/*
* While we find nice hex chars, build a long_val.
* Return number of chars processed.
*/
int hex2u64(const char *ptr, u64 *long_val)
{
const char *p = ptr;
*long_val = 0;
while (*p) {
const int hex_val = hex(*p);
if (hex_val < 0)
break;
*long_val = (*long_val << 4) | hex_val;
p++;
}
return p - ptr;
}
char *strxfrchar(char *s, char from, char to)
{
char *p = s;
while ((p = strchr(p, from)) != NULL)
*p++ = to;
return s;
}
#define K 1024LL #define K 1024LL
/* /*
* perf_atoll() * perf_atoll()
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include <stdbool.h> #include <stdbool.h>
#include "types.h" #include "types.h"
int hex2u64(const char *ptr, u64 *val);
char *strxfrchar(char *s, char from, char to);
s64 perf_atoll(const char *str); s64 perf_atoll(const char *str);
char **argv_split(const char *str, int *argcp); char **argv_split(const char *str, int *argcp);
void argv_free(char **argv); void argv_free(char **argv);
......
#include "util.h" #define _GNU_SOURCE
#include "../perf.h" #include <ctype.h>
#include "sort.h" #include <dirent.h>
#include "string.h" #include <errno.h>
#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <fcntl.h>
#include <unistd.h>
#include "symbol.h" #include "symbol.h"
#include "thread.h" #include "strlist.h"
#include "debug.h"
#include <asm/bug.h>
#include <libelf.h> #include <libelf.h>
#include <gelf.h> #include <gelf.h>
#include <elf.h> #include <elf.h>
...@@ -114,8 +120,8 @@ static void map_groups__fixup_end(struct map_groups *self) ...@@ -114,8 +120,8 @@ static void map_groups__fixup_end(struct map_groups *self)
static struct symbol *symbol__new(u64 start, u64 len, const char *name) static struct symbol *symbol__new(u64 start, u64 len, const char *name)
{ {
size_t namelen = strlen(name) + 1; size_t namelen = strlen(name) + 1;
struct symbol *self = zalloc(symbol_conf.priv_size + struct symbol *self = calloc(1, (symbol_conf.priv_size +
sizeof(*self) + namelen); sizeof(*self) + namelen));
if (self == NULL) if (self == NULL)
return NULL; return NULL;
...@@ -166,7 +172,7 @@ static void dso__set_basename(struct dso *self) ...@@ -166,7 +172,7 @@ static void dso__set_basename(struct dso *self)
struct dso *dso__new(const char *name) struct dso *dso__new(const char *name)
{ {
struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1); struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1);
if (self != NULL) { if (self != NULL) {
int i; int i;
...@@ -1382,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self) ...@@ -1382,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self)
return 0; return 0;
} }
static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname) static int map_groups__set_modules_path_dir(struct map_groups *self, char *dir_name)
{ {
struct dirent *dent; struct dirent *dent;
DIR *dir = opendir(dirname); DIR *dir = opendir(dir_name);
if (!dir) { if (!dir) {
pr_debug("%s: cannot open %s dir\n", __func__, dirname); pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
return -1; return -1;
} }
...@@ -1401,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna ...@@ -1401,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
continue; continue;
snprintf(path, sizeof(path), "%s/%s", snprintf(path, sizeof(path), "%s/%s",
dirname, dent->d_name); dir_name, dent->d_name);
if (map_groups__set_modules_path_dir(self, path) < 0) if (map_groups__set_modules_path_dir(self, path) < 0)
goto failure; goto failure;
} else { } else {
...@@ -1421,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna ...@@ -1421,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
continue; continue;
snprintf(path, sizeof(path), "%s/%s", snprintf(path, sizeof(path), "%s/%s",
dirname, dent->d_name); dir_name, dent->d_name);
long_name = strdup(path); long_name = strdup(path);
if (long_name == NULL) if (long_name == NULL)
...@@ -1458,8 +1464,8 @@ static int map_groups__set_modules_path(struct map_groups *self) ...@@ -1458,8 +1464,8 @@ static int map_groups__set_modules_path(struct map_groups *self)
*/ */
static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
{ {
struct map *self = zalloc(sizeof(*self) + struct map *self = calloc(1, (sizeof(*self) +
(dso->kernel ? sizeof(struct kmap) : 0)); (dso->kernel ? sizeof(struct kmap) : 0)));
if (self != NULL) { if (self != NULL) {
/* /*
* ->end will be filled after we load all the symbols * ->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,3 +1969,46 @@ int map_groups__create_kernel_maps(struct map_groups *self,
map_groups__fixup_end(self); map_groups__fixup_end(self);
return 0; return 0;
} }
static int hex(char ch)
{
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
if ((ch >= 'A') && (ch <= 'F'))
return ch - 'A' + 10;
return -1;
}
/*
* While we find nice hex chars, build a long_val.
* Return number of chars processed.
*/
int hex2u64(const char *ptr, u64 *long_val)
{
const char *p = ptr;
*long_val = 0;
while (*p) {
const int hex_val = hex(*p);
if (hex_val < 0)
break;
*long_val = (*long_val << 4) | hex_val;
p++;
}
return p - ptr;
}
char *strxfrchar(char *s, char from, char to)
{
char *p = s;
while ((p = strchr(p, from)) != NULL)
*p++ = to;
return s;
}
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
#include <linux/types.h> #include <linux/types.h>
#include <stdbool.h> #include <stdbool.h>
#include "types.h" #include <stdint.h>
#include "map.h"
#include <linux/list.h> #include <linux/list.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include "event.h" #include <stdio.h>
#define DEBUG_CACHE_DIR ".debug" #define DEBUG_CACHE_DIR ".debug"
...@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, ...@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
#endif #endif
#endif #endif
int hex2u64(const char *ptr, u64 *val);
char *strxfrchar(char *s, char from, char to);
/* /*
* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
* for newer versions we can use mmap to reduce memory usage: * 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,6 +48,8 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
#endif #endif
#define BUILD_ID_SIZE 20
struct symbol { struct symbol {
struct rb_node rb_node; struct rb_node rb_node;
u64 start; u64 start;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册