3 #include "util/debug.h"
4 #include "util/symbol.h"
6 #include "util/evsel.h"
7 #include "util/evlist.h"
8 #include "util/machine.h"
9 #include "util/thread.h"
10 #include "tests/hists_common.h"
11 #include <linux/kernel.h>
17 { FAKE_PID_PERF1
, "perf" },
18 { FAKE_PID_PERF2
, "perf" },
19 { FAKE_PID_BASH
, "bash" },
26 } fake_mmap_info
[] = {
27 { FAKE_PID_PERF1
, FAKE_MAP_PERF
, "perf" },
28 { FAKE_PID_PERF1
, FAKE_MAP_LIBC
, "libc" },
29 { FAKE_PID_PERF1
, FAKE_MAP_KERNEL
, "[kernel]" },
30 { FAKE_PID_PERF2
, FAKE_MAP_PERF
, "perf" },
31 { FAKE_PID_PERF2
, FAKE_MAP_LIBC
, "libc" },
32 { FAKE_PID_PERF2
, FAKE_MAP_KERNEL
, "[kernel]" },
33 { FAKE_PID_BASH
, FAKE_MAP_BASH
, "bash" },
34 { FAKE_PID_BASH
, FAKE_MAP_LIBC
, "libc" },
35 { FAKE_PID_BASH
, FAKE_MAP_KERNEL
, "[kernel]" },
44 static struct fake_sym perf_syms
[] = {
45 { FAKE_SYM_OFFSET1
, FAKE_SYM_LENGTH
, "main" },
46 { FAKE_SYM_OFFSET2
, FAKE_SYM_LENGTH
, "run_command" },
47 { FAKE_SYM_OFFSET3
, FAKE_SYM_LENGTH
, "cmd_record" },
50 static struct fake_sym bash_syms
[] = {
51 { FAKE_SYM_OFFSET1
, FAKE_SYM_LENGTH
, "main" },
52 { FAKE_SYM_OFFSET2
, FAKE_SYM_LENGTH
, "xmalloc" },
53 { FAKE_SYM_OFFSET3
, FAKE_SYM_LENGTH
, "xfree" },
56 static struct fake_sym libc_syms
[] = {
57 { 700, 100, "malloc" },
59 { 900, 100, "realloc" },
60 { FAKE_SYM_OFFSET1
, FAKE_SYM_LENGTH
, "malloc" },
61 { FAKE_SYM_OFFSET2
, FAKE_SYM_LENGTH
, "free" },
62 { FAKE_SYM_OFFSET3
, FAKE_SYM_LENGTH
, "realloc" },
65 static struct fake_sym kernel_syms
[] = {
66 { FAKE_SYM_OFFSET1
, FAKE_SYM_LENGTH
, "schedule" },
67 { FAKE_SYM_OFFSET2
, FAKE_SYM_LENGTH
, "page_fault" },
68 { FAKE_SYM_OFFSET3
, FAKE_SYM_LENGTH
, "sys_perf_event_open" },
73 struct fake_sym
*syms
;
76 { "perf", perf_syms
, ARRAY_SIZE(perf_syms
) },
77 { "bash", bash_syms
, ARRAY_SIZE(bash_syms
) },
78 { "libc", libc_syms
, ARRAY_SIZE(libc_syms
) },
79 { "[kernel]", kernel_syms
, ARRAY_SIZE(kernel_syms
) },
82 struct machine
*setup_fake_machine(struct machines
*machines
)
84 struct machine
*machine
= machines__find(machines
, HOST_KERNEL_ID
);
87 if (machine
== NULL
) {
88 pr_debug("Not enough memory for machine setup\n");
92 for (i
= 0; i
< ARRAY_SIZE(fake_threads
); i
++) {
93 struct thread
*thread
;
95 thread
= machine__findnew_thread(machine
, fake_threads
[i
].pid
,
100 thread__set_comm(thread
, fake_threads
[i
].comm
, 0);
104 for (i
= 0; i
< ARRAY_SIZE(fake_mmap_info
); i
++) {
105 struct perf_sample sample
= {
106 .cpumode
= PERF_RECORD_MISC_USER
,
108 union perf_event fake_mmap_event
= {
110 .pid
= fake_mmap_info
[i
].pid
,
111 .tid
= fake_mmap_info
[i
].pid
,
112 .start
= fake_mmap_info
[i
].start
,
113 .len
= FAKE_MAP_LENGTH
,
118 strcpy(fake_mmap_event
.mmap
.filename
,
119 fake_mmap_info
[i
].filename
);
121 machine__process_mmap_event(machine
, &fake_mmap_event
, &sample
);
124 for (i
= 0; i
< ARRAY_SIZE(fake_symbols
); i
++) {
128 dso
= machine__findnew_dso(machine
, fake_symbols
[i
].dso_name
);
132 /* emulate dso__load() */
133 dso__set_loaded(dso
, MAP__FUNCTION
);
135 for (k
= 0; k
< fake_symbols
[i
].nr_syms
; k
++) {
137 struct fake_sym
*fsym
= &fake_symbols
[i
].syms
[k
];
139 sym
= symbol__new(fsym
->start
, fsym
->length
,
140 STB_GLOBAL
, fsym
->name
);
146 symbols__insert(&dso
->symbols
[MAP__FUNCTION
], sym
);
155 pr_debug("Not enough memory for machine setup\n");
156 machine__delete_threads(machine
);
160 void print_hists_in(struct hists
*hists
)
163 struct rb_root
*root
;
164 struct rb_node
*node
;
166 if (hists__has(hists
, need_collapse
))
167 root
= &hists
->entries_collapsed
;
169 root
= hists
->entries_in
;
171 pr_info("----- %s --------\n", __func__
);
172 node
= rb_first(root
);
174 struct hist_entry
*he
;
176 he
= rb_entry(node
, struct hist_entry
, rb_node_in
);
179 pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64
"\n",
180 i
, thread__comm_str(he
->thread
),
181 he
->ms
.map
->dso
->short_name
,
182 he
->ms
.sym
->name
, he
->stat
.period
);
186 node
= rb_next(node
);
190 void print_hists_out(struct hists
*hists
)
193 struct rb_root
*root
;
194 struct rb_node
*node
;
196 root
= &hists
->entries
;
198 pr_info("----- %s --------\n", __func__
);
199 node
= rb_first(root
);
201 struct hist_entry
*he
;
203 he
= rb_entry(node
, struct hist_entry
, rb_node
);
206 pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64
"/%"PRIu64
"\n",
207 i
, thread__comm_str(he
->thread
), he
->thread
->tid
,
208 he
->ms
.map
->dso
->short_name
,
209 he
->ms
.sym
->name
, he
->stat
.period
,
210 he
->stat_acc
? he
->stat_acc
->period
: 0);
214 node
= rb_next(node
);