perf hist: Pass struct sample to __hists__add_entry()
[deliverable/linux.git] / tools / perf / util / hist.c
index 4fd37d6708cb973d2653c1ec4f6f17b086c712d0..039bb91d0a92255f1e84e0f8c6f62801e09d0f96 100644 (file)
@@ -270,6 +270,8 @@ static void hists__delete_entry(struct hists *hists, struct hist_entry *he)
 
        if (sort__need_collapse)
                rb_erase(&he->rb_node_in, &hists->entries_collapsed);
+       else
+               rb_erase(&he->rb_node_in, hists->entries_in);
 
        --hists->nr_entries;
        if (!he->filtered)
@@ -459,7 +461,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
                                      struct symbol *sym_parent,
                                      struct branch_info *bi,
                                      struct mem_info *mi,
-                                     u64 period, u64 weight, u64 transaction,
+                                     struct perf_sample *sample,
                                      bool sample_self)
 {
        struct hist_entry entry = {
@@ -476,15 +478,15 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
                .level   = al->level,
                .stat = {
                        .nr_events = 1,
-                       .period = period,
-                       .weight = weight,
+                       .period = sample->period,
+                       .weight = sample->weight,
                },
                .parent = sym_parent,
                .filtered = symbol__parent_filter(sym_parent) | al->filtered,
                .hists  = hists,
                .branch_info = bi,
                .mem_info = mi,
-               .transaction = transaction,
+               .transaction = sample->transaction,
        };
 
        return hists__findnew_entry(hists, &entry, al, sample_self);
@@ -524,12 +526,13 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al
        u64 cost;
        struct mem_info *mi = iter->priv;
        struct hists *hists = evsel__hists(iter->evsel);
+       struct perf_sample *sample = iter->sample;
        struct hist_entry *he;
 
        if (mi == NULL)
                return -EINVAL;
 
-       cost = iter->sample->weight;
+       cost = sample->weight;
        if (!cost)
                cost = 1;
 
@@ -540,8 +543,10 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al
         * and this is indirectly achieved by passing period=weight here
         * and the he_stat__add_period() function.
         */
+       sample->period = cost;
+
        he = __hists__add_entry(hists, al, iter->parent, NULL, mi,
-                               cost, cost, 0, true);
+                               sample, true);
        if (!he)
                return -ENOMEM;
 
@@ -628,6 +633,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
        struct branch_info *bi;
        struct perf_evsel *evsel = iter->evsel;
        struct hists *hists = evsel__hists(evsel);
+       struct perf_sample *sample = iter->sample;
        struct hist_entry *he = NULL;
        int i = iter->curr;
        int err = 0;
@@ -641,9 +647,11 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
         * The report shows the percentage of total branches captured
         * and not events sampled. Thus we use a pseudo period of 1.
         */
+       sample->period = 1;
+       sample->weight = bi->flags.cycles ? bi->flags.cycles : 1;
+
        he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
-                               1, bi->flags.cycles ? bi->flags.cycles : 1,
-                               0, true);
+                               sample, true);
        if (he == NULL)
                return -ENOMEM;
 
@@ -680,8 +688,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location
        struct hist_entry *he;
 
        he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-                               sample->period, sample->weight,
-                               sample->transaction, true);
+                               sample, true);
        if (he == NULL)
                return -ENOMEM;
 
@@ -742,8 +749,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
        int err = 0;
 
        he = __hists__add_entry(hists, al, iter->parent, NULL, NULL,
-                               sample->period, sample->weight,
-                               sample->transaction, true);
+                               sample, true);
        if (he == NULL)
                return -ENOMEM;
 
@@ -816,8 +822,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
        }
 
        he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-                               sample->period, sample->weight,
-                               sample->transaction, false);
+                               sample, false);
        if (he == NULL)
                return -ENOMEM;
 
@@ -924,9 +929,6 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
        int64_t cmp = 0;
 
        perf_hpp__for_each_sort_list(fmt) {
-               if (perf_hpp__should_skip(fmt))
-                       continue;
-
                cmp = fmt->cmp(fmt, left, right);
                if (cmp)
                        break;
@@ -942,9 +944,6 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
        int64_t cmp = 0;
 
        perf_hpp__for_each_sort_list(fmt) {
-               if (perf_hpp__should_skip(fmt))
-                       continue;
-
                cmp = fmt->collapse(fmt, left, right);
                if (cmp)
                        break;
@@ -1573,6 +1572,35 @@ static int hists_evsel__init(struct perf_evsel *evsel)
        return 0;
 }
 
+static void hists__delete_remaining_entries(struct rb_root *root)
+{
+       struct rb_node *node;
+       struct hist_entry *he;
+
+       while (!RB_EMPTY_ROOT(root)) {
+               node = rb_first(root);
+               rb_erase(node, root);
+
+               he = rb_entry(node, struct hist_entry, rb_node_in);
+               hist_entry__delete(he);
+       }
+}
+
+static void hists__delete_all_entries(struct hists *hists)
+{
+       hists__delete_entries(hists);
+       hists__delete_remaining_entries(&hists->entries_in_array[0]);
+       hists__delete_remaining_entries(&hists->entries_in_array[1]);
+       hists__delete_remaining_entries(&hists->entries_collapsed);
+}
+
+static void hists_evsel__exit(struct perf_evsel *evsel)
+{
+       struct hists *hists = evsel__hists(evsel);
+
+       hists__delete_all_entries(hists);
+}
+
 /*
  * XXX We probably need a hists_evsel__exit() to free the hist_entries
  * stored in the rbtree...
@@ -1581,7 +1609,8 @@ static int hists_evsel__init(struct perf_evsel *evsel)
 int hists__init(void)
 {
        int err = perf_evsel__object_config(sizeof(struct hists_evsel),
-                                           hists_evsel__init, NULL);
+                                           hists_evsel__init,
+                                           hists_evsel__exit);
        if (err)
                fputs("FATAL ERROR: Couldn't setup hists class\n", stderr);
 
This page took 0.033587 seconds and 5 git commands to generate.