// SPDX-License-Identifier: GPL-2.0
/*
 * builtin-list.c
 *
 * Builtin list command: list all event types
 *
 * Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de>
 * Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
 */
#include "builtin.h"

#include "util/print-events.h"
#include "util/pmus.h"
#include "util/pmu.h"
#include "util/debug.h"
#include "util/metricgroup.h"
#include "util/pfm.h"
#include "util/string2.h"
#include "util/strlist.h"
#include "util/strbuf.h"
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
#include <linux/zalloc.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>

/**
 * struct print_state - State and configuration passed to the default_print
 * functions.
 */
struct print_state {
	/** @fp: File to write output to. */
	FILE *fp;
	/**
	 * @pmu_glob: Optionally restrict PMU and metric matching to PMU or
	 * debugfs subsystem name.
	 */
	char *pmu_glob;
	/** @event_glob: Optional pattern matching glob. */
	char *event_glob;
	/** @name_only: Print event or metric names only. */
	bool name_only;
	/** @desc: Print the event or metric description. */
	bool desc;
	/** @long_desc: Print longer event or metric description. */
	bool long_desc;
	/** @deprecated: Print deprecated events or metrics. */
	bool deprecated;
	/**
	 * @detailed: Print extra information on the perf event such as names
	 * and expressions used internally by events.
	 */
	bool detailed;
	/** @metrics: Controls printing of metric and metric groups. */
	bool metrics;
	/** @metricgroups: Controls printing of metric and metric groups. */
	bool metricgroups;
	/** @last_topic: The last printed event topic. */
	char *last_topic;
	/** @last_metricgroups: The last printed metric group. */
	char *last_metricgroups;
	/** @visited_metrics: Metrics that are printed to avoid duplicates. */
	struct strlist *visited_metrics;
};

static void default_print_start(void *ps)
{
	struct print_state *print_state = ps;

	if (!print_state->name_only && pager_in_use()) {
		fprintf(print_state->fp,
			"\nList of pre-defined events (to be used in -e or -M):\n\n");
	}
}

static void default_print_end(void *print_state __maybe_unused) {}

static const char *skip_spaces_or_commas(const char *str)
{
	while (isspace(*str) || *str == ',')
		++str;
	return str;
}

static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
{
	int column = start;
	int n;
	bool saw_newline = false;
	bool comma = false;

	while (*s) {
		int wlen = strcspn(s, " ,\t\n");
		const char *sep = comma ? "," : " ";

		if ((column + wlen >= max && column > start) || saw_newline) {
			fprintf(fp, comma ? ",\n%*s" : "\n%*s", start, "");
			column = start + corr;
		}
		if (column <= start)
			sep = "";
		n = fprintf(fp, "%s%.*s", sep, wlen, s);
		if (n <= 0)
			break;
		saw_newline = s[wlen] == '\n';
		s += wlen;
		comma = s[0] == ',';
		column += n;
		s = skip_spaces_or_commas(s);
	}
}

