diff options
Diffstat (limited to 'tools/perf/util/hist.c')
| -rw-r--r-- | tools/perf/util/hist.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 82808dc4f8e3..7393a02fd8d4 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
| @@ -21,6 +21,52 @@ unsigned long total_lost; | |||
| 21 | * histogram, sorted on item, collects counts | 21 | * histogram, sorted on item, collects counts |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | struct hist_entry *__hist_entry__add(struct thread *thread, struct map *map, | ||
| 25 | struct symbol *sym, | ||
| 26 | struct symbol *sym_parent, | ||
| 27 | u64 ip, u64 count, char level, bool *hit) | ||
| 28 | { | ||
| 29 | struct rb_node **p = &hist.rb_node; | ||
| 30 | struct rb_node *parent = NULL; | ||
| 31 | struct hist_entry *he; | ||
| 32 | struct hist_entry entry = { | ||
| 33 | .thread = thread, | ||
| 34 | .map = map, | ||
| 35 | .sym = sym, | ||
| 36 | .ip = ip, | ||
| 37 | .level = level, | ||
| 38 | .count = count, | ||
| 39 | .parent = sym_parent, | ||
| 40 | }; | ||
| 41 | int cmp; | ||
| 42 | |||
| 43 | while (*p != NULL) { | ||
| 44 | parent = *p; | ||
| 45 | he = rb_entry(parent, struct hist_entry, rb_node); | ||
| 46 | |||
| 47 | cmp = hist_entry__cmp(&entry, he); | ||
| 48 | |||
| 49 | if (!cmp) { | ||
| 50 | *hit = true; | ||
| 51 | return he; | ||
| 52 | } | ||
| 53 | |||
| 54 | if (cmp < 0) | ||
| 55 | p = &(*p)->rb_left; | ||
| 56 | else | ||
| 57 | p = &(*p)->rb_right; | ||
| 58 | } | ||
| 59 | |||
| 60 | he = malloc(sizeof(*he)); | ||
| 61 | if (!he) | ||
| 62 | return NULL; | ||
| 63 | *he = entry; | ||
| 64 | rb_link_node(&he->rb_node, parent, p); | ||
| 65 | rb_insert_color(&he->rb_node, &hist); | ||
| 66 | *hit = false; | ||
| 67 | return he; | ||
| 68 | } | ||
| 69 | |||
| 24 | int64_t | 70 | int64_t |
| 25 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | 71 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 26 | { | 72 | { |
