perf hists browser: Recalculate browser pointers after resort/decay
[pandora-kernel.git] / tools / perf / util / ui / browser.c
index 611219f..5911bba 100644 (file)
@@ -230,6 +230,29 @@ int ui_browser__refresh(struct ui_browser *self)
        return 0;
 }
 
+/*
+ * Here we're updating nr_entries _after_ we started browsing, i.e.  we have to
+ * forget about any reference to any entry in the underlying data structure,
+ * that is why we do a SEEK_SET. Think about 'perf top' in the hists browser
+ * after an output_resort and hist decay.
+ */
+void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries)
+{
+       off_t offset = nr_entries - browser->nr_entries;
+
+       browser->nr_entries = nr_entries;
+
+       if (offset < 0) {
+               if (browser->top_idx < (u64)-offset)
+                       offset = -browser->top_idx;
+
+               browser->index += offset;
+               browser->top_idx += offset;
+       }
+
+       browser->seek(browser, browser->top_idx, SEEK_SET);
+}
+
 int ui_browser__run(struct ui_browser *self)
 {
        struct newtExitStruct es;