static void default_print_event(void *ps, const char *pmu_name, const char *topic,
				const char *event_name, const char *event_alias,
				const char *scale_unit __maybe_unused,
				bool deprecated, const char *event_type_desc,
				const char *desc, const char *long_desc,
				const char *encoding_desc)
{
	struct print_state *print_state = ps;
	int pos;
	FILE *fp = print_state->fp;

	if (deprecated && !print_state->deprecated)
		return;

	if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_state->pmu_glob))
		return;

	if (print_state->event_glob &&
	    (!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
	    (!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
	    (!topic || !strglobmatch_nocase(topic, print_state->event_glob)))
		return;

	if (print_state->name_only) {
		if (event_alias && strlen(event_alias))
			fprintf(fp, "%s ", event_alias);
		else
			fprintf(fp, "%s ", event_name);
		return;
	}

	if (strcmp(print_state->last_topic, topic ?: "")) {
		if (topic)
			fprintf(fp, "\n%s:\n", topic);
		zfree(&print_state->last_topic);
		print_state->last_topic = strdup(topic ?: "");
	}

	if (event_alias && strlen(event_alias))
		pos = fprintf(fp, "  %s OR %s", event_name, event_alias);
	else
		pos = fprintf(fp, "  %s", event_name);

	if (!topic && event_type_desc) {
		for (; pos < 53; pos++)
			fputc(' ', fp);
		fprintf(fp, "[%s]\n", event_type_desc);
	} else
		fputc('\n', fp);

	if (long_desc && print_state->long_desc) {
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
	} else if (desc && print_state->desc) {
		char *desc_with_unit = NULL;
		int desc_len = -1;

		if (pmu_name && strcmp(pmu_name, "default_core")) {
			desc_len = strlen(desc);
			desc_len = asprintf(&desc_with_unit,
					    desc[desc_len - 1] != '.'
					      ? "%s. Unit: %s" : "%s Unit: %s",
					    desc, pmu_name);
		}
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, desc_len > 0 ? desc_with_unit : desc, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
		free(desc_with_unit);
	}

	if (print_state->detailed && encoding_desc) {
		fprintf(fp, "%*s", 8, "");
		wordwrap(fp, encoding_desc, 8, pager_get_columns(), 0);
		fputc('\n', fp);
	}
}

static void default_print_metric(void *ps,
				const char *group,
				const char *name,
				const char *desc,
				const char *long_desc,
				const char *expr,
				const char *threshold,
				const char *unit __maybe_unused)
{
	struct print_state *print_state = ps;
	FILE *fp = print_state->fp;

	if (print_state->event_glob &&
	    (!print_state->metrics || !name || !strglobmatch(name, print_state->event_glob)) &&
	    (!print_state->metricgroups || !group || !strglobmatch(group, print_state->event_glob)))
		return;

	if (!print_state->name_only && !print_state->last_metricgroups) {
		if (print_state->metricgroups) {
			fprintf(fp, "\nMetric Groups:\n");
			if (!print_state->metrics)
				fputc('\n', fp);
		} else {
			fprintf(fp, "\nMetrics:\n\n");
		}
	}
	if (!print_state->last_metricgroups ||
	    strcmp(print_state->last_metricgroups, group ?: "")) {
		if (group && print_state->metricgroups) {
			if (print_state->name_only) {
				fprintf(fp, "%s ", group);
			} else {
				const char *gdesc = print_state->desc
					? describe_metricgroup(group)
					: NULL;
				const char *print_colon = "";

				if (print_state->metrics) {
					print_colon = ":";
					fputc('\n', fp);
				}

				if (gdesc)
					fprintf(fp, "%s%s [%s]\n", group, print_colon, gdesc);
				else
					fprintf(fp, "%s%s\n", group, print_colon);
			}
		}
		zfree(&print_state->last_metricgroups);
		print_state->last_metricgroups = strdup(group ?: "");
	}
	if (!print_state->metrics)
		return;

	if (print_state->name_only) {
		if (print_state->metrics &&
		    !strlist__has_entry(print_state->visited_metrics, name)) {
			fprintf(fp, "%s ", name);
			strlist__add(print_state->visited_metrics, name);
		}
		return;
	}
	fprintf(fp, "  %s\n", name);

	if (long_desc && print_state->long_desc) {
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, long_desc, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
	} else if (desc && print_state->desc) {
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, desc, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
	}
	if (expr && print_state->detailed) {
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, expr, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
	}
	if (threshold && print_state->detailed) {
		fprintf(fp, "%*s", 8, "[");
		wordwrap(fp, threshold, 8, pager_get_columns(), 0);
		fprintf(fp, "]\n");
	}
}

struct json_print_state {
	/** @fp: File to write output to. */
	FILE *fp;
	/** Should a separator be printed prior to the next item? */
	bool need_sep;
};

static void json_print_start(void *ps)
{
	struct json_print_state *print_state = ps;
	FILE *fp = print_state->fp;

	fprintf(fp, "[\n");
}

static void json_print_end(void *ps)
{
	struct json_print_state *print_state = ps;
	FILE *fp = print_state->fp;

	fprintf(fp, "%s]\n", print_state->need_sep ? "\n" : "");
}

static void fix_escape_fprintf(FILE *fp, struct strbuf *buf, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	strbuf_setlen(buf, 0);
	for (size_t fmt_pos = 0; fmt_pos < strlen(fmt); fmt_pos++) {
		switch (fmt[fmt_pos]) {
		case '%':
			fmt_pos++;
			switch (fmt[fmt_pos]) {
			case 's': {
				const char *s = va_arg(args, const char*);

				strbuf_addstr(buf, s);
				break;
			}
			case 'S': {
				const char *s = va_arg(args, const char*);

				for (size_t s_pos = 0; s_pos < strlen(s); s_pos++) {
					switch (s[s_pos]) {
					case '\n':
						strbuf_addstr(buf, "\\n");
						break;
					case '\r':
						strbuf_addstr(buf, "\\r");
						break;
					case '\\':
						fallthrough;
					case '\"':
						strbuf_addch(buf, '\\');
						fallthrough;
					default:
						strbuf_addch(buf, s[s_pos]);
						break;
					}
				}
				break;
			}
			default:
				pr_err("Unexpected format character '%c'\n", fmt[fmt_pos]);
				strbuf_addch(buf, '%');
				strbuf_addch(buf, fmt[fmt_pos]);
			}
			break;
		default:
			strbuf_addch(buf, fmt[fmt_pos]);
			break;
		}
	}
	va_end(args);
	fputs(buf->buf, fp);
}

static void json_print_event(void *ps, const char *pmu_name, const char *topic,
			     const char *event_name, const char *event_alias,
			     const char *scale_unit,
			     bool deprecated, const char *event_type_desc,
			     const char *desc, const char *long_desc,
			     const char *encoding_desc)
{
	struct json_print_state *print_state = ps;
	bool need_sep = false;
	FILE *fp = print_state->fp;
	struct strbuf buf;

	strbuf_init(&buf, 0);
	fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
	print_state->need_sep = true;
	if (pmu_name) {
		fix_escape_fprintf(fp, &buf, "\t\"Unit\": \"%S\"", pmu_name);
		need_sep = true;
	}
	if (topic) {
		fix_escape_fprintf(fp, &buf, "%s\t\"Topic\": \"%S\"",
				   need_sep ? ",\n" : "",
				   topic);
		need_sep = true;
	}
	if (event_name) {
		fix_escape_fprintf(fp, &buf, "%s\t\"EventName\": \"%S\"",
				   need_sep ? ",\n" : "",
				   event_name);
		need_sep = true;
	}
	if (event_alias && strlen(event_alias)) {
		fix_escape_fprintf(fp, &buf, "%s\t\"EventAlias\": \"%S\"",
				   need_sep ? ",\n" : "",
				   event_alias);
		need_sep = true;
	}
	if (scale_unit && strlen(scale_unit)) {
		fix_escape_fprintf(fp, &buf, "%s\t\"ScaleUnit\": \"%S\"",
				   need_sep ? ",\n" : "",
				   scale_unit);
		need_sep = true;
	}
	if (event_type_desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"EventType\": \"%S\"",
				   need_sep ? ",\n" : "",
				   event_type_desc);
		need_sep = true;
	}
	if (deprecated) {
		fix_escape_fprintf(fp, &buf, "%s\t\"Deprecated\": \"%S\"",
				   need_sep ? ",\n" : "",
				   deprecated ? "1" : "0");
		need_sep = true;
	}
	if (desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
				   need_sep ? ",\n" : "",
				   desc);
		need_sep = true;
	}
	if (long_desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"PublicDescription\": \"%S\"",
				   need_sep ? ",\n" : "",
				   long_desc);
		need_sep = true;
	}
	if (encoding_desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"Encoding\": \"%S\"",
				   need_sep ? ",\n" : "",
				   encoding_desc);
		need_sep = true;
	}
	fprintf(fp, "%s}", need_sep ? "\n" : "");
	strbuf_release(&buf);
}

