tools/perf/builtin-kvm.c

Source file repositories/reference/linux-study-clean/tools/perf/builtin-kvm.c

File Facts

System
Linux kernel
Corpus path
tools/perf/builtin-kvm.c
Extension
.c
Size
52465 bytes
Lines
2193
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct kvm_hists {
	struct hists		hists;
	struct perf_hpp_list	list;
};

struct kvm_dimension {
	const char *name;
	const char *header;
	int width;
	int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left,
		       struct hist_entry *right);
	int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
		     struct hist_entry *he);
};

struct kvm_fmt {
	struct perf_hpp_fmt	fmt;
	struct kvm_dimension	*dim;
};

static struct kvm_hists kvm_hists;

static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
			   struct hist_entry *left,
			   struct hist_entry *right)
{
	/* Return opposite number for sorting in alphabetical order */
	return -strcmp(left->kvm_info->name, right->kvm_info->name);
}

static int fmt_width(struct perf_hpp_fmt *fmt,
		     struct perf_hpp *hpp __maybe_unused,
		     struct hists *hists __maybe_unused);

static int ev_name_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
			 struct hist_entry *he)
{
	int width = fmt_width(fmt, hpp, he->hists);

	return scnprintf(hpp->buf, hpp->size, "%*s", width, he->kvm_info->name);
}

static struct kvm_dimension dim_event = {
	.header		= "Event name",
	.name		= "ev_name",
	.cmp		= ev_name_cmp,
	.entry		= ev_name_entry,
	.width		= 40,
};

#define EV_METRIC_CMP(metric)						\
static int64_t ev_cmp_##metric(struct perf_hpp_fmt *fmt __maybe_unused,	\
			       struct hist_entry *left,			\
			       struct hist_entry *right)		\
{									\
	struct kvm_event *event_left;					\
	struct kvm_event *event_right;					\
	struct perf_kvm_stat *perf_kvm;					\
									\
	event_left  = container_of(left, struct kvm_event, he);		\
	event_right = container_of(right, struct kvm_event, he);	\
									\
	perf_kvm = event_left->perf_kvm;				\
	return cmp_event_##metric(event_left, event_right,		\
				  perf_kvm->trace_vcpu);		\
}

EV_METRIC_CMP(time)
EV_METRIC_CMP(count)
EV_METRIC_CMP(max)
EV_METRIC_CMP(min)
EV_METRIC_CMP(mean)

#define EV_METRIC_ENTRY(metric)						\
static int ev_entry_##metric(struct perf_hpp_fmt *fmt,			\
			     struct perf_hpp *hpp,			\
			     struct hist_entry *he)			\
{									\
	struct kvm_event *event;					\
	int width = fmt_width(fmt, hpp, he->hists);			\
	struct perf_kvm_stat *perf_kvm;					\
									\
	event = container_of(he, struct kvm_event, he);			\
	perf_kvm = event->perf_kvm;					\
	return scnprintf(hpp->buf, hpp->size, "%*lu", width,		\
		get_event_##metric(event, perf_kvm->trace_vcpu));	\
}

EV_METRIC_ENTRY(time)
EV_METRIC_ENTRY(count)

Annotation

Implementation Notes