2 #include "util/debug.h"
3 #include "util/symbol.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"
15 { FAKE_PID_PERF1
, "perf" },
16 { FAKE_PID_PERF2
, "perf" },
17 { FAKE_PID_BASH
, "bash" },
24 } fake_mmap_info
[] = {
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]" },
42 static struct fake_sym perf_syms
[] = {
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" },
48 static struct fake_sym bash_syms
[] = {
49 { FAKE_SYM_OFFSET1
, FAKE_SYM_LENGTH
, "main" },
50 { FAKE_SYM_OFFSET2
, FAKE_SYM_LENGTH
, "xmalloc" },
51 { FAKE_SYM_OFFSET3
, FAKE_SYM_LENGTH
, "xfree" },
54 static struct fake_sym libc_syms
[] = {
55 { 700, 100, "malloc" },
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" },
63 static struct fake_sym kernel_syms
[] = {
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" },
71 struct fake_sym
*syms
;
74 { "perf", perf_syms
, ARRAY_SIZE(perf_syms
) },
75 { "bash", bash_syms
, ARRAY_SIZE(bash_syms
) },
76 { "libc", libc_syms
, ARRAY_SIZE(libc_syms
) },
77 { "[kernel]", kernel_syms
, ARRAY_SIZE(kernel_syms
) },
80 struct machine
*setup_fake_machine(struct machines
*machines
)
82 struct machine
*machine
= machines__find(machines
, HOST_KERNEL_ID
);
85 if (machine
== NULL
) {
86 pr_debug("Not enough memory for machine setup\n");
90 for (i
= 0; i
< ARRAY_SIZE(fake_threads
); i
++) {
91 struct thread
*thread
;
93 thread
= machine__findnew_thread(machine
, fake_threads
[i
].pid
,
98 thread__set_comm(thread
, fake_threads
[i
].comm
, 0);
101 for (i
= 0; i
< ARRAY_SIZE(fake_mmap_info
); i
++) {
102 union perf_event fake_mmap_event
= {
104 .header
= { .misc
= PERF_RECORD_MISC_USER
, },
105 .pid
= fake_mmap_info
[i
].pid
,
106 .tid
= fake_mmap_info
[i
].pid
,
107 .start
= fake_mmap_info
[i
].start
,
108 .len
= FAKE_MAP_LENGTH
,
113 strcpy(fake_mmap_event
.mmap
.filename
,
114 fake_mmap_info
[i
].filename
);
116 machine__process_mmap_event(machine
, &fake_mmap_event
, NULL
);
119 for (i
= 0; i
< ARRAY_SIZE(fake_symbols
); i
++) {
123 dso
= __dsos__findnew(&machine
->user_dsos
,
124 fake_symbols
[i
].dso_name
);
128 /* emulate dso__load() */
129 dso__set_loaded(dso
, MAP__FUNCTION
);
131 for (k
= 0; k
< fake_symbols
[i
].nr_syms
; k
++) {
133 struct fake_sym
*fsym
= &fake_symbols
[i
].syms
[k
];
135 sym
= symbol__new(fsym
->start
, fsym
->length
,
136 STB_GLOBAL
, fsym
->name
);
140 symbols__insert(&dso
->symbols
[MAP__FUNCTION
], sym
);
147 pr_debug("Not enough memory for machine setup\n");
148 machine__delete_threads(machine
);
149 machine__delete(machine
);
153 void print_hists_in(struct hists
*hists
)
156 struct rb_root
*root
;
157 struct rb_node
*node
;
159 if (sort__need_collapse
)
160 root
= &hists
->entries_collapsed
;
162 root
= hists
->entries_in
;
164 pr_info("----- %s --------\n", __func__
);
165 node
= rb_first(root
);
167 struct hist_entry
*he
;
169 he
= rb_entry(node
, struct hist_entry
, rb_node_in
);
172 pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64
"\n",
173 i
, thread__comm_str(he
->thread
),
174 he
->ms
.map
->dso
->short_name
,
175 he
->ms
.sym
->name
, he
->stat
.period
);
179 node
= rb_next(node
);
183 void print_hists_out(struct hists
*hists
)
186 struct rb_root
*root
;
187 struct rb_node
*node
;
189 root
= &hists
->entries
;
191 pr_info("----- %s --------\n", __func__
);
192 node
= rb_first(root
);
194 struct hist_entry
*he
;
196 he
= rb_entry(node
, struct hist_entry
, rb_node
);
199 pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64
"/%"PRIu64
"\n",
200 i
, thread__comm_str(he
->thread
), he
->thread
->tid
,
201 he
->ms
.map
->dso
->short_name
,
202 he
->ms
.sym
->name
, he
->stat
.period
,
203 he
->stat_acc
? he
->stat_acc
->period
: 0);
207 node
= rb_next(node
);