diff options
| author | Namhyung Kim <namhyung@kernel.org> | 2014-04-24 23:28:13 -0400 |
|---|---|---|
| committer | Jiri Olsa <jolsa@kernel.org> | 2014-04-28 07:42:29 -0400 |
| commit | 6e344a952dcfa45b8bfef8eaf8423ab73c5adaf2 (patch) | |
| tree | af0200fd0df2a89def1a0a87a1c39309edfe430e /tools | |
| parent | 2933d7813d8618f18632a7dc7f4e7f1f7d17383a (diff) | |
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 <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1398396494-12811-1-git-send-email-namhyung@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/Makefile.perf | 1 | ||||
| -rw-r--r-- | tools/perf/tests/hists_common.c | 148 | ||||
| -rw-r--r-- | tools/perf/tests/hists_common.h | 44 | ||||
| -rw-r--r-- | tools/perf/tests/hists_link.c | 141 |
4 files changed, 195 insertions, 139 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index e96923310d57..a4aad7844b2b 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
| @@ -397,6 +397,7 @@ LIB_OBJS += $(OUTPUT)tests/rdpmc.o | |||
| 397 | LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o | 397 | LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o |
| 398 | LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o | 398 | LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o |
| 399 | LIB_OBJS += $(OUTPUT)tests/pmu.o | 399 | LIB_OBJS += $(OUTPUT)tests/pmu.o |
| 400 | LIB_OBJS += $(OUTPUT)tests/hists_common.o | ||
| 400 | LIB_OBJS += $(OUTPUT)tests/hists_link.o | 401 | LIB_OBJS += $(OUTPUT)tests/hists_link.o |
| 401 | LIB_OBJS += $(OUTPUT)tests/python-use.o | 402 | LIB_OBJS += $(OUTPUT)tests/python-use.o |
| 402 | LIB_OBJS += $(OUTPUT)tests/bp_signal.o | 403 | 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 000000000000..44655b395bb9 --- /dev/null +++ b/tools/perf/tests/hists_common.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | #include "perf.h" | ||
| 2 | #include "util/debug.h" | ||
| 3 | #include "util/symbol.h" | ||
| 4 | #include "util/sort.h" | ||
| 5 | #include "util/evsel.h" | ||
| 6 | #include "util/evlist.h" | ||
| 7 | #include "util/machine.h" | ||
| 8 | #include "util/thread.h" | ||
| 9 | #include "tests/hists_common.h" | ||
| 10 | |||
| 11 | static struct { | ||
| 12 | u32 pid; | ||
| 13 | const char *comm; | ||
| 14 | } fake_threads[] = { | ||
| 15 | { 100, "perf" }, | ||
| 16 | { 200, "perf" }, | ||
| 17 | { 300, "bash" }, | ||
| 18 | }; | ||
| 19 | |||
| 20 | static struct { | ||
| 21 | u32 pid; | ||
| 22 | u64 start; | ||
| 23 | const char *filename; | ||
| 24 | } fake_mmap_info[] = { | ||
| 25 | { 100, 0x40000, "perf" }, | ||
| 26 | { 100, 0x50000, "libc" }, | ||
| 27 | { 100, 0xf0000, "[kernel]" }, | ||
| 28 | { 200, 0x40000, "perf" }, | ||
| 29 | { 200, 0x50000, "libc" }, | ||
| 30 | { 200, 0xf0000, "[kernel]" }, | ||
| 31 | { 300, 0x40000, "bash" }, | ||
| 32 | { 300, 0x50000, "libc" }, | ||
| 33 | { 300, 0xf0000, "[kernel]" }, | ||
| 34 | }; | ||
| 35 | |||
| 36 | struct fake_sym { | ||
| 37 | u64 start; | ||
| 38 | u64 length; | ||
| 39 | const char *name; | ||
| 40 | }; | ||
| 41 | |||
| 42 | static struct fake_sym perf_syms[] = { | ||
| 43 | { 700, 100, "main" }, | ||
| 44 | { 800, 100, "run_command" }, | ||
| 45 | { 900, 100, "cmd_record" }, | ||
| 46 | }; | ||
| 47 | |||
| 48 | static struct fake_sym bash_syms[] = { | ||
| 49 | { 700, 100, "main" }, | ||
| 50 | { 800, 100, "xmalloc" }, | ||
| 51 | { 900, 100, "xfree" }, | ||
| 52 | }; | ||
| 53 | |||
| 54 | static struct fake_sym libc_syms[] = { | ||
| 55 | { 700, 100, "malloc" }, | ||
| 56 | { 800, 100, "free" }, | ||
| 57 | { 900, 100, "realloc" }, | ||
| 58 | }; | ||
| 59 | |||
| 60 | static struct fake_sym kernel_syms[] = { | ||
| 61 | { 700, 100, "schedule" }, | ||
| 62 | { 800, 100, "page_fault" }, | ||
| 63 | { 900, 100, "sys_perf_event_open" }, | ||
| 64 | }; | ||
| 65 | |||
| 66 | static struct { | ||
| 67 | const char *dso_name; | ||
| 68 | struct fake_sym *syms; | ||
| 69 | size_t nr_syms; | ||
| 70 | } fake_symbols[] = { | ||
| 71 | { "perf", perf_syms, ARRAY_SIZE(perf_syms) }, | ||
| 72 | { "bash", bash_syms, ARRAY_SIZE(bash_syms) }, | ||
| 73 | { "libc", libc_syms, ARRAY_SIZE(libc_syms) }, | ||
| 74 | { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) }, | ||
| 75 | }; | ||
| 76 | |||
| 77 | struct machine *setup_fake_machine(struct machines *machines) | ||
| 78 | { | ||
| 79 | struct machine *machine = machines__find(machines, HOST_KERNEL_ID); | ||
| 80 | size_t i; | ||
| 81 | |||
| 82 | if (machine == NULL) { | ||
| 83 | pr_debug("Not enough memory for machine setup\n"); | ||
| 84 | return NULL; | ||
| 85 | } | ||
| 86 | |||
| 87 | for (i = 0; i < ARRAY_SIZE(fake_threads); i++) { | ||
| 88 | struct thread *thread; | ||
| 89 | |||
| 90 | thread = machine__findnew_thread(machine, fake_threads[i].pid, | ||
| 91 | fake_threads[i].pid); | ||
| 92 | if (thread == NULL) | ||
| 93 | goto out; | ||
| 94 | |||
| 95 | thread__set_comm(thread, fake_threads[i].comm, 0); | ||
| 96 | } | ||
| 97 | |||
| 98 | for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { | ||
| 99 | union perf_event fake_mmap_event = { | ||
| 100 | .mmap = { | ||
| 101 | .header = { .misc = PERF_RECORD_MISC_USER, }, | ||
| 102 | .pid = fake_mmap_info[i].pid, | ||
| 103 | .tid = fake_mmap_info[i].pid, | ||
| 104 | .start = fake_mmap_info[i].start, | ||
| 105 | .len = 0x1000ULL, | ||
| 106 | .pgoff = 0ULL, | ||
| 107 | }, | ||
| 108 | }; | ||
| 109 | |||
| 110 | strcpy(fake_mmap_event.mmap.filename, | ||
| 111 | fake_mmap_info[i].filename); | ||
| 112 | |||
| 113 | machine__process_mmap_event(machine, &fake_mmap_event, NULL); | ||
| 114 | } | ||
| 115 | |||
| 116 | for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) { | ||
| 117 | size_t k; | ||
| 118 | struct dso *dso; | ||
| 119 | |||
| 120 | dso = __dsos__findnew(&machine->user_dsos, | ||
| 121 | fake_symbols[i].dso_name); | ||
| 122 | if (dso == NULL) | ||
| 123 | goto out; | ||
| 124 | |||
| 125 | /* emulate dso__load() */ | ||
| 126 | dso__set_loaded(dso, MAP__FUNCTION); | ||
| 127 | |||
| 128 | for (k = 0; k < fake_symbols[i].nr_syms; k++) { | ||
| 129 | struct symbol *sym; | ||
| 130 | struct fake_sym *fsym = &fake_symbols[i].syms[k]; | ||
| 131 | |||
| 132 | sym = symbol__new(fsym->start, fsym->length, | ||
| 133 | STB_GLOBAL, fsym->name); | ||
| 134 | if (sym == NULL) | ||
| 135 | goto out; | ||
| 136 | |||
| 137 | symbols__insert(&dso->symbols[MAP__FUNCTION], sym); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | return machine; | ||
| 142 | |||
| 143 | out: | ||
| 144 | pr_debug("Not enough memory for machine setup\n"); | ||
| 145 | machine__delete_threads(machine); | ||
| 146 | machine__delete(machine); | ||
| 147 | return NULL; | ||
| 148 | } | ||
diff --git a/tools/perf/tests/hists_common.h b/tools/perf/tests/hists_common.h new file mode 100644 index 000000000000..2528b8fc105a --- /dev/null +++ b/tools/perf/tests/hists_common.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #ifndef __PERF_TESTS__HISTS_COMMON_H__ | ||
| 2 | #define __PERF_TESTS__HISTS_COMMON_H__ | ||
| 3 | |||
| 4 | struct machine; | ||
| 5 | struct machines; | ||
| 6 | |||
| 7 | /* | ||
| 8 | * The setup_fake_machine() provides a test environment which consists | ||
| 9 | * of 3 processes that have 3 mappings and in turn, have 3 symbols | ||
| 10 | * respectively. See below table: | ||
| 11 | * | ||
| 12 | * Command: Pid Shared Object Symbol | ||
| 13 | * ............. ............. ................... | ||
| 14 | * perf: 100 perf main | ||
| 15 | * perf: 100 perf run_command | ||
| 16 | * perf: 100 perf comd_record | ||
| 17 | * perf: 100 libc malloc | ||
| 18 | * perf: 100 libc free | ||
| 19 | * perf: 100 libc realloc | ||
| 20 | * perf: 100 [kernel] schedule | ||
| 21 | * perf: 100 [kernel] page_fault | ||
| 22 | * perf: 100 [kernel] sys_perf_event_open | ||
| 23 | * perf: 200 perf main | ||
| 24 | * perf: 200 perf run_command | ||
| 25 | * perf: 200 perf comd_record | ||
| 26 | * perf: 200 libc malloc | ||
| 27 | * perf: 200 libc free | ||
| 28 | * perf: 200 libc realloc | ||
| 29 | * perf: 200 [kernel] schedule | ||
| 30 | * perf: 200 [kernel] page_fault | ||
| 31 | * perf: 200 [kernel] sys_perf_event_open | ||
| 32 | * bash: 300 bash main | ||
| 33 | * bash: 300 bash xmalloc | ||
| 34 | * bash: 300 bash xfree | ||
| 35 | * bash: 300 libc malloc | ||
| 36 | * bash: 300 libc free | ||
| 37 | * bash: 300 libc realloc | ||
| 38 | * bash: 300 [kernel] schedule | ||
| 39 | * bash: 300 [kernel] page_fault | ||
| 40 | * bash: 300 [kernel] sys_perf_event_open | ||
| 41 | */ | ||
| 42 | struct machine *setup_fake_machine(struct machines *machines); | ||
| 43 | |||
| 44 | #endif /* __PERF_TESTS__HISTS_COMMON_H__ */ | ||
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 7ccbc7b6ae77..e42d6790811a 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c | |||
| @@ -8,145 +8,7 @@ | |||
| 8 | #include "machine.h" | 8 | #include "machine.h" |
| 9 | #include "thread.h" | 9 | #include "thread.h" |
| 10 | #include "parse-events.h" | 10 | #include "parse-events.h" |
| 11 | 11 | #include "hists_common.h" | |
| 12 | static struct { | ||
| 13 | u32 pid; | ||
| 14 | const char *comm; | ||
| 15 | } fake_threads[] = { | ||
| 16 | { 100, "perf" }, | ||
| 17 | { 200, "perf" }, | ||
| 18 | { 300, "bash" }, | ||
| 19 | }; | ||
| 20 | |||
| 21 | static struct { | ||
| 22 | u32 pid; | ||
| 23 | u64 start; | ||
| 24 | const char *filename; | ||
| 25 | } fake_mmap_info[] = { | ||
| 26 | { 100, 0x40000, "perf" }, | ||
| 27 | { 100, 0x50000, "libc" }, | ||
| 28 | { 100, 0xf0000, "[kernel]" }, | ||
| 29 | { 200, 0x40000, "perf" }, | ||
| 30 | { 200, 0x50000, "libc" }, | ||
| 31 | { 200, 0xf0000, "[kernel]" }, | ||
| 32 | { 300, 0x40000, "bash" }, | ||
| 33 | { 300, 0x50000, "libc" }, | ||
| 34 | { 300, 0xf0000, "[kernel]" }, | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct fake_sym { | ||
| 38 | u64 start; | ||
| 39 | u64 length; | ||
| 40 | const char *name; | ||
| 41 | }; | ||
| 42 | |||
| 43 | static struct fake_sym perf_syms[] = { | ||
| 44 | { 700, 100, "main" }, | ||
| 45 | { 800, 100, "run_command" }, | ||
| 46 | { 900, 100, "cmd_record" }, | ||
| 47 | }; | ||
| 48 | |||
| 49 | static struct fake_sym bash_syms[] = { | ||
| 50 | { 700, 100, "main" }, | ||
| 51 | { 800, 100, "xmalloc" }, | ||
| 52 | { 900, 100, "xfree" }, | ||
| 53 | }; | ||
| 54 | |||
| 55 | static struct fake_sym libc_syms[] = { | ||
| 56 | { 700, 100, "malloc" }, | ||
| 57 | { 800, 100, "free" }, | ||
| 58 | { 900, 100, "realloc" }, | ||
| 59 | }; | ||
| 60 | |||
| 61 | static struct fake_sym kernel_syms[] = { | ||
| 62 | { 700, 100, "schedule" }, | ||
| 63 | { 800, 100, "page_fault" }, | ||
| 64 | { 900, 100, "sys_perf_event_open" }, | ||
| 65 | }; | ||
| 66 | |||
| 67 | static struct { | ||
| 68 | const char *dso_name; | ||
| 69 | struct fake_sym *syms; | ||
| 70 | size_t nr_syms; | ||
| 71 | } fake_symbols[] = { | ||
| 72 | { "perf", perf_syms, ARRAY_SIZE(perf_syms) }, | ||
| 73 | { "bash", bash_syms, ARRAY_SIZE(bash_syms) }, | ||
| 74 | { "libc", libc_syms, ARRAY_SIZE(libc_syms) }, | ||
| 75 | { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) }, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static struct machine *setup_fake_machine(struct machines *machines) | ||
| 79 | { | ||
| 80 | struct machine *machine = machines__find(machines, HOST_KERNEL_ID); | ||
| 81 | size_t i; | ||
| 82 | |||
| 83 | if (machine == NULL) { | ||
| 84 | pr_debug("Not enough memory for machine setup\n"); | ||
| 85 | return NULL; | ||
| 86 | } | ||
| 87 | |||
| 88 | for (i = 0; i < ARRAY_SIZE(fake_threads); i++) { | ||
| 89 | struct thread *thread; | ||
| 90 | |||
| 91 | thread = machine__findnew_thread(machine, fake_threads[i].pid, | ||
| 92 | fake_threads[i].pid); | ||
| 93 | if (thread == NULL) | ||
| 94 | goto out; | ||
| 95 | |||
| 96 | thread__set_comm(thread, fake_threads[i].comm, 0); | ||
| 97 | } | ||
| 98 | |||
| 99 | for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { | ||
| 100 | union perf_event fake_mmap_event = { | ||
| 101 | .mmap = { | ||
| 102 | .header = { .misc = PERF_RECORD_MISC_USER, }, | ||
| 103 | .pid = fake_mmap_info[i].pid, | ||
| 104 | .tid = fake_mmap_info[i].pid, | ||
| 105 | .start = fake_mmap_info[i].start, | ||
| 106 | .len = 0x1000ULL, | ||
| 107 | .pgoff = 0ULL, | ||
| 108 | }, | ||
| 109 | }; | ||
| 110 | |||
| 111 | strcpy(fake_mmap_event.mmap.filename, | ||
| 112 | fake_mmap_info[i].filename); | ||
| 113 | |||
| 114 | machine__process_mmap_event(machine, &fake_mmap_event, NULL); | ||
| 115 | } | ||
| 116 | |||
| 117 | for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) { | ||
| 118 | size_t k; | ||
| 119 | struct dso *dso; | ||
| 120 | |||
| 121 | dso = __dsos__findnew(&machine->user_dsos, | ||
| 122 | fake_symbols[i].dso_name); | ||
| 123 | if (dso == NULL) | ||
| 124 | goto out; | ||
| 125 | |||
| 126 | /* emulate dso__load() */ | ||
| 127 | dso__set_loaded(dso, MAP__FUNCTION); | ||
| 128 | |||
| 129 | for (k = 0; k < fake_symbols[i].nr_syms; k++) { | ||
| 130 | struct symbol *sym; | ||
| 131 | struct fake_sym *fsym = &fake_symbols[i].syms[k]; | ||
| 132 | |||
| 133 | sym = symbol__new(fsym->start, fsym->length, | ||
| 134 | STB_GLOBAL, fsym->name); | ||
| 135 | if (sym == NULL) | ||
| 136 | goto out; | ||
| 137 | |||
| 138 | symbols__insert(&dso->symbols[MAP__FUNCTION], sym); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | return machine; | ||
| 143 | |||
| 144 | out: | ||
| 145 | pr_debug("Not enough memory for machine setup\n"); | ||
| 146 | machine__delete_threads(machine); | ||
| 147 | machine__delete(machine); | ||
| 148 | return NULL; | ||
| 149 | } | ||
| 150 | 12 | ||
| 151 | struct sample { | 13 | struct sample { |
| 152 | u32 pid; | 14 | u32 pid; |
| @@ -156,6 +18,7 @@ struct sample { | |||
| 156 | struct symbol *sym; | 18 | struct symbol *sym; |
| 157 | }; | 19 | }; |
| 158 | 20 | ||
| 21 | /* For the numbers, see hists_common.c */ | ||
| 159 | static struct sample fake_common_samples[] = { | 22 | static struct sample fake_common_samples[] = { |
| 160 | /* perf [kernel] schedule() */ | 23 | /* perf [kernel] schedule() */ |
| 161 | { .pid = 100, .ip = 0xf0000 + 700, }, | 24 | { .pid = 100, .ip = 0xf0000 + 700, }, |
