Re: [PATCH 1/2] perf tests: Factor out fake_setup_machine()
On Mon, Apr 28, 2014 at 08:59:42AM +0900, Namhyung Kim wrote: > Hi Jiri, > > On Fri, 25 Apr 2014 14:27:34 +0200, Jiri Olsa wrote: > > On Fri, Apr 25, 2014 at 12:28:13PM +0900, Namhyung Kim wrote: > >> The fake_setup_machine() is for setting up a environment for testing > >> various hists operations. As it'll be used for other test cases it'd > >> better factoring it out. > > > > looks like print_hists could be in hists_common.c as well.. > > within another update ;-) > > The difference is that one in hists_link.c is working on the input tree > while one in hists_filter.c is working on the output tree. I see, missed that.. ok thanks, jirka -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/2] perf tests: Factor out fake_setup_machine()
Hi Jiri, On Fri, 25 Apr 2014 14:27:34 +0200, Jiri Olsa wrote: > On Fri, Apr 25, 2014 at 12:28:13PM +0900, Namhyung Kim wrote: >> The fake_setup_machine() is for setting up a environment for testing >> various hists operations. As it'll be used for other test cases it'd >> better factoring it out. > > looks like print_hists could be in hists_common.c as well.. > within another update ;-) The difference is that one in hists_link.c is working on the input tree while one in hists_filter.c is working on the output tree. > > nice! > > Acked-by: Jiri Olsa > > for patchset Thanks for review! Namhyung -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/2] perf tests: Factor out fake_setup_machine()
On Fri, Apr 25, 2014 at 12:28:13PM +0900, Namhyung Kim wrote: > The fake_setup_machine() is for setting up a environment for testing > various hists operations. As it'll be used for other test cases it'd > better factoring it out. looks like print_hists could be in hists_common.c as well.. within another update ;-) nice! Acked-by: Jiri Olsa for patchset thanks, jirka > > Signed-off-by: Namhyung Kim > --- > tools/perf/Makefile.perf| 1 + > tools/perf/tests/hists_common.c | 148 > > tools/perf/tests/hists_common.h | 44 > tools/perf/tests/hists_link.c | 141 +- > 4 files changed, 195 insertions(+), 139 deletions(-) > create mode 100644 tools/perf/tests/hists_common.c > create mode 100644 tools/perf/tests/hists_common.h > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index eb57e2cf1b4c..1490afeb7252 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -396,6 +396,7 @@ LIB_OBJS += $(OUTPUT)tests/rdpmc.o > LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o > LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o > LIB_OBJS += $(OUTPUT)tests/pmu.o > +LIB_OBJS += $(OUTPUT)tests/hists_common.o > LIB_OBJS += $(OUTPUT)tests/hists_link.o > LIB_OBJS += $(OUTPUT)tests/python-use.o > LIB_OBJS += $(OUTPUT)tests/bp_signal.o > diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c > new file mode 100644 > index ..44655b395bb9 > --- /dev/null > +++ b/tools/perf/tests/hists_common.c > @@ -0,0 +1,148 @@ > +#include "perf.h" > +#include "util/debug.h" > +#include "util/symbol.h" > +#include "util/sort.h" > +#include "util/evsel.h" > +#include "util/evlist.h" > +#include "util/machine.h" > +#include "util/thread.h" > +#include "tests/hists_common.h" > + > +static struct { > + u32 pid; > + const char *comm; > +} fake_threads[] = { > + { 100, "perf" }, > + { 200, "perf" }, > + { 300, "bash" }, > +}; > + > +static struct { > + u32 pid; > + u64 start; > + const char *filename; > +} fake_mmap_info[] = { > + { 100, 0x4, "perf" }, > + { 100, 0x5, "libc" }, > + { 100, 0xf, "[kernel]" }, > + { 200, 0x4, "perf" }, > + { 200, 0x5, "libc" }, > + { 200, 0xf, "[kernel]" }, > + { 300, 0x4, "bash" }, > + { 300, 0x5, "libc" }, > + { 300, 0xf, "[kernel]" }, > +}; > + > +struct fake_sym { > + u64 start; > + u64 length; > + const char *name; > +}; > + > +static struct fake_sym perf_syms[] = { > + { 700, 100, "main" }, > + { 800, 100, "run_command" }, > + { 900, 100, "cmd_record" }, > +}; > + > +static struct fake_sym bash_syms[] = { > + { 700, 100, "main" }, > + { 800, 100, "xmalloc" }, > + { 900, 100, "xfree" }, > +}; > + > +static struct fake_sym libc_syms[] = { > + { 700, 100, "malloc" }, > + { 800, 100, "free" }, > + { 900, 100, "realloc" }, > +}; > + > +static struct fake_sym kernel_syms[] = { > + { 700, 100, "schedule" }, > + { 800, 100, "page_fault" }, > + { 900, 100, "sys_perf_event_open" }, > +}; > + > +static struct { > + const char *dso_name; > + struct fake_sym *syms; > + size_t nr_syms; > +} fake_symbols[] = { > + { "perf", perf_syms, ARRAY_SIZE(perf_syms) }, > + { "bash", bash_syms, ARRAY_SIZE(bash_syms) }, > + { "libc", libc_syms, ARRAY_SIZE(libc_syms) }, > + { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) }, > +}; > + > +struct machine *setup_fake_machine(struct machines *machines) > +{ > + struct machine *machine = machines__find(machines, HOST_KERNEL_ID); > + size_t i; > + > + if (machine == NULL) { > + pr_debug("Not enough memory for machine setup\n"); > + return NULL; > + } > + > + for (i = 0; i < ARRAY_SIZE(fake_threads); i++) { > + struct thread *thread; > + > + thread = machine__findnew_thread(machine, fake_threads[i].pid, > + fake_threads[i].pid); > + if (thread == NULL) > + goto out; > + > + thread__set_comm(thread, fake_threads[i].comm, 0); > + } > + > + for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { > + union perf_event fake_mmap_event = { > + .mmap = { > + .header = { .misc = PERF_RECORD_MISC_USER, }, > + .pid = fake_mmap_info[i].pid, > + .tid = fake_mmap_info[i].pid, > + .start = fake_mmap_info[i].start, > + .len = 0x1000ULL, > + .pgoff = 0ULL, > + }, > + }; > + > + strcpy(fake_mmap_event.mmap.filename, > +fake_mmap_info[i].filename); > + > + machine__process_mmap_event(machine, &fake_mmap_event, NU
[PATCH 1/2] perf tests: Factor out fake_setup_machine()
The fake_setup_machine() is for setting up a environment for testing various hists operations. As it'll be used for other test cases it'd better factoring it out. Signed-off-by: Namhyung Kim --- tools/perf/Makefile.perf| 1 + tools/perf/tests/hists_common.c | 148 tools/perf/tests/hists_common.h | 44 tools/perf/tests/hists_link.c | 141 +- 4 files changed, 195 insertions(+), 139 deletions(-) create mode 100644 tools/perf/tests/hists_common.c create mode 100644 tools/perf/tests/hists_common.h diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index eb57e2cf1b4c..1490afeb7252 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -396,6 +396,7 @@ LIB_OBJS += $(OUTPUT)tests/rdpmc.o LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o LIB_OBJS += $(OUTPUT)tests/pmu.o +LIB_OBJS += $(OUTPUT)tests/hists_common.o LIB_OBJS += $(OUTPUT)tests/hists_link.o LIB_OBJS += $(OUTPUT)tests/python-use.o LIB_OBJS += $(OUTPUT)tests/bp_signal.o diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c new file mode 100644 index ..44655b395bb9 --- /dev/null +++ b/tools/perf/tests/hists_common.c @@ -0,0 +1,148 @@ +#include "perf.h" +#include "util/debug.h" +#include "util/symbol.h" +#include "util/sort.h" +#include "util/evsel.h" +#include "util/evlist.h" +#include "util/machine.h" +#include "util/thread.h" +#include "tests/hists_common.h" + +static struct { + u32 pid; + const char *comm; +} fake_threads[] = { + { 100, "perf" }, + { 200, "perf" }, + { 300, "bash" }, +}; + +static struct { + u32 pid; + u64 start; + const char *filename; +} fake_mmap_info[] = { + { 100, 0x4, "perf" }, + { 100, 0x5, "libc" }, + { 100, 0xf, "[kernel]" }, + { 200, 0x4, "perf" }, + { 200, 0x5, "libc" }, + { 200, 0xf, "[kernel]" }, + { 300, 0x4, "bash" }, + { 300, 0x5, "libc" }, + { 300, 0xf, "[kernel]" }, +}; + +struct fake_sym { + u64 start; + u64 length; + const char *name; +}; + +static struct fake_sym perf_syms[] = { + { 700, 100, "main" }, + { 800, 100, "run_command" }, + { 900, 100, "cmd_record" }, +}; + +static struct fake_sym bash_syms[] = { + { 700, 100, "main" }, + { 800, 100, "xmalloc" }, + { 900, 100, "xfree" }, +}; + +static struct fake_sym libc_syms[] = { + { 700, 100, "malloc" }, + { 800, 100, "free" }, + { 900, 100, "realloc" }, +}; + +static struct fake_sym kernel_syms[] = { + { 700, 100, "schedule" }, + { 800, 100, "page_fault" }, + { 900, 100, "sys_perf_event_open" }, +}; + +static struct { + const char *dso_name; + struct fake_sym *syms; + size_t nr_syms; +} fake_symbols[] = { + { "perf", perf_syms, ARRAY_SIZE(perf_syms) }, + { "bash", bash_syms, ARRAY_SIZE(bash_syms) }, + { "libc", libc_syms, ARRAY_SIZE(libc_syms) }, + { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) }, +}; + +struct machine *setup_fake_machine(struct machines *machines) +{ + struct machine *machine = machines__find(machines, HOST_KERNEL_ID); + size_t i; + + if (machine == NULL) { + pr_debug("Not enough memory for machine setup\n"); + return NULL; + } + + for (i = 0; i < ARRAY_SIZE(fake_threads); i++) { + struct thread *thread; + + thread = machine__findnew_thread(machine, fake_threads[i].pid, +fake_threads[i].pid); + if (thread == NULL) + goto out; + + thread__set_comm(thread, fake_threads[i].comm, 0); + } + + for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { + union perf_event fake_mmap_event = { + .mmap = { + .header = { .misc = PERF_RECORD_MISC_USER, }, + .pid = fake_mmap_info[i].pid, + .tid = fake_mmap_info[i].pid, + .start = fake_mmap_info[i].start, + .len = 0x1000ULL, + .pgoff = 0ULL, + }, + }; + + strcpy(fake_mmap_event.mmap.filename, + fake_mmap_info[i].filename); + + machine__process_mmap_event(machine, &fake_mmap_event, NULL); + } + + for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) { + size_t k; + struct dso *dso; + + dso = __dsos__findnew(&machine->user_dsos, + fake_symbols[i].dso_name); + if (dso == NULL) + goto out; + + /* emulate dso__load()