static void json_print_metric(void *ps __maybe_unused, const char *group,
			      const char *name, const char *desc,
			      const char *long_desc, const char *expr,
			      const char *threshold, const char *unit)
{
	struct json_print_state *print_state = ps;
	bool need_sep = false;
	FILE *fp = print_state->fp;
	struct strbuf buf;

	strbuf_init(&buf, 0);
	fprintf(fp, "%s{\n", print_state->need_sep ? ",\n" : "");
	print_state->need_sep = true;
	if (group) {
		fix_escape_fprintf(fp, &buf, "\t\"MetricGroup\": \"%S\"", group);
		need_sep = true;
	}
	if (name) {
		fix_escape_fprintf(fp, &buf, "%s\t\"MetricName\": \"%S\"",
				   need_sep ? ",\n" : "",
				   name);
		need_sep = true;
	}
	if (expr) {
		fix_escape_fprintf(fp, &buf, "%s\t\"MetricExpr\": \"%S\"",
				   need_sep ? ",\n" : "",
				   expr);
		need_sep = true;
	}
	if (threshold) {
		fix_escape_fprintf(fp, &buf, "%s\t\"MetricThreshold\": \"%S\"",
				   need_sep ? ",\n" : "",
				   threshold);
		need_sep = true;
	}
	if (unit) {
		fix_escape_fprintf(fp, &buf, "%s\t\"ScaleUnit\": \"%S\"",
				   need_sep ? ",\n" : "",
				   unit);
		need_sep = true;
	}
	if (desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"BriefDescription\": \"%S\"",
				   need_sep ? ",\n" : "",
				   desc);
		need_sep = true;
	}
	if (long_desc) {
		fix_escape_fprintf(fp, &buf, "%s\t\"PublicDescription\": \"%S\"",
				   need_sep ? ",\n" : "",
				   long_desc);
		need_sep = true;
	}
	fprintf(fp, "%s}", need_sep ? "\n" : "");
	strbuf_release(&buf);
}

