| .. | .. |
|---|
| 8 | 8 | #include <stdio.h> |
|---|
| 9 | 9 | #include <string.h> |
|---|
| 10 | 10 | #include <sys/param.h> |
|---|
| 11 | +#include <perf/cpumap.h> |
|---|
| 12 | +#include <perf/evlist.h> |
|---|
| 13 | +#include <perf/mmap.h> |
|---|
| 11 | 14 | |
|---|
| 15 | +#include "debug.h" |
|---|
| 16 | +#include "dso.h" |
|---|
| 17 | +#include "env.h" |
|---|
| 12 | 18 | #include "parse-events.h" |
|---|
| 19 | +#include "trace-event.h" |
|---|
| 13 | 20 | #include "evlist.h" |
|---|
| 14 | 21 | #include "evsel.h" |
|---|
| 15 | 22 | #include "thread_map.h" |
|---|
| 16 | | -#include "cpumap.h" |
|---|
| 17 | 23 | #include "machine.h" |
|---|
| 24 | +#include "map.h" |
|---|
| 25 | +#include "symbol.h" |
|---|
| 18 | 26 | #include "event.h" |
|---|
| 27 | +#include "record.h" |
|---|
| 28 | +#include "util/mmap.h" |
|---|
| 29 | +#include "util/synthetic-events.h" |
|---|
| 19 | 30 | #include "thread.h" |
|---|
| 20 | 31 | |
|---|
| 21 | 32 | #include "tests.h" |
|---|
| 22 | 33 | |
|---|
| 23 | | -#include "sane_ctype.h" |
|---|
| 34 | +#include <linux/ctype.h> |
|---|
| 24 | 35 | |
|---|
| 25 | 36 | #define BUFSZ 1024 |
|---|
| 26 | 37 | #define READLEN 128 |
|---|
| .. | .. |
|---|
| 265 | 276 | len = al.map->end - addr; |
|---|
| 266 | 277 | |
|---|
| 267 | 278 | /* Read the object code using perf */ |
|---|
| 268 | | - ret_len = dso__data_read_offset(al.map->dso, thread->mg->machine, |
|---|
| 279 | + ret_len = dso__data_read_offset(al.map->dso, thread->maps->machine, |
|---|
| 269 | 280 | al.addr, buf1, len); |
|---|
| 270 | 281 | if (ret_len != len) { |
|---|
| 271 | 282 | pr_debug("dso__data_read_offset failed\n"); |
|---|
| .. | .. |
|---|
| 360 | 371 | } |
|---|
| 361 | 372 | |
|---|
| 362 | 373 | static int process_sample_event(struct machine *machine, |
|---|
| 363 | | - struct perf_evlist *evlist, |
|---|
| 374 | + struct evlist *evlist, |
|---|
| 364 | 375 | union perf_event *event, struct state *state) |
|---|
| 365 | 376 | { |
|---|
| 366 | 377 | struct perf_sample sample; |
|---|
| .. | .. |
|---|
| 383 | 394 | return ret; |
|---|
| 384 | 395 | } |
|---|
| 385 | 396 | |
|---|
| 386 | | -static int process_event(struct machine *machine, struct perf_evlist *evlist, |
|---|
| 397 | +static int process_event(struct machine *machine, struct evlist *evlist, |
|---|
| 387 | 398 | union perf_event *event, struct state *state) |
|---|
| 388 | 399 | { |
|---|
| 389 | 400 | if (event->header.type == PERF_RECORD_SAMPLE) |
|---|
| .. | .. |
|---|
| 406 | 417 | return 0; |
|---|
| 407 | 418 | } |
|---|
| 408 | 419 | |
|---|
| 409 | | -static int process_events(struct machine *machine, struct perf_evlist *evlist, |
|---|
| 420 | +static int process_events(struct machine *machine, struct evlist *evlist, |
|---|
| 410 | 421 | struct state *state) |
|---|
| 411 | 422 | { |
|---|
| 412 | 423 | union perf_event *event; |
|---|
| 413 | | - struct perf_mmap *md; |
|---|
| 424 | + struct mmap *md; |
|---|
| 414 | 425 | int i, ret; |
|---|
| 415 | 426 | |
|---|
| 416 | | - for (i = 0; i < evlist->nr_mmaps; i++) { |
|---|
| 427 | + for (i = 0; i < evlist->core.nr_mmaps; i++) { |
|---|
| 417 | 428 | md = &evlist->mmap[i]; |
|---|
| 418 | | - if (perf_mmap__read_init(md) < 0) |
|---|
| 429 | + if (perf_mmap__read_init(&md->core) < 0) |
|---|
| 419 | 430 | continue; |
|---|
| 420 | 431 | |
|---|
| 421 | | - while ((event = perf_mmap__read_event(md)) != NULL) { |
|---|
| 432 | + while ((event = perf_mmap__read_event(&md->core)) != NULL) { |
|---|
| 422 | 433 | ret = process_event(machine, evlist, event, state); |
|---|
| 423 | | - perf_mmap__consume(md); |
|---|
| 434 | + perf_mmap__consume(&md->core); |
|---|
| 424 | 435 | if (ret < 0) |
|---|
| 425 | 436 | return ret; |
|---|
| 426 | 437 | } |
|---|
| 427 | | - perf_mmap__read_done(md); |
|---|
| 438 | + perf_mmap__read_done(&md->core); |
|---|
| 428 | 439 | } |
|---|
| 429 | 440 | return 0; |
|---|
| 430 | 441 | } |
|---|
| .. | .. |
|---|
| 489 | 500 | } |
|---|
| 490 | 501 | } |
|---|
| 491 | 502 | |
|---|
| 503 | +#ifdef __s390x__ |
|---|
| 504 | +#include "header.h" // for get_cpuid() |
|---|
| 505 | +#endif |
|---|
| 506 | + |
|---|
| 492 | 507 | static const char *do_determine_event(bool excl_kernel) |
|---|
| 493 | 508 | { |
|---|
| 494 | 509 | const char *event = excl_kernel ? "cycles:u" : "cycles"; |
|---|
| .. | .. |
|---|
| 550 | 565 | struct state state = { |
|---|
| 551 | 566 | .done_cnt = 0, |
|---|
| 552 | 567 | }; |
|---|
| 553 | | - struct thread_map *threads = NULL; |
|---|
| 554 | | - struct cpu_map *cpus = NULL; |
|---|
| 555 | | - struct perf_evlist *evlist = NULL; |
|---|
| 556 | | - struct perf_evsel *evsel = NULL; |
|---|
| 568 | + struct perf_thread_map *threads = NULL; |
|---|
| 569 | + struct perf_cpu_map *cpus = NULL; |
|---|
| 570 | + struct evlist *evlist = NULL; |
|---|
| 571 | + struct evsel *evsel = NULL; |
|---|
| 557 | 572 | int err = -1, ret; |
|---|
| 558 | 573 | pid_t pid; |
|---|
| 559 | 574 | struct map *map; |
|---|
| .. | .. |
|---|
| 599 | 614 | } |
|---|
| 600 | 615 | |
|---|
| 601 | 616 | ret = perf_event__synthesize_thread_map(NULL, threads, |
|---|
| 602 | | - perf_event__process, machine, false, 500); |
|---|
| 617 | + perf_event__process, machine, false); |
|---|
| 603 | 618 | if (ret < 0) { |
|---|
| 604 | 619 | pr_debug("perf_event__synthesize_thread_map failed\n"); |
|---|
| 605 | 620 | goto out_err; |
|---|
| .. | .. |
|---|
| 611 | 626 | goto out_put; |
|---|
| 612 | 627 | } |
|---|
| 613 | 628 | |
|---|
| 614 | | - cpus = cpu_map__new(NULL); |
|---|
| 629 | + cpus = perf_cpu_map__new(NULL); |
|---|
| 615 | 630 | if (!cpus) { |
|---|
| 616 | | - pr_debug("cpu_map__new failed\n"); |
|---|
| 631 | + pr_debug("perf_cpu_map__new failed\n"); |
|---|
| 617 | 632 | goto out_put; |
|---|
| 618 | 633 | } |
|---|
| 619 | 634 | |
|---|
| 620 | 635 | while (1) { |
|---|
| 621 | 636 | const char *str; |
|---|
| 622 | 637 | |
|---|
| 623 | | - evlist = perf_evlist__new(); |
|---|
| 638 | + evlist = evlist__new(); |
|---|
| 624 | 639 | if (!evlist) { |
|---|
| 625 | 640 | pr_debug("perf_evlist__new failed\n"); |
|---|
| 626 | 641 | goto out_put; |
|---|
| 627 | 642 | } |
|---|
| 628 | 643 | |
|---|
| 629 | | - perf_evlist__set_maps(evlist, cpus, threads); |
|---|
| 644 | + perf_evlist__set_maps(&evlist->core, cpus, threads); |
|---|
| 630 | 645 | |
|---|
| 631 | 646 | str = do_determine_event(excl_kernel); |
|---|
| 632 | 647 | pr_debug("Parsing event '%s'\n", str); |
|---|
| .. | .. |
|---|
| 638 | 653 | |
|---|
| 639 | 654 | perf_evlist__config(evlist, &opts, NULL); |
|---|
| 640 | 655 | |
|---|
| 641 | | - evsel = perf_evlist__first(evlist); |
|---|
| 656 | + evsel = evlist__first(evlist); |
|---|
| 642 | 657 | |
|---|
| 643 | | - evsel->attr.comm = 1; |
|---|
| 644 | | - evsel->attr.disabled = 1; |
|---|
| 645 | | - evsel->attr.enable_on_exec = 0; |
|---|
| 658 | + evsel->core.attr.comm = 1; |
|---|
| 659 | + evsel->core.attr.disabled = 1; |
|---|
| 660 | + evsel->core.attr.enable_on_exec = 0; |
|---|
| 646 | 661 | |
|---|
| 647 | | - ret = perf_evlist__open(evlist); |
|---|
| 662 | + ret = evlist__open(evlist); |
|---|
| 648 | 663 | if (ret < 0) { |
|---|
| 649 | 664 | if (!excl_kernel) { |
|---|
| 650 | 665 | excl_kernel = true; |
|---|
| .. | .. |
|---|
| 653 | 668 | * and will be freed by following perf_evlist__set_maps |
|---|
| 654 | 669 | * call. Getting refference to keep them alive. |
|---|
| 655 | 670 | */ |
|---|
| 656 | | - cpu_map__get(cpus); |
|---|
| 657 | | - thread_map__get(threads); |
|---|
| 658 | | - perf_evlist__set_maps(evlist, NULL, NULL); |
|---|
| 659 | | - perf_evlist__delete(evlist); |
|---|
| 671 | + perf_cpu_map__get(cpus); |
|---|
| 672 | + perf_thread_map__get(threads); |
|---|
| 673 | + perf_evlist__set_maps(&evlist->core, NULL, NULL); |
|---|
| 674 | + evlist__delete(evlist); |
|---|
| 660 | 675 | evlist = NULL; |
|---|
| 661 | 676 | continue; |
|---|
| 662 | 677 | } |
|---|
| 663 | 678 | |
|---|
| 664 | 679 | if (verbose > 0) { |
|---|
| 665 | 680 | char errbuf[512]; |
|---|
| 666 | | - perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); |
|---|
| 681 | + evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); |
|---|
| 667 | 682 | pr_debug("perf_evlist__open() failed!\n%s\n", errbuf); |
|---|
| 668 | 683 | } |
|---|
| 669 | 684 | |
|---|
| .. | .. |
|---|
| 672 | 687 | break; |
|---|
| 673 | 688 | } |
|---|
| 674 | 689 | |
|---|
| 675 | | - ret = perf_evlist__mmap(evlist, UINT_MAX); |
|---|
| 690 | + ret = evlist__mmap(evlist, UINT_MAX); |
|---|
| 676 | 691 | if (ret < 0) { |
|---|
| 677 | | - pr_debug("perf_evlist__mmap failed\n"); |
|---|
| 692 | + pr_debug("evlist__mmap failed\n"); |
|---|
| 678 | 693 | goto out_put; |
|---|
| 679 | 694 | } |
|---|
| 680 | 695 | |
|---|
| 681 | | - perf_evlist__enable(evlist); |
|---|
| 696 | + evlist__enable(evlist); |
|---|
| 682 | 697 | |
|---|
| 683 | 698 | do_something(); |
|---|
| 684 | 699 | |
|---|
| 685 | | - perf_evlist__disable(evlist); |
|---|
| 700 | + evlist__disable(evlist); |
|---|
| 686 | 701 | |
|---|
| 687 | 702 | ret = process_events(machine, evlist, &state); |
|---|
| 688 | 703 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 701 | 716 | out_err: |
|---|
| 702 | 717 | |
|---|
| 703 | 718 | if (evlist) { |
|---|
| 704 | | - perf_evlist__delete(evlist); |
|---|
| 719 | + evlist__delete(evlist); |
|---|
| 705 | 720 | } else { |
|---|
| 706 | | - cpu_map__put(cpus); |
|---|
| 707 | | - thread_map__put(threads); |
|---|
| 721 | + perf_cpu_map__put(cpus); |
|---|
| 722 | + perf_thread_map__put(threads); |
|---|
| 708 | 723 | } |
|---|
| 709 | 724 | machine__delete_threads(machine); |
|---|
| 710 | 725 | machine__delete(machine); |
|---|