Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tests: Define and use symbolic names for fake symbols

In various histogram test cases, fake symbols are used as raw numbers.
Define macros for each pid, map, symbols so that it can increase
readability somewhat.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Arun Sharma <asharma@fb.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/1401335910-16832-27-git-send-email-namhyung@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>

authored by

Namhyung Kim and committed by
Jiri Olsa
a1891aa4 d69b2962

+92 -62
+25 -22
tools/perf/tests/hists_common.c
··· 12 12 u32 pid; 13 13 const char *comm; 14 14 } fake_threads[] = { 15 - { 100, "perf" }, 16 - { 200, "perf" }, 17 - { 300, "bash" }, 15 + { FAKE_PID_PERF1, "perf" }, 16 + { FAKE_PID_PERF2, "perf" }, 17 + { FAKE_PID_BASH, "bash" }, 18 18 }; 19 19 20 20 static struct { ··· 22 22 u64 start; 23 23 const char *filename; 24 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]" }, 25 + { FAKE_PID_PERF1, FAKE_MAP_PERF, "perf" }, 26 + { FAKE_PID_PERF1, FAKE_MAP_LIBC, "libc" }, 27 + { FAKE_PID_PERF1, FAKE_MAP_KERNEL, "[kernel]" }, 28 + { FAKE_PID_PERF2, FAKE_MAP_PERF, "perf" }, 29 + { FAKE_PID_PERF2, FAKE_MAP_LIBC, "libc" }, 30 + { FAKE_PID_PERF2, FAKE_MAP_KERNEL, "[kernel]" }, 31 + { FAKE_PID_BASH, FAKE_MAP_BASH, "bash" }, 32 + { FAKE_PID_BASH, FAKE_MAP_LIBC, "libc" }, 33 + { FAKE_PID_BASH, FAKE_MAP_KERNEL, "[kernel]" }, 34 34 }; 35 35 36 36 struct fake_sym { ··· 40 40 }; 41 41 42 42 static struct fake_sym perf_syms[] = { 43 - { 700, 100, "main" }, 44 - { 800, 100, "run_command" }, 45 - { 900, 100, "cmd_record" }, 43 + { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "main" }, 44 + { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "run_command" }, 45 + { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "cmd_record" }, 46 46 }; 47 47 48 48 static struct fake_sym bash_syms[] = { 49 - { 700, 100, "main" }, 50 - { 800, 100, "xmalloc" }, 51 - { 900, 100, "xfree" }, 49 + { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "main" }, 50 + { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "xmalloc" }, 51 + { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "xfree" }, 52 52 }; 53 53 54 54 static struct fake_sym libc_syms[] = { 55 55 { 700, 100, "malloc" }, 56 56 { 800, 100, "free" }, 57 57 { 900, 100, "realloc" }, 58 + { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "malloc" }, 59 + { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "free" }, 60 + { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "realloc" }, 58 61 }; 59 62 60 63 static struct fake_sym kernel_syms[] = { 61 - { 700, 100, "schedule" }, 62 - { 800, 100, "page_fault" }, 63 - { 900, 100, "sys_perf_event_open" }, 64 + { FAKE_SYM_OFFSET1, FAKE_SYM_LENGTH, "schedule" }, 65 + { FAKE_SYM_OFFSET2, FAKE_SYM_LENGTH, "page_fault" }, 66 + { FAKE_SYM_OFFSET3, FAKE_SYM_LENGTH, "sys_perf_event_open" }, 64 67 }; 65 68 66 69 static struct { ··· 105 102 .pid = fake_mmap_info[i].pid, 106 103 .tid = fake_mmap_info[i].pid, 107 104 .start = fake_mmap_info[i].start, 108 - .len = 0x1000ULL, 105 + .len = FAKE_MAP_LENGTH, 109 106 .pgoff = 0ULL, 110 107 }, 111 108 };
+30 -2
tools/perf/tests/hists_common.h
··· 4 4 struct machine; 5 5 struct machines; 6 6 7 + #define FAKE_PID_PERF1 100 8 + #define FAKE_PID_PERF2 200 9 + #define FAKE_PID_BASH 300 10 + 11 + #define FAKE_MAP_PERF 0x400000 12 + #define FAKE_MAP_BASH 0x400000 13 + #define FAKE_MAP_LIBC 0x500000 14 + #define FAKE_MAP_KERNEL 0xf00000 15 + #define FAKE_MAP_LENGTH 0x100000 16 + 17 + #define FAKE_SYM_OFFSET1 700 18 + #define FAKE_SYM_OFFSET2 800 19 + #define FAKE_SYM_OFFSET3 900 20 + #define FAKE_SYM_LENGTH 100 21 + 22 + #define FAKE_IP_PERF_MAIN FAKE_MAP_PERF + FAKE_SYM_OFFSET1 23 + #define FAKE_IP_PERF_RUN_COMMAND FAKE_MAP_PERF + FAKE_SYM_OFFSET2 24 + #define FAKE_IP_PERF_CMD_RECORD FAKE_MAP_PERF + FAKE_SYM_OFFSET3 25 + #define FAKE_IP_BASH_MAIN FAKE_MAP_BASH + FAKE_SYM_OFFSET1 26 + #define FAKE_IP_BASH_XMALLOC FAKE_MAP_BASH + FAKE_SYM_OFFSET2 27 + #define FAKE_IP_BASH_XFREE FAKE_MAP_BASH + FAKE_SYM_OFFSET3 28 + #define FAKE_IP_LIBC_MALLOC FAKE_MAP_LIBC + FAKE_SYM_OFFSET1 29 + #define FAKE_IP_LIBC_FREE FAKE_MAP_LIBC + FAKE_SYM_OFFSET2 30 + #define FAKE_IP_LIBC_REALLOC FAKE_MAP_LIBC + FAKE_SYM_OFFSET3 31 + #define FAKE_IP_KERNEL_SCHEDULE FAKE_MAP_KERNEL + FAKE_SYM_OFFSET1 32 + #define FAKE_IP_KERNEL_PAGE_FAULT FAKE_MAP_KERNEL + FAKE_SYM_OFFSET2 33 + #define FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN FAKE_MAP_KERNEL + FAKE_SYM_OFFSET3 34 + 7 35 /* 8 36 * The setup_fake_machine() provides a test environment which consists 9 37 * of 3 processes that have 3 mappings and in turn, have 3 symbols ··· 41 13 * ............. ............. ................... 42 14 * perf: 100 perf main 43 15 * perf: 100 perf run_command 44 - * perf: 100 perf comd_record 16 + * perf: 100 perf cmd_record 45 17 * perf: 100 libc malloc 46 18 * perf: 100 libc free 47 19 * perf: 100 libc realloc ··· 50 22 * perf: 100 [kernel] sys_perf_event_open 51 23 * perf: 200 perf main 52 24 * perf: 200 perf run_command 53 - * perf: 200 perf comd_record 25 + * perf: 200 perf cmd_record 54 26 * perf: 200 libc malloc 55 27 * perf: 200 libc free 56 28 * perf: 200 libc realloc
+11 -12
tools/perf/tests/hists_filter.c
··· 21 21 /* For the numbers, see hists_common.c */ 22 22 static struct sample fake_samples[] = { 23 23 /* perf [kernel] schedule() */ 24 - { .pid = 100, .ip = 0xf0000 + 700, }, 24 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, 25 25 /* perf [perf] main() */ 26 - { .pid = 100, .ip = 0x40000 + 700, }, 26 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, }, 27 27 /* perf [libc] malloc() */ 28 - { .pid = 100, .ip = 0x50000 + 700, }, 28 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, 29 29 /* perf [perf] main() */ 30 - { .pid = 200, .ip = 0x40000 + 700, }, /* will be merged */ 30 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, /* will be merged */ 31 31 /* perf [perf] cmd_record() */ 32 - { .pid = 200, .ip = 0x40000 + 900, }, 32 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, }, 33 33 /* perf [kernel] page_fault() */ 34 - { .pid = 200, .ip = 0xf0000 + 800, }, 34 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 35 35 /* bash [bash] main() */ 36 - { .pid = 300, .ip = 0x40000 + 700, }, 36 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, }, 37 37 /* bash [bash] xmalloc() */ 38 - { .pid = 300, .ip = 0x40000 + 800, }, 38 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, 39 39 /* bash [libc] malloc() */ 40 - { .pid = 300, .ip = 0x50000 + 700, }, 40 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, 41 41 /* bash [kernel] page_fault() */ 42 - { .pid = 300, .ip = 0xf0000 + 800, }, 42 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 43 43 }; 44 44 45 45 static int add_hist_entries(struct perf_evlist *evlist, ··· 47 47 { 48 48 struct perf_evsel *evsel; 49 49 struct addr_location al; 50 - struct perf_sample sample = { .cpu = 0, }; 50 + struct perf_sample sample = { .period = 100, }; 51 51 size_t i; 52 52 53 53 /* ··· 75 75 sample.pid = fake_samples[i].pid; 76 76 sample.tid = fake_samples[i].pid; 77 77 sample.ip = fake_samples[i].ip; 78 - sample.period = 100; 79 78 80 79 if (perf_event__preprocess_sample(&event, machine, &al, 81 80 &sample) < 0)
+16 -16
tools/perf/tests/hists_link.c
··· 21 21 /* For the numbers, see hists_common.c */ 22 22 static struct sample fake_common_samples[] = { 23 23 /* perf [kernel] schedule() */ 24 - { .pid = 100, .ip = 0xf0000 + 700, }, 24 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, 25 25 /* perf [perf] main() */ 26 - { .pid = 200, .ip = 0x40000 + 700, }, 26 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, 27 27 /* perf [perf] cmd_record() */ 28 - { .pid = 200, .ip = 0x40000 + 900, }, 28 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, }, 29 29 /* bash [bash] xmalloc() */ 30 - { .pid = 300, .ip = 0x40000 + 800, }, 30 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, 31 31 /* bash [libc] malloc() */ 32 - { .pid = 300, .ip = 0x50000 + 700, }, 32 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, 33 33 }; 34 34 35 35 static struct sample fake_samples[][5] = { 36 36 { 37 37 /* perf [perf] run_command() */ 38 - { .pid = 100, .ip = 0x40000 + 800, }, 38 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_RUN_COMMAND, }, 39 39 /* perf [libc] malloc() */ 40 - { .pid = 100, .ip = 0x50000 + 700, }, 40 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, 41 41 /* perf [kernel] page_fault() */ 42 - { .pid = 100, .ip = 0xf0000 + 800, }, 42 + { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 43 43 /* perf [kernel] sys_perf_event_open() */ 44 - { .pid = 200, .ip = 0xf0000 + 900, }, 44 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN, }, 45 45 /* bash [libc] free() */ 46 - { .pid = 300, .ip = 0x50000 + 800, }, 46 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_FREE, }, 47 47 }, 48 48 { 49 49 /* perf [libc] free() */ 50 - { .pid = 200, .ip = 0x50000 + 800, }, 50 + { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_LIBC_FREE, }, 51 51 /* bash [libc] malloc() */ 52 - { .pid = 300, .ip = 0x50000 + 700, }, /* will be merged */ 52 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, }, /* will be merged */ 53 53 /* bash [bash] xfee() */ 54 - { .pid = 300, .ip = 0x40000 + 900, }, 54 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XFREE, }, 55 55 /* bash [libc] realloc() */ 56 - { .pid = 300, .ip = 0x50000 + 900, }, 56 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_REALLOC, }, 57 57 /* bash [kernel] page_fault() */ 58 - { .pid = 300, .ip = 0xf0000 + 800, }, 58 + { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 59 59 }, 60 60 }; 61 61 ··· 64 64 struct perf_evsel *evsel; 65 65 struct addr_location al; 66 66 struct hist_entry *he; 67 - struct perf_sample sample = { .cpu = 0, }; 67 + struct perf_sample sample = { .period = 1, }; 68 68 size_t i = 0, k; 69 69 70 70 /*
+10 -10
tools/perf/tests/hists_output.c
··· 22 22 /* For the numbers, see hists_common.c */ 23 23 static struct sample fake_samples[] = { 24 24 /* perf [kernel] schedule() */ 25 - { .cpu = 0, .pid = 100, .ip = 0xf0000 + 700, }, 25 + { .cpu = 0, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, }, 26 26 /* perf [perf] main() */ 27 - { .cpu = 1, .pid = 100, .ip = 0x40000 + 700, }, 27 + { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, }, 28 28 /* perf [perf] cmd_record() */ 29 - { .cpu = 1, .pid = 100, .ip = 0x40000 + 900, }, 29 + { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, }, 30 30 /* perf [libc] malloc() */ 31 - { .cpu = 1, .pid = 100, .ip = 0x50000 + 700, }, 31 + { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, }, 32 32 /* perf [libc] free() */ 33 - { .cpu = 2, .pid = 100, .ip = 0x50000 + 800, }, 33 + { .cpu = 2, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, }, 34 34 /* perf [perf] main() */ 35 - { .cpu = 2, .pid = 200, .ip = 0x40000 + 700, }, 35 + { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, 36 36 /* perf [kernel] page_fault() */ 37 - { .cpu = 2, .pid = 200, .ip = 0xf0000 + 800, }, 37 + { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 38 38 /* bash [bash] main() */ 39 - { .cpu = 3, .pid = 300, .ip = 0x40000 + 700, }, 39 + { .cpu = 3, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, }, 40 40 /* bash [bash] xmalloc() */ 41 - { .cpu = 0, .pid = 300, .ip = 0x40000 + 800, }, 41 + { .cpu = 0, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, }, 42 42 /* bash [kernel] page_fault() */ 43 - { .cpu = 1, .pid = 300, .ip = 0xf0000 + 800, }, 43 + { .cpu = 1, .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, }, 44 44 }; 45 45 46 46 static int add_hist_entries(struct hists *hists, struct machine *machine)