static bool json_skip_duplicate_pmus(void *ps __maybe_unused)
{
	return false;
}

static bool default_skip_duplicate_pmus(void *ps)
{
	struct print_state *print_state = ps;

	return !print_state->long_desc;
}

int cmd_list(int argc, const char **argv)
{
	int i, ret = 0;
	struct print_state default_ps = {
		.fp = stdout,
		.desc = true,
	};
	struct print_state json_ps = {
		.fp = stdout,
	};
	void *ps = &default_ps;
	struct print_callbacks print_cb = {
		.print_start = default_print_start,
		.print_end = default_print_end,
		.print_event = default_print_event,
		.print_metric = default_print_metric,
		.skip_duplicate_pmus = default_skip_duplicate_pmus,
	};
	const char *cputype = NULL;
	const char *unit_name = NULL;
	const char *output_path = NULL;
	bool json = false;
	struct option list_options[] = {
		OPT_BOOLEAN(0, "raw-dump", &default_ps.name_only, "Dump raw events"),
		OPT_BOOLEAN('j', "json", &json, "JSON encode events and metrics"),
		OPT_BOOLEAN('d', "desc", &default_ps.desc,
			    "Print extra event descriptions. --no-desc to not print."),
		OPT_BOOLEAN('v', "long-desc", &default_ps.long_desc,
			    "Print longer event descriptions."),
		OPT_BOOLEAN(0, "details", &default_ps.detailed,
			    "Print information on the perf event names and expressions used internally by events."),
		OPT_STRING('o', "output", &output_path, "file", "output file name"),
		OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated,
			    "Print deprecated events."),
		OPT_STRING(0, "cputype", &cputype, "cpu type",
			   "Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."),
		OPT_STRING(0, "unit", &unit_name, "PMU name",
			   "Limit PMU or metric printing to the specified PMU."),
		OPT_INCR(0, "debug", &verbose,
			     "Enable debugging output"),
		OPT_END()
	};
	const char * const list_usage[] = {
#ifdef HAVE_LIBPFM
		"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob|pfm]",
#else
		"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
#endif
		NULL
	};

	set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
	/* Hide hybrid flag for the more generic 'unit' flag. */
	set_option_flag(list_options, 0, "cputype", PARSE_OPT_HIDDEN);

	argc = parse_options(argc, argv, list_options, list_usage,
			     PARSE_OPT_STOP_AT_NON_OPTION);

	if (output_path) {
		default_ps.fp = fopen(output_path, "w");
		json_ps.fp = default_ps.fp;
	}

	setup_pager();

	if (!default_ps.name_only)
		setup_pager();

	if (json) {
		print_cb = (struct print_callbacks){
			.print_start = json_print_start,
			.print_end = json_print_end,
			.print_event = json_print_event,
			.print_metric = json_print_metric,
			.skip_duplicate_pmus = json_skip_duplicate_pmus,
		};
		ps = &json_ps;
	} else {
		default_ps.last_topic = strdup("");
		assert(default_ps.last_topic);
		default_ps.visited_metrics = strlist__new(NULL, NULL);
		assert(default_ps.visited_metrics);
		if (unit_name)
			default_ps.pmu_glob = strdup(unit_name);
		else if (cputype) {
			const struct perf_pmu *pmu = perf_pmus__pmu_for_pmu_filter(cputype);

			if (!pmu) {
				pr_err("ERROR: cputype is not supported!\n");
				ret = -1;
				goto out;
			}
			default_ps.pmu_glob = strdup(pmu->name);
		}
	}
	print_cb.print_start(ps);

	if (argc == 0) {
		default_ps.metrics = true;
		default_ps.metricgroups = true;
		print_events(&print_cb, ps);
		goto out;
	}

	for (i = 0; i < argc; ++i) {
		char *sep, *s;

		if (strcmp(argv[i], "tracepoint") == 0)
			print_tracepoint_events(&print_cb, ps);
		else if (strcmp(argv[i], "hw") == 0 ||
			 strcmp(argv[i], "hardware") == 0)
			print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
					event_symbols_hw, PERF_COUNT_HW_MAX);
		else if (strcmp(argv[i], "sw") == 0 ||
			 strcmp(argv[i], "software") == 0) {
			print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
					event_symbols_sw, PERF_COUNT_SW_MAX);
			print_tool_events(&print_cb, ps);
		} else if (strcmp(argv[i], "cache") == 0 ||
			 strcmp(argv[i], "hwcache") == 0)
			print_hwcache_events(&print_cb, ps);
		else if (strcmp(argv[i], "pmu") == 0)
			perf_pmus__print_pmu_events(&print_cb, ps);
		else if (strcmp(argv[i], "sdt") == 0)
			print_sdt_events(&print_cb, ps);
		else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
			default_ps.metricgroups = false;
			default_ps.metrics = true;
			metricgroup__print(&print_cb, ps);
		} else if (strcmp(argv[i], "metricgroup") == 0 ||
			   strcmp(argv[i], "metricgroups") == 0) {
			default_ps.metricgroups = true;
			default_ps.metrics = false;
			metricgroup__print(&print_cb, ps);
		}
