#include <stdio.h>
#include "../../util/util.h"
#include "../../util/hist.h"
#include "../../util/sort.h"
#include "../../util/evsel.h"
static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
{
int i;
int ret = fprintf(fp, " ");
for (i = 0; i < left_margin; i++)
ret += fprintf(fp, " ");
return ret;
}
static size_t inline__fprintf(struct map *map, u64 ip, int left_margin,
int depth, int depth_mask, FILE *fp)
{
struct dso *dso;
struct inline_node *node;
struct inline_list *ilist;
int ret = 0, i;
if (map == NULL)
return 0;
dso = map->dso;
if (dso == NULL)
return 0;
if (dso->kernel != DSO_TYPE_USER)
return 0;
node = dso__parse_addr_inlines(dso,
map__rip_2objdump(map, ip));
if (node == NULL)
return 0;
list_for_each_entry(ilist, &node->val, list) {
if ((ilist->filename != NULL) || (ilist->funcname != NULL)) {
ret += callchain__fprintf_left_margin(fp, left_margin);
for (i = 0; i < depth; i++) {
if (depth_mask & (1 << i))
ret += fprintf(fp, "|");
else
ret += fprintf(fp, " ");
ret += fprintf(fp, " ");
}
if (callchain_param.key == CCKEY_ADDRESS ||
callchain_param.key == CCKEY_SRCLINE) {
if (ilist->filename != NULL)
ret += fprintf(fp, "%s:%d (inline)",
ilist->filename,
ilist->line_nr);
else
ret += fprintf(fp, "??");
} else if (ilist->funcname != NULL)
ret += fprintf(fp, "%s (inline)",
ilist->funcname);
else if (ilist->filename != NULL)
ret += fprintf(fp, "%s:%d (inline)",
ilist->filename,
ilist->line_nr);
else
ret += fprintf(fp, "??");
ret += fprintf(fp, "\n");
}
}
inline_node__delete(node);
return ret;
}
static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
int left_margin)
{
int i;
size_t ret = callchain__fprintf_left_margin(fp, left_margin);
for (i = 0; i < depth; i++)
if (depth_mask & (1 << i))
ret += fprintf(fp, "| ");
else
ret += fprintf(fp, " ");
ret += fprintf(fp, "\n");
return ret;
}
static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
struct callchain_list *chain,
int depth, int depth_mask, int period,
u64 total_samples, int left_margin)
{
int i;
size_t ret = 0;
char bf[1024], *alloc_str = NULL;
char buf[64];
const char *str;
ret += callchain__fprintf_left_margin(fp, left_margin);
for (i = 0; i < depth; i++) {
if (depth_mask & (1 << i))
ret += fprintf(fp, "|");
else
ret += fprintf(fp, " ");
if (!period && i == depth - 1) {
ret += fprintf(fp, "--");
ret += callchain_node__fprintf_value(node, fp, total_samples);
ret += fprintf(fp, "--");
} else
ret += fprintf(fp, "%s", " ");
}