#define _GNU_SOURCE
#include <stdio.h>
#undef _GNU_SOURCE
#include "../libslang.h"
#include <stdlib.h>
#include <string.h>
#include <newt.h>
#include <linux/rbtree.h>
#include "../../evsel.h"
#include "../../evlist.h"
#include "../../hist.h"
#include "../../pstack.h"
#include "../../sort.h"
#include "../../util.h"
#include "../browser.h"
#include "../helpline.h"
#include "../util.h"
#include "map.h"
struct hist_browser {
struct ui_browser b;
struct hists *hists;
struct hist_entry *he_selection;
struct map_symbol *selection;
};
static void hist_browser__refresh_dimensions(struct hist_browser *self)
{
/* 3 == +/- toggle symbol before actual hist_entry rendering */
self->b.width = 3 + (hists__sort_list_width(self->hists) +
sizeof("[k]"));
}
static void hist_browser__reset(struct hist_browser *self)
{
self->b.nr_entries = self->hists->nr_entries;
hist_browser__refresh_dimensions(self);
ui_browser__reset_index(&self->b);
}
static char tree__folded_sign(bool unfolded)
{
return unfolded ? '-' : '+';
}
static char map_symbol__folded(const struct map_symbol *self)
{
return self->has_children ? tree__folded_sign(self->unfolded) : ' ';
}
static char hist_entry__folded(const struct hist_entry *self)
{
return map_symbol__folded(&self->ms);
}
static char callchain_list__folded(const struct callchain_list *self)
{
return map_symbol__folded(&self->ms);
}
static void map_symbol__set_folding(struct map_symbol *self, bool unfold)
{
self->unfolded = unfold ? self->has_children : false;
}
static int callchain_node__count_rows_rb_tree(struct callchain_node *self)
{
int n = 0;
struct rb_node *nd;
for (nd = rb_first(&self->rb_root); nd; nd = rb_next(nd)) {
struct callchain_node *child = rb_entry(nd, struct callchain_node, rb_node);
struct callchain_list *chain;
char folded_sign = ' '; /* No children */
list_for_each_entry(chain, &child->val, list) {
++n;
/* We need this because we may not have children */
folded_sign = callchain_list__folded(chain);
if (folded_sign == '+')
break;
}
if (folded_sign == '-') /* Have children and they're unfolded */
n += callchain_node__count_rows_rb_tree(child);
}
return n;
}
static int callchain_node__count_rows(struct callchain_node *node)
{
struct callchain_list *chain;
bool unfolded = false;
int n = 0;
list_for_each_entry(chain, &node->val, list) {
++n;
unfolded = chain->ms.unfolded;
}
if (unfolded)
n += callchain_node__count_rows_rb_tree(node);
return n;
}
static int callchain__count_rows(struct rb_root *chain)
{
struct rb_node *nd;
int n = 0;
for (nd