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-only OR BSD-2-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Copyright (C) 2018 Facebook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Author: Yonghong Song <yhs@fb.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <ftw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <bpf/bpf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* 0: undecided, 1: supported, 2: not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int perf_query_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static bool has_perf_query_support(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	__u64 probe_offset, probe_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	__u32 len, prog_id, fd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	char buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (perf_query_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	fd = open("/", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		p_err("perf_query_support: cannot open directory \"/\" (%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		      strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* the following query will fail as no bpf attachment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 * the expected errno is ENOTSUPP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	len = sizeof(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	bpf_task_fd_query(getpid(), fd, 0, buf, &len, &prog_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			  &fd_type, &probe_offset, &probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (errno == 524 /* ENOTSUPP */) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		perf_query_supported = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		goto close_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	perf_query_supported = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	p_err("perf_query_support: %s", strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	fprintf(stderr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		"HINT: non root or kernel doesn't support TASK_FD_QUERY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) close_fd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return perf_query_supported == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static void print_perf_json(int pid, int fd, __u32 prog_id, __u32 fd_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			    char *buf, __u64 probe_offset, __u64 probe_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	jsonw_start_object(json_wtr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	jsonw_int_field(json_wtr, "pid", pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	jsonw_int_field(json_wtr, "fd", fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	jsonw_uint_field(json_wtr, "prog_id", prog_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	switch (fd_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	case BPF_FD_TYPE_RAW_TRACEPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		jsonw_string_field(json_wtr, "fd_type", "raw_tracepoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		jsonw_string_field(json_wtr, "tracepoint", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case BPF_FD_TYPE_TRACEPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		jsonw_string_field(json_wtr, "fd_type", "tracepoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		jsonw_string_field(json_wtr, "tracepoint", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	case BPF_FD_TYPE_KPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		jsonw_string_field(json_wtr, "fd_type", "kprobe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (buf[0] != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			jsonw_string_field(json_wtr, "func", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			jsonw_lluint_field(json_wtr, "offset", probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			jsonw_lluint_field(json_wtr, "addr", probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	case BPF_FD_TYPE_KRETPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		jsonw_string_field(json_wtr, "fd_type", "kretprobe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (buf[0] != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			jsonw_string_field(json_wtr, "func", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			jsonw_lluint_field(json_wtr, "offset", probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			jsonw_lluint_field(json_wtr, "addr", probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	case BPF_FD_TYPE_UPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		jsonw_string_field(json_wtr, "fd_type", "uprobe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		jsonw_string_field(json_wtr, "filename", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		jsonw_lluint_field(json_wtr, "offset", probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case BPF_FD_TYPE_URETPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		jsonw_string_field(json_wtr, "fd_type", "uretprobe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		jsonw_string_field(json_wtr, "filename", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		jsonw_lluint_field(json_wtr, "offset", probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	jsonw_end_object(json_wtr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void print_perf_plain(int pid, int fd, __u32 prog_id, __u32 fd_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			     char *buf, __u64 probe_offset, __u64 probe_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	printf("pid %d  fd %d: prog_id %u  ", pid, fd, prog_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	switch (fd_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case BPF_FD_TYPE_RAW_TRACEPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		printf("raw_tracepoint  %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case BPF_FD_TYPE_TRACEPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		printf("tracepoint  %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	case BPF_FD_TYPE_KPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (buf[0] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			printf("kprobe  func %s  offset %llu\n", buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			       probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			printf("kprobe  addr %llu\n", probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	case BPF_FD_TYPE_KRETPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (buf[0] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			printf("kretprobe  func %s  offset %llu\n", buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			       probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			printf("kretprobe  addr %llu\n", probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case BPF_FD_TYPE_UPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		printf("uprobe  filename %s  offset %llu\n", buf, probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	case BPF_FD_TYPE_URETPROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		printf("uretprobe  filename %s  offset %llu\n", buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		       probe_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int show_proc(const char *fpath, const struct stat *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		     int tflag, struct FTW *ftwbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	__u64 probe_offset, probe_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	__u32 len, prog_id, fd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int err, pid = 0, fd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	const char *pch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	char buf[4096];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	/* prefix always /proc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	pch = fpath + 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (*pch == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* pid should be all numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	pch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	while (isdigit(*pch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		pid = pid * 10 + *pch - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		pch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (*pch == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (*pch != '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return FTW_SKIP_SUBTREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* check /proc/<pid>/fd directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	pch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (strncmp(pch, "fd", 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return FTW_SKIP_SUBTREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	pch += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (*pch == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (*pch != '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return FTW_SKIP_SUBTREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* check /proc/<pid>/fd/<fd_num> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	pch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	while (isdigit(*pch)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		fd = fd * 10 + *pch - '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		pch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (*pch != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return FTW_SKIP_SUBTREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	/* query (pid, fd) for potential perf events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	len = sizeof(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	err = bpf_task_fd_query(pid, fd, 0, buf, &len, &prog_id, &fd_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				&probe_offset, &probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (json_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		print_perf_json(pid, fd, prog_id, fd_type, buf, probe_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		print_perf_plain(pid, fd, prog_id, fd_type, buf, probe_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				 probe_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static int do_show(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	int flags = FTW_ACTIONRETVAL | FTW_PHYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	int err = 0, nopenfd = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!has_perf_query_support())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (json_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		jsonw_start_array(json_wtr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (nftw("/proc", show_proc, nopenfd, flags) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		p_err("%s", strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (json_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		jsonw_end_array(json_wtr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int do_help(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	fprintf(stderr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		"Usage: %1$s %2$s { show | list | help }\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		bin_name, argv[-2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct cmd cmds[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	{ "show",	do_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	{ "list",	do_show },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	{ "help",	do_help },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	{ 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int do_perf(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return cmd_select(cmds, argc, argv, do_help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }