diff options
| -rw-r--r-- | tools/perf/Makefile | 2 | ||||
| -rw-r--r-- | tools/perf/builtin-annotate.c | 152 | ||||
| -rw-r--r-- | tools/perf/builtin-report.c | 164 | ||||
| -rw-r--r-- | tools/perf/util/hist.c | 164 | ||||
| -rw-r--r-- | tools/perf/util/hist.h | 47 |
5 files changed, 216 insertions, 313 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 0a9e5aede318..3a99a9fda645 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
| @@ -340,6 +340,7 @@ LIB_H += util/module.h | |||
| 340 | LIB_H += util/color.h | 340 | LIB_H += util/color.h |
| 341 | LIB_H += util/values.h | 341 | LIB_H += util/values.h |
| 342 | LIB_H += util/sort.h | 342 | LIB_H += util/sort.h |
| 343 | LIB_H += util/hist.h | ||
| 343 | 344 | ||
| 344 | LIB_OBJS += util/abspath.o | 345 | LIB_OBJS += util/abspath.o |
| 345 | LIB_OBJS += util/alias.o | 346 | LIB_OBJS += util/alias.o |
| @@ -376,6 +377,7 @@ LIB_OBJS += util/trace-event-read.o | |||
| 376 | LIB_OBJS += util/trace-event-info.o | 377 | LIB_OBJS += util/trace-event-info.o |
| 377 | LIB_OBJS += util/svghelper.o | 378 | LIB_OBJS += util/svghelper.o |
| 378 | LIB_OBJS += util/sort.o | 379 | LIB_OBJS += util/sort.o |
| 380 | LIB_OBJS += util/hist.o | ||
| 379 | 381 | ||
| 380 | BUILTIN_OBJS += builtin-annotate.o | 382 | BUILTIN_OBJS += builtin-annotate.o |
| 381 | BUILTIN_OBJS += builtin-help.o | 383 | BUILTIN_OBJS += builtin-help.o |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 059c565b31ea..df516dce9540 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "util/parse-events.h" | 23 | #include "util/parse-events.h" |
| 24 | #include "util/thread.h" | 24 | #include "util/thread.h" |
| 25 | #include "util/sort.h" | 25 | #include "util/sort.h" |
| 26 | #include "util/hist.h" | ||
| 26 | 27 | ||
| 27 | static char const *input_name = "perf.data"; | 28 | static char const *input_name = "perf.data"; |
| 28 | 29 | ||
| @@ -47,45 +48,6 @@ struct sym_ext { | |||
| 47 | char *path; | 48 | char *path; |
| 48 | }; | 49 | }; |
| 49 | 50 | ||
| 50 | /* | ||
| 51 | * histogram, sorted on item, collects counts | ||
| 52 | */ | ||
| 53 | |||
| 54 | static struct rb_root hist; | ||
| 55 | |||
| 56 | static int64_t | ||
| 57 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | ||
| 58 | { | ||
| 59 | struct sort_entry *se; | ||
| 60 | int64_t cmp = 0; | ||
| 61 | |||
| 62 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 63 | cmp = se->cmp(left, right); | ||
| 64 | if (cmp) | ||
| 65 | break; | ||
| 66 | } | ||
| 67 | |||
| 68 | return cmp; | ||
| 69 | } | ||
| 70 | |||
| 71 | static int64_t | ||
| 72 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | ||
| 73 | { | ||
| 74 | struct sort_entry *se; | ||
| 75 | int64_t cmp = 0; | ||
| 76 | |||
| 77 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 78 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | ||
| 79 | |||
| 80 | f = se->collapse ?: se->cmp; | ||
| 81 | |||
| 82 | cmp = f(left, right); | ||
| 83 | if (cmp) | ||
| 84 | break; | ||
| 85 | } | ||
| 86 | |||
| 87 | return cmp; | ||
| 88 | } | ||
| 89 | 51 | ||
| 90 | /* | 52 | /* |
| 91 | * collect histogram counts | 53 | * collect histogram counts |
| @@ -163,116 +125,6 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso, | |||
| 163 | return 0; | 125 | return 0; |
| 164 | } | 126 | } |
| 165 | 127 | ||
| 166 | static void hist_entry__free(struct hist_entry *he) | ||
| 167 | { | ||
| 168 | free(he); | ||
| 169 | } | ||
| 170 | |||
| 171 | /* | ||
| 172 | * collapse the histogram | ||
| 173 | */ | ||
| 174 | |||
| 175 | static struct rb_root collapse_hists; | ||
| 176 | |||
| 177 | static void collapse__insert_entry(struct hist_entry *he) | ||
| 178 | { | ||
| 179 | struct rb_node **p = &collapse_hists.rb_node; | ||
| 180 | struct rb_node *parent = NULL; | ||
| 181 | struct hist_entry *iter; | ||
| 182 | int64_t cmp; | ||
| 183 | |||
| 184 | while (*p != NULL) { | ||
| 185 | parent = *p; | ||
| 186 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 187 | |||
| 188 | cmp = hist_entry__collapse(iter, he); | ||
| 189 | |||
| 190 | if (!cmp) { | ||
| 191 | iter->count += he->count; | ||
| 192 | hist_entry__free(he); | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | if (cmp < 0) | ||
| 197 | p = &(*p)->rb_left; | ||
| 198 | else | ||
| 199 | p = &(*p)->rb_right; | ||
| 200 | } | ||
| 201 | |||
| 202 | rb_link_node(&he->rb_node, parent, p); | ||
| 203 | rb_insert_color(&he->rb_node, &collapse_hists); | ||
| 204 | } | ||
| 205 | |||
| 206 | static void collapse__resort(void) | ||
| 207 | { | ||
| 208 | struct rb_node *next; | ||
| 209 | struct hist_entry *n; | ||
| 210 | |||
| 211 | if (!sort__need_collapse) | ||
| 212 | return; | ||
| 213 | |||
| 214 | next = rb_first(&hist); | ||
| 215 | while (next) { | ||
| 216 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 217 | next = rb_next(&n->rb_node); | ||
| 218 | |||
| 219 | rb_erase(&n->rb_node, &hist); | ||
| 220 | collapse__insert_entry(n); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | /* | ||
| 225 | * reverse the map, sort on count. | ||
| 226 | */ | ||
| 227 | |||
| 228 | static struct rb_root output_hists; | ||
| 229 | |||
| 230 | static void output__insert_entry(struct hist_entry *he) | ||
| 231 | { | ||
| 232 | struct rb_node **p = &output_hists.rb_node; | ||
| 233 | struct rb_node *parent = NULL; | ||
| 234 | struct hist_entry *iter; | ||
| 235 | |||
| 236 | while (*p != NULL) { | ||
| 237 | parent = *p; | ||
| 238 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 239 | |||
| 240 | if (he->count > iter->count) | ||
| 241 | p = &(*p)->rb_left; | ||
| 242 | else | ||
| 243 | p = &(*p)->rb_right; | ||
| 244 | } | ||
| 245 | |||
| 246 | rb_link_node(&he->rb_node, parent, p); | ||
| 247 | rb_insert_color(&he->rb_node, &output_hists); | ||
| 248 | } | ||
| 249 | |||
| 250 | static void output__resort(void) | ||
| 251 | { | ||
| 252 | struct rb_node *next; | ||
| 253 | struct hist_entry *n; | ||
| 254 | struct rb_root *tree = &hist; | ||
| 255 | |||
| 256 | if (sort__need_collapse) | ||
| 257 | tree = &collapse_hists; | ||
| 258 | |||
| 259 | next = rb_first(tree); | ||
| 260 | |||
| 261 | while (next) { | ||
| 262 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 263 | next = rb_next(&n->rb_node); | ||
| 264 | |||
| 265 | rb_erase(&n->rb_node, tree); | ||
| 266 | output__insert_entry(n); | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | static unsigned long total = 0, | ||
| 271 | total_mmap = 0, | ||
| 272 | total_comm = 0, | ||
| 273 | total_fork = 0, | ||
| 274 | total_unknown = 0; | ||
| 275 | |||
| 276 | static int | 128 | static int |
| 277 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) | 129 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) |
| 278 | { | 130 | { |
| @@ -861,7 +713,7 @@ more: | |||
| 861 | dsos__fprintf(stdout); | 713 | dsos__fprintf(stdout); |
| 862 | 714 | ||
| 863 | collapse__resort(); | 715 | collapse__resort(); |
| 864 | output__resort(); | 716 | output__resort(total); |
| 865 | 717 | ||
| 866 | find_annotations(); | 718 | find_annotations(); |
| 867 | 719 | ||
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 7b43504900ff..c1a54fc8527a 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | #include "util/thread.h" | 29 | #include "util/thread.h" |
| 30 | #include "util/sort.h" | 30 | #include "util/sort.h" |
| 31 | #include "util/hist.h" | ||
| 31 | 32 | ||
| 32 | static char const *input_name = "perf.data"; | 33 | static char const *input_name = "perf.data"; |
| 33 | 34 | ||
| @@ -55,8 +56,6 @@ static int exclude_other = 1; | |||
| 55 | 56 | ||
| 56 | static char callchain_default_opt[] = "fractal,0.5"; | 57 | static char callchain_default_opt[] = "fractal,0.5"; |
| 57 | 58 | ||
| 58 | static int callchain; | ||
| 59 | |||
| 60 | static char __cwd[PATH_MAX]; | 59 | static char __cwd[PATH_MAX]; |
| 61 | static char *cwd = __cwd; | 60 | static char *cwd = __cwd; |
| 62 | static int cwdlen; | 61 | static int cwdlen; |
| @@ -66,50 +65,8 @@ static struct thread *last_match; | |||
| 66 | 65 | ||
| 67 | static struct perf_header *header; | 66 | static struct perf_header *header; |
| 68 | 67 | ||
| 69 | static | ||
| 70 | struct callchain_param callchain_param = { | ||
| 71 | .mode = CHAIN_GRAPH_REL, | ||
| 72 | .min_percent = 0.5 | ||
| 73 | }; | ||
| 74 | |||
| 75 | static u64 sample_type; | 68 | static u64 sample_type; |
| 76 | 69 | ||
| 77 | static struct rb_root hist; | ||
| 78 | |||
| 79 | static int64_t | ||
| 80 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | ||
| 81 | { | ||
| 82 | struct sort_entry *se; | ||
| 83 | int64_t cmp = 0; | ||
| 84 | |||
| 85 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 86 | cmp = se->cmp(left, right); | ||
| 87 | if (cmp) | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | |||
| 91 | return cmp; | ||
| 92 | } | ||
| 93 | |||
| 94 | static int64_t | ||
| 95 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | ||
| 96 | { | ||
| 97 | struct sort_entry *se; | ||
| 98 | int64_t cmp = 0; | ||
| 99 | |||
| 100 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 101 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | ||
| 102 | |||
| 103 | f = se->collapse ?: se->cmp; | ||
| 104 | |||
| 105 | cmp = f(left, right); | ||
| 106 | if (cmp) | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | |||
| 110 | return cmp; | ||
| 111 | } | ||
| 112 | |||
| 113 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask) | 70 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask) |
| 114 | { | 71 | { |
| 115 | int i; | 72 | int i; |
| @@ -308,7 +265,6 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |||
| 308 | return ret; | 265 | return ret; |
| 309 | } | 266 | } |
| 310 | 267 | ||
| 311 | |||
| 312 | static size_t | 268 | static size_t |
| 313 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) | 269 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) |
| 314 | { | 270 | { |
| @@ -573,117 +529,6 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso, | |||
| 573 | return 0; | 529 | return 0; |
| 574 | } | 530 | } |
| 575 | 531 | ||
| 576 | static void hist_entry__free(struct hist_entry *he) | ||
| 577 | { | ||
| 578 | free(he); | ||
| 579 | } | ||
| 580 | |||
| 581 | /* | ||
| 582 | * collapse the histogram | ||
| 583 | */ | ||
| 584 | |||
| 585 | static struct rb_root collapse_hists; | ||
| 586 | |||
| 587 | static void collapse__insert_entry(struct hist_entry *he) | ||
| 588 | { | ||
| 589 | struct rb_node **p = &collapse_hists.rb_node; | ||
| 590 | struct rb_node *parent = NULL; | ||
| 591 | struct hist_entry *iter; | ||
| 592 | int64_t cmp; | ||
| 593 | |||
| 594 | while (*p != NULL) { | ||
| 595 | parent = *p; | ||
| 596 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 597 | |||
| 598 | cmp = hist_entry__collapse(iter, he); | ||
| 599 | |||
| 600 | if (!cmp) { | ||
| 601 | iter->count += he->count; | ||
| 602 | hist_entry__free(he); | ||
| 603 | return; | ||
| 604 | } | ||
| 605 | |||
| 606 | if (cmp < 0) | ||
| 607 | p = &(*p)->rb_left; | ||
| 608 | else | ||
| 609 | p = &(*p)->rb_right; | ||
| 610 | } | ||
| 611 | |||
| 612 | rb_link_node(&he->rb_node, parent, p); | ||
| 613 | rb_insert_color(&he->rb_node, &collapse_hists); | ||
| 614 | } | ||
| 615 | |||
| 616 | static void collapse__resort(void) | ||
| 617 | { | ||
| 618 | struct rb_node *next; | ||
| 619 | struct hist_entry *n; | ||
| 620 | |||
| 621 | if (!sort__need_collapse) | ||
| 622 | return; | ||
| 623 | |||
| 624 | next = rb_first(&hist); | ||
| 625 | while (next) { | ||
| 626 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 627 | next = rb_next(&n->rb_node); | ||
| 628 | |||
| 629 | rb_erase(&n->rb_node, &hist); | ||
| 630 | collapse__insert_entry(n); | ||
| 631 | } | ||
| 632 | } | ||
| 633 | |||
| 634 | /* | ||
| 635 | * reverse the map, sort on count. | ||
| 636 | */ | ||
| 637 | |||
| 638 | static struct rb_root output_hists; | ||
| 639 | |||
| 640 | static void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) | ||
| 641 | { | ||
| 642 | struct rb_node **p = &output_hists.rb_node; | ||
| 643 | struct rb_node *parent = NULL; | ||
| 644 | struct hist_entry *iter; | ||
| 645 | |||
| 646 | if (callchain) | ||
| 647 | callchain_param.sort(&he->sorted_chain, &he->callchain, | ||
| 648 | min_callchain_hits, &callchain_param); | ||
| 649 | |||
| 650 | while (*p != NULL) { | ||
| 651 | parent = *p; | ||
| 652 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 653 | |||
| 654 | if (he->count > iter->count) | ||
| 655 | p = &(*p)->rb_left; | ||
| 656 | else | ||
| 657 | p = &(*p)->rb_right; | ||
| 658 | } | ||
| 659 | |||
| 660 | rb_link_node(&he->rb_node, parent, p); | ||
| 661 | rb_insert_color(&he->rb_node, &output_hists); | ||
| 662 | } | ||
| 663 | |||
| 664 | static void output__resort(u64 total_samples) | ||
| 665 | { | ||
| 666 | struct rb_node *next; | ||
| 667 | struct hist_entry *n; | ||
| 668 | struct rb_root *tree = &hist; | ||
| 669 | u64 min_callchain_hits; | ||
| 670 | |||
| 671 | min_callchain_hits = total_samples * (callchain_param.min_percent / 100); | ||
| 672 | |||
| 673 | if (sort__need_collapse) | ||
| 674 | tree = &collapse_hists; | ||
| 675 | |||
| 676 | next = rb_first(tree); | ||
| 677 | |||
| 678 | while (next) { | ||
| 679 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 680 | next = rb_next(&n->rb_node); | ||
| 681 | |||
| 682 | rb_erase(&n->rb_node, tree); | ||
| 683 | output__insert_entry(n, min_callchain_hits); | ||
| 684 | } | ||
| 685 | } | ||
| 686 | |||
| 687 | static size_t output__fprintf(FILE *fp, u64 total_samples) | 532 | static size_t output__fprintf(FILE *fp, u64 total_samples) |
| 688 | { | 533 | { |
| 689 | struct hist_entry *pos; | 534 | struct hist_entry *pos; |
| @@ -778,13 +623,6 @@ print_entries: | |||
| 778 | return ret; | 623 | return ret; |
| 779 | } | 624 | } |
| 780 | 625 | ||
| 781 | static unsigned long total = 0, | ||
| 782 | total_mmap = 0, | ||
| 783 | total_comm = 0, | ||
| 784 | total_fork = 0, | ||
| 785 | total_unknown = 0, | ||
| 786 | total_lost = 0; | ||
| 787 | |||
| 788 | static int validate_chain(struct ip_callchain *chain, event_t *event) | 626 | static int validate_chain(struct ip_callchain *chain, event_t *event) |
| 789 | { | 627 | { |
| 790 | unsigned int chain_size; | 628 | unsigned int chain_size; |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c new file mode 100644 index 000000000000..82808dc4f8e3 --- /dev/null +++ b/tools/perf/util/hist.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | #include "hist.h" | ||
| 2 | |||
| 3 | struct rb_root hist; | ||
| 4 | struct rb_root collapse_hists; | ||
| 5 | struct rb_root output_hists; | ||
| 6 | int callchain; | ||
| 7 | |||
| 8 | struct callchain_param callchain_param = { | ||
| 9 | .mode = CHAIN_GRAPH_REL, | ||
| 10 | .min_percent = 0.5 | ||
| 11 | }; | ||
| 12 | |||
| 13 | unsigned long total; | ||
| 14 | unsigned long total_mmap; | ||
| 15 | unsigned long total_comm; | ||
| 16 | unsigned long total_fork; | ||
| 17 | unsigned long total_unknown; | ||
| 18 | unsigned long total_lost; | ||
| 19 | |||
| 20 | /* | ||
| 21 | * histogram, sorted on item, collects counts | ||
| 22 | */ | ||
| 23 | |||
| 24 | int64_t | ||
| 25 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | ||
| 26 | { | ||
| 27 | struct sort_entry *se; | ||
| 28 | int64_t cmp = 0; | ||
| 29 | |||
| 30 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 31 | cmp = se->cmp(left, right); | ||
| 32 | if (cmp) | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | |||
| 36 | return cmp; | ||
| 37 | } | ||
| 38 | |||
| 39 | int64_t | ||
| 40 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | ||
| 41 | { | ||
| 42 | struct sort_entry *se; | ||
| 43 | int64_t cmp = 0; | ||
| 44 | |||
| 45 | list_for_each_entry(se, &hist_entry__sort_list, list) { | ||
| 46 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | ||
| 47 | |||
| 48 | f = se->collapse ?: se->cmp; | ||
| 49 | |||
| 50 | cmp = f(left, right); | ||
| 51 | if (cmp) | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | |||
| 55 | return cmp; | ||
| 56 | } | ||
| 57 | |||
| 58 | void hist_entry__free(struct hist_entry *he) | ||
| 59 | { | ||
| 60 | free(he); | ||
| 61 | } | ||
| 62 | |||
| 63 | /* | ||
| 64 | * collapse the histogram | ||
| 65 | */ | ||
| 66 | |||
| 67 | void collapse__insert_entry(struct hist_entry *he) | ||
| 68 | { | ||
| 69 | struct rb_node **p = &collapse_hists.rb_node; | ||
| 70 | struct rb_node *parent = NULL; | ||
| 71 | struct hist_entry *iter; | ||
| 72 | int64_t cmp; | ||
| 73 | |||
| 74 | while (*p != NULL) { | ||
| 75 | parent = *p; | ||
| 76 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 77 | |||
| 78 | cmp = hist_entry__collapse(iter, he); | ||
| 79 | |||
| 80 | if (!cmp) { | ||
| 81 | iter->count += he->count; | ||
| 82 | hist_entry__free(he); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | |||
| 86 | if (cmp < 0) | ||
| 87 | p = &(*p)->rb_left; | ||
| 88 | else | ||
| 89 | p = &(*p)->rb_right; | ||
| 90 | } | ||
| 91 | |||
| 92 | rb_link_node(&he->rb_node, parent, p); | ||
| 93 | rb_insert_color(&he->rb_node, &collapse_hists); | ||
| 94 | } | ||
| 95 | |||
| 96 | void collapse__resort(void) | ||
| 97 | { | ||
| 98 | struct rb_node *next; | ||
| 99 | struct hist_entry *n; | ||
| 100 | |||
| 101 | if (!sort__need_collapse) | ||
| 102 | return; | ||
| 103 | |||
| 104 | next = rb_first(&hist); | ||
| 105 | while (next) { | ||
| 106 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 107 | next = rb_next(&n->rb_node); | ||
| 108 | |||
| 109 | rb_erase(&n->rb_node, &hist); | ||
| 110 | collapse__insert_entry(n); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | /* | ||
| 115 | * reverse the map, sort on count. | ||
| 116 | */ | ||
| 117 | |||
| 118 | void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits) | ||
| 119 | { | ||
| 120 | struct rb_node **p = &output_hists.rb_node; | ||
| 121 | struct rb_node *parent = NULL; | ||
| 122 | struct hist_entry *iter; | ||
| 123 | |||
| 124 | if (callchain) | ||
| 125 | callchain_param.sort(&he->sorted_chain, &he->callchain, | ||
| 126 | min_callchain_hits, &callchain_param); | ||
| 127 | |||
| 128 | while (*p != NULL) { | ||
| 129 | parent = *p; | ||
| 130 | iter = rb_entry(parent, struct hist_entry, rb_node); | ||
| 131 | |||
| 132 | if (he->count > iter->count) | ||
| 133 | p = &(*p)->rb_left; | ||
| 134 | else | ||
| 135 | p = &(*p)->rb_right; | ||
| 136 | } | ||
| 137 | |||
| 138 | rb_link_node(&he->rb_node, parent, p); | ||
| 139 | rb_insert_color(&he->rb_node, &output_hists); | ||
| 140 | } | ||
| 141 | |||
| 142 | void output__resort(u64 total_samples) | ||
| 143 | { | ||
| 144 | struct rb_node *next; | ||
| 145 | struct hist_entry *n; | ||
| 146 | struct rb_root *tree = &hist; | ||
| 147 | u64 min_callchain_hits; | ||
| 148 | |||
| 149 | min_callchain_hits = | ||
| 150 | total_samples * (callchain_param.min_percent / 100); | ||
| 151 | |||
| 152 | if (sort__need_collapse) | ||
| 153 | tree = &collapse_hists; | ||
| 154 | |||
| 155 | next = rb_first(tree); | ||
| 156 | |||
| 157 | while (next) { | ||
| 158 | n = rb_entry(next, struct hist_entry, rb_node); | ||
| 159 | next = rb_next(&n->rb_node); | ||
| 160 | |||
| 161 | rb_erase(&n->rb_node, tree); | ||
| 162 | output__insert_entry(n, min_callchain_hits); | ||
| 163 | } | ||
| 164 | } | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h new file mode 100644 index 000000000000..9a8daa12b43a --- /dev/null +++ b/tools/perf/util/hist.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #ifndef __PERF_HIST_H | ||
| 2 | #define __PERF_HIST_H | ||
| 3 | #include "../builtin.h" | ||
| 4 | |||
| 5 | #include "util.h" | ||
| 6 | |||
| 7 | #include "color.h" | ||
| 8 | #include <linux/list.h> | ||
| 9 | #include "cache.h" | ||
| 10 | #include <linux/rbtree.h> | ||
| 11 | #include "symbol.h" | ||
| 12 | #include "string.h" | ||
| 13 | #include "callchain.h" | ||
| 14 | #include "strlist.h" | ||
| 15 | #include "values.h" | ||
| 16 | |||
| 17 | #include "../perf.h" | ||
| 18 | #include "debug.h" | ||
| 19 | #include "header.h" | ||
| 20 | |||
| 21 | #include "parse-options.h" | ||
| 22 | #include "parse-events.h" | ||
| 23 | |||
| 24 | #include "thread.h" | ||
| 25 | #include "sort.h" | ||
| 26 | |||
| 27 | extern struct rb_root hist; | ||
| 28 | extern struct rb_root collapse_hists; | ||
| 29 | extern struct rb_root output_hists; | ||
| 30 | extern int callchain; | ||
| 31 | extern struct callchain_param callchain_param; | ||
| 32 | extern unsigned long total; | ||
| 33 | extern unsigned long total_mmap; | ||
| 34 | extern unsigned long total_comm; | ||
| 35 | extern unsigned long total_fork; | ||
| 36 | extern unsigned long total_unknown; | ||
| 37 | extern unsigned long total_lost; | ||
| 38 | |||
| 39 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | ||
| 40 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | ||
| 41 | extern void hist_entry__free(struct hist_entry *); | ||
| 42 | extern void collapse__insert_entry(struct hist_entry *); | ||
| 43 | extern void collapse__resort(void); | ||
| 44 | extern void output__insert_entry(struct hist_entry *, u64); | ||
| 45 | extern void output__resort(u64); | ||
| 46 | |||
| 47 | #endif /* __PERF_HIST_H */ | ||
