aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/machine.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-12-18 17:15:48 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:40:12 -0500
commit876650e6c3209861a8949111140d805b3440951f (patch)
tree92923adf71a21512f20889c49ace7ed42b139f29 /tools/perf/util/machine.c
parent28a6b6aa54878a6a239e901698b3fc111bbcc54f (diff)
perf machine: Introduce struct machines
That consolidates the grouping of host + guests, isolating a bit more of functionality now centered on 'perf_session' that can be used independently in tools that don't need a 'perf_session' instance, but needs to have all the thread/map/symbol machinery. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-c700rsiphpmzv8klogojpfut@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/machine.c')
-rw-r--r--tools/perf/util/machine.c64
1 files changed, 42 insertions, 22 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 71fa90391fe4..efdb38e65a92 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -91,10 +91,22 @@ void machine__delete(struct machine *machine)
91 free(machine); 91 free(machine);
92} 92}
93 93
94struct machine *machines__add(struct rb_root *machines, pid_t pid, 94void machines__init(struct machines *machines)
95{
96 machine__init(&machines->host, "", HOST_KERNEL_ID);
97 machines->guests = RB_ROOT;
98}
99
100void machines__exit(struct machines *machines)
101{
102 machine__exit(&machines->host);
103 /* XXX exit guest */
104}
105
106struct machine *machines__add(struct machines *machines, pid_t pid,
95 const char *root_dir) 107 const char *root_dir)
96{ 108{
97 struct rb_node **p = &machines->rb_node; 109 struct rb_node **p = &machines->guests.rb_node;
98 struct rb_node *parent = NULL; 110 struct rb_node *parent = NULL;
99 struct machine *pos, *machine = malloc(sizeof(*machine)); 111 struct machine *pos, *machine = malloc(sizeof(*machine));
100 112
@@ -116,18 +128,21 @@ struct machine *machines__add(struct rb_root *machines, pid_t pid,
116 } 128 }
117 129
118 rb_link_node(&machine->rb_node, parent, p); 130 rb_link_node(&machine->rb_node, parent, p);
119 rb_insert_color(&machine->rb_node, machines); 131 rb_insert_color(&machine->rb_node, &machines->guests);
120 132
121 return machine; 133 return machine;
122} 134}
123 135
124struct machine *machines__find(struct rb_root *machines, pid_t pid) 136struct machine *machines__find(struct machines *machines, pid_t pid)
125{ 137{
126 struct rb_node **p = &machines->rb_node; 138 struct rb_node **p = &machines->guests.rb_node;
127 struct rb_node *parent = NULL; 139 struct rb_node *parent = NULL;
128 struct machine *machine; 140 struct machine *machine;
129 struct machine *default_machine = NULL; 141 struct machine *default_machine = NULL;
130 142
143 if (pid == HOST_KERNEL_ID)
144 return &machines->host;
145
131 while (*p != NULL) { 146 while (*p != NULL) {
132 parent = *p; 147 parent = *p;
133 machine = rb_entry(parent, struct machine, rb_node); 148 machine = rb_entry(parent, struct machine, rb_node);
@@ -144,7 +159,7 @@ struct machine *machines__find(struct rb_root *machines, pid_t pid)
144 return default_machine; 159 return default_machine;
145} 160}
146 161
147struct machine *machines__findnew(struct rb_root *machines, pid_t pid) 162struct machine *machines__findnew(struct machines *machines, pid_t pid)
148{ 163{
149 char path[PATH_MAX]; 164 char path[PATH_MAX];
150 const char *root_dir = ""; 165 const char *root_dir = "";
@@ -178,12 +193,12 @@ out:
178 return machine; 193 return machine;
179} 194}
180 195
181void machines__process(struct rb_root *machines, 196void machines__process_guests(struct machines *machines,
182 machine__process_t process, void *data) 197 machine__process_t process, void *data)
183{ 198{
184 struct rb_node *nd; 199 struct rb_node *nd;
185 200
186 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 201 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
187 struct machine *pos = rb_entry(nd, struct machine, rb_node); 202 struct machine *pos = rb_entry(nd, struct machine, rb_node);
188 process(pos, data); 203 process(pos, data);
189 } 204 }
@@ -203,12 +218,14 @@ char *machine__mmap_name(struct machine *machine, char *bf, size_t size)
203 return bf; 218 return bf;
204} 219}
205 220
206void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size) 221void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size)
207{ 222{
208 struct rb_node *node; 223 struct rb_node *node;
209 struct machine *machine; 224 struct machine *machine;
210 225
211 for (node = rb_first(machines); node; node = rb_next(node)) { 226 machines->host.id_hdr_size = id_hdr_size;
227
228 for (node = rb_first(&machines->guests); node; node = rb_next(node)) {
212 machine = rb_entry(node, struct machine, rb_node); 229 machine = rb_entry(node, struct machine, rb_node);
213 machine->id_hdr_size = id_hdr_size; 230 machine->id_hdr_size = id_hdr_size;
214 } 231 }
@@ -313,12 +330,13 @@ struct map *machine__new_module(struct machine *machine, u64 start,
313 return map; 330 return map;
314} 331}
315 332
316size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp) 333size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
317{ 334{
318 struct rb_node *nd; 335 struct rb_node *nd;
319 size_t ret = 0; 336 size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) +
337 __dsos__fprintf(&machines->host.user_dsos, fp);
320 338
321 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 339 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
322 struct machine *pos = rb_entry(nd, struct machine, rb_node); 340 struct machine *pos = rb_entry(nd, struct machine, rb_node);
323 ret += __dsos__fprintf(&pos->kernel_dsos, fp); 341 ret += __dsos__fprintf(&pos->kernel_dsos, fp);
324 ret += __dsos__fprintf(&pos->user_dsos, fp); 342 ret += __dsos__fprintf(&pos->user_dsos, fp);
@@ -334,13 +352,13 @@ size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
334 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm); 352 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
335} 353}
336 354
337size_t machines__fprintf_dsos_buildid(struct rb_root *machines, FILE *fp, 355size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
338 bool (skip)(struct dso *dso, int parm), int parm) 356 bool (skip)(struct dso *dso, int parm), int parm)
339{ 357{
340 struct rb_node *nd; 358 struct rb_node *nd;
341 size_t ret = 0; 359 size_t ret = machine__fprintf_dsos_buildid(&machines->host, fp, skip, parm);
342 360
343 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 361 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
344 struct machine *pos = rb_entry(nd, struct machine, rb_node); 362 struct machine *pos = rb_entry(nd, struct machine, rb_node);
345 ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm); 363 ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm);
346 } 364 }
@@ -511,7 +529,7 @@ void machine__destroy_kernel_maps(struct machine *machine)
511 } 529 }
512} 530}
513 531
514int machines__create_guest_kernel_maps(struct rb_root *machines) 532int machines__create_guest_kernel_maps(struct machines *machines)
515{ 533{
516 int ret = 0; 534 int ret = 0;
517 struct dirent **namelist = NULL; 535 struct dirent **namelist = NULL;
@@ -560,20 +578,22 @@ failure:
560 return ret; 578 return ret;
561} 579}
562 580
563void machines__destroy_guest_kernel_maps(struct rb_root *machines) 581void machines__destroy_kernel_maps(struct machines *machines)
564{ 582{
565 struct rb_node *next = rb_first(machines); 583 struct rb_node *next = rb_first(&machines->guests);
584
585 machine__destroy_kernel_maps(&machines->host);
566 586
567 while (next) { 587 while (next) {
568 struct machine *pos = rb_entry(next, struct machine, rb_node); 588 struct machine *pos = rb_entry(next, struct machine, rb_node);
569 589
570 next = rb_next(&pos->rb_node); 590 next = rb_next(&pos->rb_node);
571 rb_erase(&pos->rb_node, machines); 591 rb_erase(&pos->rb_node, &machines->guests);
572 machine__delete(pos); 592 machine__delete(pos);
573 } 593 }
574} 594}
575 595
576int machines__create_kernel_maps(struct rb_root *machines, pid_t pid) 596int machines__create_kernel_maps(struct machines *machines, pid_t pid)
577{ 597{
578 struct machine *machine = machines__findnew(machines, pid); 598 struct machine *machine = machines__findnew(machines, pid);
579 599