Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191144
b: refs/heads/master
c: 5aab621
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Mar 26, 2010
1 parent 4354d29 commit aab76fc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 66 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 618038df3588fdfcaccfd40057f36ce792bee252
refs/heads/master: 5aab621b7bf024608f0c089e21656e7fe875a150
1 change: 1 addition & 0 deletions trunk/tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "parse-events.h"
#include "exec_cmd.h"
#include "string.h"
#include "symbol.h"
#include "cache.h"
#include "header.h"
#include "debugfs.h"
Expand Down
43 changes: 0 additions & 43 deletions trunk/tools/perf/util/string.c
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
#include "string.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
/*
* perf_atoll()
Expand Down
2 changes: 0 additions & 2 deletions trunk/tools/perf/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <stdbool.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);
char **argv_split(const char *str, int *argcp);
void argv_free(char **argv);
Expand Down
85 changes: 67 additions & 18 deletions trunk/tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#include "util.h"
#include "../perf.h"
#include "sort.h"
#include "string.h"
#define _GNU_SOURCE
#include <ctype.h>
#include <dirent.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 "thread.h"
#include "strlist.h"

#include "debug.h"

#include <asm/bug.h>
#include <libelf.h>
#include <gelf.h>
#include <elf.h>
Expand Down Expand Up @@ -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)
{
size_t namelen = strlen(name) + 1;
struct symbol *self = zalloc(symbol_conf.priv_size +
sizeof(*self) + namelen);
struct symbol *self = calloc(1, (symbol_conf.priv_size +
sizeof(*self) + namelen));
if (self == NULL)
return NULL;

Expand Down Expand Up @@ -166,7 +172,7 @@ static void dso__set_basename(struct dso *self)

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) {
int i;
Expand Down Expand Up @@ -1382,13 +1388,13 @@ static int dso__kernel_module_get_build_id(struct dso *self)
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;
DIR *dir = opendir(dirname);
DIR *dir = opendir(dir_name);

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;
}

Expand All @@ -1401,7 +1407,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
continue;

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)
goto failure;
} else {
Expand All @@ -1421,7 +1427,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
continue;

snprintf(path, sizeof(path), "%s/%s",
dirname, dent->d_name);
dir_name, dent->d_name);

long_name = strdup(path);
if (long_name == NULL)
Expand Down Expand Up @@ -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)
{
struct map *self = zalloc(sizeof(*self) +
(dso->kernel ? sizeof(struct kmap) : 0));
struct map *self = calloc(1, (sizeof(*self) +
(dso->kernel ? sizeof(struct kmap) : 0)));
if (self != NULL) {
/*
* ->end will be filled after we load all the symbols
Expand Down Expand Up @@ -1963,3 +1969,46 @@ int map_groups__create_kernel_maps(struct map_groups *self,
map_groups__fixup_end(self);
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;
}
10 changes: 8 additions & 2 deletions trunk/tools/perf/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <linux/types.h>
#include <stdbool.h>
#include "types.h"
#include <stdint.h>
#include "map.h"
#include <linux/list.h>
#include <linux/rbtree.h>
#include "event.h"
#include <stdio.h>

#define DEBUG_CACHE_DIR ".debug"

Expand All @@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
#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;
* for newer versions we can use mmap to reduce memory usage:
Expand All @@ -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 */
#endif

#define BUILD_ID_SIZE 20

struct symbol {
struct rb_node rb_node;
u64 start;
Expand Down

0 comments on commit aab76fc

Please sign in to comment.