Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native profiling tools support #789

Merged
merged 5 commits into from
Apr 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions boards/native/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ export DEBUGGER = gdb
export TERMPROG = $(ELF)
export FLASHER = true
export VALGRIND ?= valgrind
export CGANNOTATE ?= cg_annotate
export GPROF ?= gprof

# flags:
export CFLAGS += -Wall -Wextra -pedantic -m32
export LINKFLAGS += -m32 -gc -ldl
export ASFLAGS =
export DEBUGGER_FLAGS = $(ELF)
export VALGRIND_FLAGS ?= --track-origins=yes
term-memcheck: export VALGRIND_FLAGS ?= --track-origins=yes
term-cachegrind: export CACHEGRIND_FLAGS += --tool=cachegrind
term-gprof: export TERMPROG = GMON_OUT_PREFIX=gmon.out $(ELF)
all-valgrind: export CFLAGS += -DHAVE_VALGRIND_H -g
all-valgrind: export NATIVEINCLUDES += $(shell pkg-config valgrind --cflags)
all-debug: export CFLAGS += -g
all-cachegrind: export CFLAGS += -g
all-gprof: export CFLAGS += -pg
all-gprof: export LINKFLAGS += -pg

export INCLUDES += $(NATIVEINCLUDES)

Expand Down Expand Up @@ -56,10 +64,25 @@ endif

all: # do not override first target

all-gprof: all

all-valgrind: all

valgrind:
all-cachegrind: all

term-valgrind:
# use this if you want to attach gdb from valgrind:
# echo 0 > /proc/sys/kernel/yama/ptrace_scope
# VALGRIND_FLAGS += --db-attach=yes
$(VALGRIND) $(VALGRIND_FLAGS) $(ELF) $(PORT)

term-cachegrind:
$(VALGRIND) $(CACHEGRIND_FLAGS) $(ELF) $(PORT)

term-gprof: term

eval-gprof:
$(GPROF) $(ELF) $(shell ls -rt gmon.out* | tail -1)

eval-cachegrind:
$(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1)
1 change: 0 additions & 1 deletion cpu/native/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
*(void **)(&real_read) = dlsym(RTLD_NEXT, "read");
*(void **)(&real_write) = dlsym(RTLD_NEXT, "write");
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
*(void **)(&real_calloc) = dlsym(RTLD_NEXT, "calloc");
*(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc");
*(void **)(&real_free) = dlsym(RTLD_NEXT, "free");

Expand Down
16 changes: 13 additions & 3 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,22 @@ void free(void *ptr)
_native_syscall_leave();
}

int _native_in_calloc;
void *calloc(size_t nmemb, size_t size)
{
/* XXX: This is a dirty hack to enable old dlsym versions to run.
* Throw it out when Ubuntu 12.04 support runs out (in 2017-04)! */
/* dynamically load calloc when it's needed - this is necessary to
* support profiling as it uses calloc before startup runs */
if (!real_calloc) {
return NULL;
if (_native_in_calloc) {
/* XXX: This is a dirty hack to enable old dlsym versions to run.
* Throw it out when Ubuntu 12.04 support runs out (in 2017-04)! */
return NULL;
}
else {
_native_in_calloc = 1;
*(void **)(&real_calloc) = dlsym(RTLD_NEXT, "calloc");
_native_in_calloc = 0;
}
}

void *r;
Expand Down