#ifdef HAVE_LIBPFM
		else if (strcmp(argv[i], "pfm") == 0)
			print_libpfm_events(&print_cb, ps);
#endif
		else if ((sep = strchr(argv[i], ':')) != NULL) {
			char *old_pmu_glob = default_ps.pmu_glob;

			default_ps.event_glob = strdup(argv[i]);
			if (!default_ps.event_glob) {
				ret = -1;
				goto out;
			}

			print_tracepoint_events(&print_cb, ps);
			print_sdt_events(&print_cb, ps);
			default_ps.metrics = true;
			default_ps.metricgroups = true;
			metricgroup__print(&print_cb, ps);
			zfree(&default_ps.event_glob);
			default_ps.pmu_glob = old_pmu_glob;
		} else {
			if (asprintf(&s, "*%s*", argv[i]) < 0) {
				printf("Critical: Not enough memory! Trying to continue...\n");
				continue;
			}
			default_ps.event_glob = s;
			print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE,
					event_symbols_hw, PERF_COUNT_HW_MAX);
			print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE,
					event_symbols_sw, PERF_COUNT_SW_MAX);
			print_tool_events(&print_cb, ps);
			print_hwcache_events(&print_cb, ps);
			perf_pmus__print_pmu_events(&print_cb, ps);
			print_tracepoint_events(&print_cb, ps);
			print_sdt_events(&print_cb, ps);
			default_ps.metrics = true;
			default_ps.metricgroups = true;
			metricgroup__print(&print_cb, ps);
			free(s);
		}
	}

out:
	print_cb.print_end(ps);
	free(default_ps.pmu_glob);
	free(default_ps.last_topic);
	free(default_ps.last_metricgroups);
	strlist__delete(default_ps.visited_metrics);
	if (output_path)
		fclose(default_ps.fp);

	return ret;
}
