Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "../../util/callchain.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "../../util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "../../util/event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "../../util/hist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "../../util/map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "../../util/maps.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "../../util/symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "../../util/sort.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "../../util/evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "../../util/srcline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "../../util/string2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../../util/thread.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "../../util/block-info.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int ret = fprintf(fp, "            ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	for (i = 0; i < left_margin; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		ret += fprintf(fp, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 					  int left_margin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	size_t ret = callchain__fprintf_left_margin(fp, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	for (i = 0; i < depth; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (depth_mask & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			ret += fprintf(fp, "|          ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			ret += fprintf(fp, "           ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				     struct callchain_list *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				     int depth, int depth_mask, int period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				     u64 total_samples, int left_margin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	char bf[1024], *alloc_str = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ret += callchain__fprintf_left_margin(fp, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	for (i = 0; i < depth; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		if (depth_mask & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			ret += fprintf(fp, "|");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			ret += fprintf(fp, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (!period && i == depth - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			ret += fprintf(fp, "--");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			ret += callchain_node__fprintf_value(node, fp, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			ret += fprintf(fp, "--");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			ret += fprintf(fp, "%s", "          ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	str = callchain_list__sym_name(chain, bf, sizeof(bf), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (symbol_conf.show_branchflag_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		callchain_list_counts__printf_value(chain, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 						    buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (asprintf(&alloc_str, "%s%s", str, buf) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			str = "Not enough memory!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			str = alloc_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	fputs(str, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	fputc('\n', fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	free(alloc_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static struct symbol *rem_sq_bracket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct callchain_list rem_hits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void init_rem_hits(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!rem_sq_bracket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		fprintf(stderr, "Not enough memory to display remaining hits\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	strcpy(rem_sq_bracket->name, "[...]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	rem_hits.ms.sym = rem_sq_bracket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 					 u64 total_samples, int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 					 int depth_mask, int left_margin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct rb_node *node, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct callchain_node *child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int new_depth_mask = depth_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u64 remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	uint entries_printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int cumul_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	remaining = total_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	node = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	while (node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		u64 new_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		u64 cumul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		child = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		cumul = callchain_cumul_hits(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		remaining -= cumul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		cumul_count += callchain_cumul_counts(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		 * The depth mask manages the output of pipes that show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		 * the depth. We don't want to keep the pipes of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		 * level for the last child of this depth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		 * Except if we have remaining filtered hits. They will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		 * supersede the last child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		next = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			new_depth_mask &= ~(1 << (depth - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		 * But we keep the older depth mask for the line separator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		 * to keep the level link until we reach the last child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 						   left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		list_for_each_entry(chain, &child->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			ret += ipchain__fprintf_graph(fp, child, chain, depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 						      new_depth_mask, i++,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 						      total_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 						      left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (callchain_param.mode == CHAIN_GRAPH_REL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			new_total = child->children_hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			new_total = total_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		ret += __callchain__fprintf_graph(fp, &child->rb_root, new_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 						  depth + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 						  new_depth_mask | (1 << depth),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 						  left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		node = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (++entries_printed == callchain_param.print_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (callchain_param.mode == CHAIN_GRAPH_REL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		remaining && remaining != total_samples) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		struct callchain_node rem_node = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			.hit = remaining,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (!rem_sq_bracket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (callchain_param.value == CCVAL_COUNT && child && child->parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			rem_node.count = child->parent->children_count - cumul_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			if (rem_node.count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		new_depth_mask &= ~(1 << (depth - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 					      new_depth_mask, 0, total_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 					      left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * If have one single callchain root, don't bother printing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * its percentage (100 % in fractal mode and the same percentage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * than the hist in graph mode). This also avoid one level of column.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * However when percent-limit applied, it's possible that single callchain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * node have different (non-100% in fractal mode) percentage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static bool need_percent_display(struct rb_node *node, u64 parent_samples)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct callchain_node *cnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (rb_next(node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	cnode = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return callchain_cumul_hits(cnode) != parent_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				       u64 total_samples, u64 parent_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				       int left_margin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct callchain_node *cnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	u32 entries_printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	bool printed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	char bf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	node = rb_first(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (node && !need_percent_display(node, parent_samples)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		cnode = rb_entry(node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		list_for_each_entry(chain, &cnode->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			 * If we sort by symbol, the first entry is the same than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			 * the symbol. No need to print it otherwise it appears as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 * displayed twice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			if (!i++ && field_order == NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			    sort_order && strstarts(sort_order, "sym"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			if (!printed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				ret += callchain__fprintf_left_margin(fp, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				ret += fprintf(fp, "|\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				ret += callchain__fprintf_left_margin(fp, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				ret += fprintf(fp, "---");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				left_margin += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				printed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				ret += callchain__fprintf_left_margin(fp, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			ret += fprintf(fp, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				       callchain_list__sym_name(chain, bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 								sizeof(bf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 								false));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			if (symbol_conf.show_branchflag_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				ret += callchain_list_counts__printf_value(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 						chain, fp, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			if (++entries_printed == callchain_param.print_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		root = &cnode->rb_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (callchain_param.mode == CHAIN_GRAPH_REL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		total_samples = parent_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ret += __callchain__fprintf_graph(fp, root, total_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 					  1, 1, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		/* do not add a blank line if it printed nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 					u64 total_samples)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	char bf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	ret += __callchain__fprintf_flat(fp, node->parent, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	list_for_each_entry(chain, &node->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (chain->ip >= PERF_CONTEXT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		ret += fprintf(fp, "                %s\n", callchain_list__sym_name(chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 					bf, sizeof(bf), false));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				      u64 total_samples)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	u32 entries_printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	struct callchain_node *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct rb_node *rb_node = rb_first(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	while (rb_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		chain = rb_entry(rb_node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		ret += fprintf(fp, "           ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		ret += callchain_node__fprintf_value(chain, fp, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		ret += __callchain__fprintf_flat(fp, chain, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		if (++entries_printed == callchain_param.print_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		rb_node = rb_next(rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static size_t __callchain__fprintf_folded(FILE *fp, struct callchain_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	const char *sep = symbol_conf.field_sep ?: ";";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct callchain_list *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	char bf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	bool first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	ret += __callchain__fprintf_folded(fp, node->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	first = (ret == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	list_for_each_entry(chain, &node->val, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		if (chain->ip >= PERF_CONTEXT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		ret += fprintf(fp, "%s%s", first ? "" : sep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			       callchain_list__sym_name(chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						bf, sizeof(bf), false));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 					u64 total_samples)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	u32 entries_printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct callchain_node *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	struct rb_node *rb_node = rb_first(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	while (rb_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		chain = rb_entry(rb_node, struct callchain_node, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		ret += callchain_node__fprintf_value(chain, fp, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		ret += fprintf(fp, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		ret += __callchain__fprintf_folded(fp, chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		ret += fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (++entries_printed == callchain_param.print_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		rb_node = rb_next(rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 					    u64 total_samples, int left_margin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 					    FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	u64 parent_samples = he->stat.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (symbol_conf.cumulate_callchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		parent_samples = he->stat_acc->period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	switch (callchain_param.mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	case CHAIN_GRAPH_REL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 						parent_samples, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	case CHAIN_GRAPH_ABS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 						parent_samples, left_margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	case CHAIN_FLAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	case CHAIN_FOLDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		return callchain__fprintf_folded(fp, &he->sorted_chain, total_samples);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	case CHAIN_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		pr_err("Bad callchain mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			   struct perf_hpp_list *hpp_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	char *start = hpp->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (symbol_conf.exclude_other && !he->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	perf_hpp_list__for_each_format(hpp_list, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		if (perf_hpp__should_skip(fmt, he->hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * If there's no field_sep, we still need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 * to display initial '  '.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		if (!sep || !first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		if (perf_hpp__use_color() && fmt->color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			ret = fmt->color(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			ret = fmt->entry(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		ret = hist_entry__snprintf_alignment(he, hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return hpp->buf - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	return __hist_entry__snprintf(he, hpp, he->hists->hpp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 					 struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 					 struct hists *hists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 					 FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	char *buf = hpp->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	size_t size = hpp->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	int ret, printed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (symbol_conf.exclude_other && !he->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	ret = scnprintf(hpp->buf, hpp->size, "%*s", he->depth * HIERARCHY_INDENT, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	fmt_node = list_first_entry(&hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 				    struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		 * If there's no field_sep, we still need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		 * to display initial '  '.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		if (!sep || !first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		if (perf_hpp__use_color() && fmt->color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			ret = fmt->color(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			ret = fmt->entry(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		ret = hist_entry__snprintf_alignment(he, hpp, fmt, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (!sep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		ret = scnprintf(hpp->buf, hpp->size, "%*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 				(hists->nr_hpp_node - 2) * HIERARCHY_INDENT, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	advance_hpp(hpp, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	printed += fprintf(fp, "%s", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	perf_hpp_list__for_each_format(he->hpp_list, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		hpp->buf  = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		hpp->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		 * No need to call hist_entry__snprintf_alignment() since this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		 * fmt is always the last column in the hierarchy mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		if (perf_hpp__use_color() && fmt->color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			fmt->color(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			fmt->entry(fmt, hpp, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		 * dynamic entries are right-aligned but we want left-aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		 * in the hierarchy mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		printed += fprintf(fp, "%s%s", sep ?: "  ", skip_spaces(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	printed += putc('\n', fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	if (he->leaf && hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		u64 total = hists__total_period(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		printed += hist_entry_callchain__fprintf(he, total, 0, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int hist_entry__block_fprintf(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 				     char *bf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 				     FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct block_hist *bh = container_of(he, struct block_hist, he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	for (unsigned int i = 0; i < bh->block_hists.nr_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			.buf		= bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 			.size		= size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			.skip		= false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		bh->block_idx = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		hist_entry__snprintf(he, &hpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (!hpp.skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			ret += fprintf(fp, "%s\n", bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static int hist_entry__individual_block_fprintf(struct hist_entry *he,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 						char *bf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 						FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		.buf		= bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		.size		= size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		.skip		= false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	hist_entry__snprintf(he, &hpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if (!hpp.skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		ret += fprintf(fp, "%s\n", bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static int hist_entry__fprintf(struct hist_entry *he, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			       char *bf, size_t bfsz, FILE *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			       bool ignore_callchains)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	int callchain_ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	struct perf_hpp hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		.buf		= bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		.size		= size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	struct hists *hists = he->hists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	u64 total_period = hists->stats.total_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	if (size == 0 || size > bfsz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		size = hpp.size = bfsz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		return hist_entry__hierarchy_fprintf(he, &hpp, hists, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (symbol_conf.report_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		return hist_entry__block_fprintf(he, bf, size, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	if (symbol_conf.report_individual_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		return hist_entry__individual_block_fprintf(he, bf, size, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	hist_entry__snprintf(he, &hpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	ret = fprintf(fp, "%s\n", bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (hist_entry__has_callchains(he) && !ignore_callchains)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		callchain_ret = hist_entry_callchain__fprintf(he, total_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 							      0, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	ret += callchain_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static int print_hierarchy_indent(const char *sep, int indent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 				  const char *line, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	if (sep != NULL || indent < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	width = (indent - 2) * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	return fprintf(fp, "%-*.*s", width, width, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static int hists__fprintf_hierarchy_headers(struct hists *hists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 					    struct perf_hpp *hpp, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	bool first_node, first_col;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	int indent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	unsigned width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	unsigned header_width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	struct perf_hpp_list_node *fmt_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	indent = hists->nr_hpp_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	/* preserve max indent depth for column headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	print_hierarchy_indent(sep, indent, " ", fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	/* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	fmt_node = list_first_entry(&hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 				    struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		fmt->header(fmt, hpp, hists, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		fprintf(fp, "%s%s", hpp->buf, sep ?: "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	/* combine sort headers with ' / ' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	first_node = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	list_for_each_entry_continue(fmt_node, &hists->hpp_formats, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		if (!first_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 			header_width += fprintf(fp, " / ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		first_node = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		first_col = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 			if (perf_hpp__should_skip(fmt, hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			if (!first_col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 				header_width += fprintf(fp, "+");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 			first_col = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			fmt->header(fmt, hpp, hists, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			header_width += fprintf(fp, "%s", strim(hpp->buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	fprintf(fp, "\n# ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	/* preserve max indent depth for initial dots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	print_hierarchy_indent(sep, indent, dots, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* the first hpp_list_node is for overhead columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	fmt_node = list_first_entry(&hists->hpp_formats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 				    struct perf_hpp_list_node, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	first_col = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		if (!first_col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 			fprintf(fp, "%s", sep ?: "..");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		first_col = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		width = fmt->width(fmt, hpp, hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		fprintf(fp, "%.*s", width, dots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	depth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	list_for_each_entry_continue(fmt_node, &hists->hpp_formats, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		first_col = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		width = depth * HIERARCHY_INDENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 		perf_hpp_list__for_each_format(&fmt_node->hpp, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 			if (perf_hpp__should_skip(fmt, hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 			if (!first_col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 				width++;  /* for '+' sign between column header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 			first_col = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			width += fmt->width(fmt, hpp, hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		if (width > header_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			header_width = width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		depth++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	fprintf(fp, "%s%-.*s", sep ?: "  ", header_width, dots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	fprintf(fp, "\n#\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) static void fprintf_line(struct hists *hists, struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 			 int line, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	int span = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	hists__for_each_format(hists, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 		if (perf_hpp__should_skip(fmt, hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		if (!first && !span)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			fprintf(fp, "%s", sep ?: "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 			first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		fmt->header(fmt, hpp, hists, line, &span);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		if (!span)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 			fprintf(fp, "%s", hpp->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) hists__fprintf_standard_headers(struct hists *hists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 				struct perf_hpp *hpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 				FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	struct perf_hpp_list *hpp_list = hists->hpp_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	struct perf_hpp_fmt *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	unsigned int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	int line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	for (line = 0; line < hpp_list->nr_header_lines; line++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		/* first # is displayed one level up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		if (line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 			fprintf(fp, "# ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		fprintf_line(hists, hpp, line, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	if (sep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		return hpp_list->nr_header_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	fprintf(fp, "# ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	hists__for_each_format(hists, fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 		if (perf_hpp__should_skip(fmt, hists))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		if (!first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 			fprintf(fp, "%s", sep ?: "  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 			first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 		width = fmt->width(fmt, hpp, hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		for (i = 0; i < width; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 			fprintf(fp, ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	fprintf(fp, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	fprintf(fp, "#\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	return hpp_list->nr_header_lines + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) int hists__fprintf_headers(struct hists *hists, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	char bf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	struct perf_hpp dummy_hpp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		.buf	= bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 		.size	= sizeof(bf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	fprintf(fp, "# ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	if (symbol_conf.report_hierarchy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		return hists__fprintf_hierarchy_headers(hists, &dummy_hpp, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 		return hists__fprintf_standard_headers(hists, &dummy_hpp, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		      int max_cols, float min_pcnt, FILE *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		      bool ignore_callchains)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	struct rb_node *nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 	const char *sep = symbol_conf.field_sep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	int nr_rows = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	size_t linesz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	char *line = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	unsigned indent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	init_rem_hits();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	hists__reset_column_width(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if (symbol_conf.col_width_list_str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		perf_hpp__set_user_width(symbol_conf.col_width_list_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	if (show_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 		nr_rows += hists__fprintf_headers(hists, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	if (max_rows && nr_rows >= max_rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	linesz = hists__sort_list_width(hists) + 3 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	linesz += perf_hpp__color_overhead();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	line = malloc(linesz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	if (line == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	indent = hists__overhead_width(hists) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	for (nd = rb_first_cached(&hists->entries); nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	     nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 		float percent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 		if (h->filtered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		if (symbol_conf.report_individual_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 			percent = block_info__total_cycles_percent(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 			percent = hist_entry__get_percent_limit(h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 		if (percent < min_pcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		ret += hist_entry__fprintf(h, max_cols, line, linesz, fp, ignore_callchains);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 		if (max_rows && ++nr_rows >= max_rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 		 * If all children are filtered out or percent-limited,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 		 * display "no entry >= x.xx%" message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		if (!h->leaf && !hist_entry__has_hierarchy_children(h, min_pcnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 			int depth = hists->nr_hpp_node + h->depth + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 			print_hierarchy_indent(sep, depth, " ", fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 			fprintf(fp, "%*sno entry >= %.2f%%\n", indent, "", min_pcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			if (max_rows && ++nr_rows >= max_rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 		if (h->ms.map == NULL && verbose > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 			maps__fprintf(h->thread->maps, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 			fprintf(fp, "%.10s end\n", graph_dotted_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	free(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 	zfree(&rem_sq_bracket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 		const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 		name = perf_event__name(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 		if (!strcmp(name, "UNKNOWN"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 		ret += fprintf(fp, "%16s events: %10d\n", name, stats->nr_events[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) }