perf hists: Add hists__filter_by_symbol
[linux-flexiantxendom0-3.2.10.git] / tools / perf / util / hist.c
index 8380c3d..2c624ad 100644 (file)
@@ -10,11 +10,14 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
                                       struct hist_entry *he);
 static bool hists__filter_entry_by_thread(struct hists *hists,
                                          struct hist_entry *he);
+static bool hists__filter_entry_by_symbol(struct hists *hists,
+                                         struct hist_entry *he);
 
 enum hist_filter {
        HIST_FILTER__DSO,
        HIST_FILTER__THREAD,
        HIST_FILTER__PARENT,
+       HIST_FILTER__SYMBOL,
 };
 
 struct callchain_param callchain_param = {
@@ -420,6 +423,7 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
 {
        hists__filter_entry_by_dso(hists, he);
        hists__filter_entry_by_thread(hists, he);
+       hists__filter_entry_by_symbol(hists, he);
 }
 
 static void __hists__collapse_resort(struct hists *hists, bool threaded)
@@ -1247,6 +1251,37 @@ void hists__filter_by_thread(struct hists *hists)
        }
 }
 
+static bool hists__filter_entry_by_symbol(struct hists *hists,
+                                         struct hist_entry *he)
+{
+       if (hists->symbol_filter_str != NULL &&
+           (!he->ms.sym || strstr(he->ms.sym->name,
+                                  hists->symbol_filter_str) == NULL)) {
+               he->filtered |= (1 << HIST_FILTER__SYMBOL);
+               return true;
+       }
+
+       return false;
+}
+
+void hists__filter_by_symbol(struct hists *hists)
+{
+       struct rb_node *nd;
+
+       hists->nr_entries = hists->stats.total_period = 0;
+       hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       hists__reset_col_len(hists);
+
+       for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
+               struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+
+               if (hists__filter_entry_by_symbol(hists, h))
+                       continue;
+
+               hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL);
+       }
+}
+
 int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
 {
        return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);